Skip to content

Commit

Permalink
LuaApi/: added cocoDemo.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
pdollar committed May 6, 2016
1 parent c5f70dd commit 7ac5017
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions LuaAPI/CocoApi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ The following API functions are defined in the Lua API:
loadAnns - Load anns with the specified ids.
loadCats - Load cats with the specified ids.
loadImgs - Load imgs with the specified ids.
showAnns - Display the specified annotations.
Throughout the API "ann"=annotation, "cat"=category, and "img"=image.
For detailed usage information please see cocoDemo.lua (coming soon).
For detailed usage information please see cocoDemo.lua.
LIMITATIONS: the following API functions are NOT defined in the Lua API:
showAnns - Display the specified annotations.
loadRes - Load algorithm results and create API for accessing them.
download - Download COCO images from mscoco.org server.
In addition, currently the getCatIds() and getImgIds() do not accept filters.
Expand Down
2 changes: 1 addition & 1 deletion LuaAPI/MaskApi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Usage:
Rs = MaskApi.frBbox( bbs, h, w )
R = MaskApi.frPoly( poly, h, w )
img = MaskApi.drawMasks( img, masks, [maxn=n], [alpha=.4], [clrs] )
For detailed usage information please see cocoDemo.lua (coming soon).
For detailed usage information please see cocoDemo.lua.
In the API the following formats are used:
R,Rs - [table] Run-length encoding of binary mask(s)
Expand Down
22 changes: 22 additions & 0 deletions LuaAPI/cocoDemo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Demo for the CocoApi (see CocoApi.lua)
coco = require 'coco'
image = require 'image'

-- initialize COCO api for instance annotations
dataDir, dataType = '../', 'val2014'
annFile = dataDir..'/annotations/instances_'..dataType..'.json'
if not cocoApi then cocoApi=coco.CocoApi(annFile) end

-- get all image ids, select one at random
imgIds = cocoApi:getImgIds()
imgId = imgIds[torch.random(imgIds:numel())]

-- load image
img = cocoApi:loadImgs(imgId)[1]
I = image.load(dataDir..'/images/'..dataType..'/'..img.file_name,3)

-- load and display instance annotations
annIds = cocoApi:getAnnIds({imgId=imgId})
anns = cocoApi:loadAnns(annIds)
J = cocoApi:showAnns(I,anns)
image.save('RES_'..img.file_name,J:double())

0 comments on commit 7ac5017

Please sign in to comment.