Skip to content

Commit

Permalink
A little change to demos (VisionLabs#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrubb committed May 13, 2016
1 parent f9f7469 commit adc414c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
5 changes: 5 additions & 0 deletions demo/LineSegmentDetector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ end

local image = cv.imread{arg[1] or 'demo/data/lena.jpg', cv.IMREAD_GRAYSCALE}

if image:nDimension() == 0 then
print('Problem loading image\n')
os.exit(0)
end

local detector = cv.LineSegmentDetector{}
local lines = detector:detect{image}
image = detector:drawSegments{image, lines}
Expand Down
5 changes: 5 additions & 0 deletions demo/denoising.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ end

local image = cv.imread{arg[1] or 'demo/data/lena.jpg'}

if image:nDimension() == 0 then
print('Problem loading image\n')
os.exit(0)
end

cv.imshow{"Denoised image", cv.fastNlMeansDenoising{image}}
cv.waitKey{0}
4 changes: 2 additions & 2 deletions demo/filtering.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ end

local image = cv.imread{arg[1] or 'demo/data/lena.jpg'}

if not image then
print("Problem loading image\n")
if image:nDimension() == 0 then
print('Problem loading image\n')
os.exit(0)
end

Expand Down
5 changes: 5 additions & 0 deletions demo/imshow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ if not arg[1] then
end

local im = cv.imread {arg[1] or 'demo/data/lena.jpg', cv.IMREAD_GRAYSCALE}
if im:nDimension() == 0 then
print('Problem loading image\n')
os.exit(0)
end

cv.imshow {"Hello, Lua!", im}
cv.waitKey {0}
5 changes: 5 additions & 0 deletions demo/inpainting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ end
local image = cv.imread{arg[1] or 'demo/data/lena.jpg', cv.IMREAD_COLOR}
local mask = cv.imread{arg[2] or 'demo/data/inpainting/lena_mask.jpg', cv.IMREAD_GRAYSCALE}

if image:nDimension() == 0 or mask:nDimension() == 0 then
print('Problem loading image\n')
os.exit(0)
end

cv.namedWindow{"Display"}
cv.setWindowTitle{"Display", "Image + mask"}
cv.imshow{"Display", cv.addWeighted{image, 0.5, cv.cvtColor{mask, nil, cv.COLOR_GRAY2BGR}, 0.5, 0}}
Expand Down
20 changes: 10 additions & 10 deletions demo/descriptors.lua → demo/keypoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ require 'cv.imgcodecs'
require 'cv.highgui'

if not arg[1] then
print('Usage: `th demo/descriptors.lua path-to-image`')
print('`Usage: `th demo/descriptors.lua path-to-image`')
print('Now using demo/data/lena.jpg')
end

local image = cv.imread{arg[1] or 'demo/data/lena.jpg'}

if not image then
print("Problem loading image\n")
if image:nDimension() == 0 then
print('Problem loading image\n')
os.exit(0)
end

cv.namedWindow{"win1"}
cv.setWindowTitle{"win1", "Original image"}
cv.imshow{"win1", image}
cv.namedWindow{'win1'}
cv.setWindowTitle{'win1', 'Original image'}
cv.imshow{'win1', image}
cv.waitKey{0}

local AGAST = cv.AgastFeatureDetector{threshold=34}
local keyPts = AGAST:detect{image}

-- show keypoints to the user
local imgWithAllKeypoints = cv.drawKeypoints{image, keyPts}
cv.setWindowTitle{"win1", keyPts.size .. " keypoints by AGAST"}
cv.imshow{"win1", imgWithAllKeypoints}
cv.setWindowTitle{'win1', keyPts.size .. ' keypoints by AGAST'}
cv.imshow{'win1', imgWithAllKeypoints}
cv.waitKey{0}

-- remove keypoints within 60 pixels from image border
Expand All @@ -35,6 +35,6 @@ keyPts = cv.KeyPointsFilter.runByImageBorder{keyPts, imageSize, 60}

-- show again, with reduced number of keypoints
local imgWithSomeKeypoints = cv.drawKeypoints{image, keyPts}
cv.setWindowTitle{"win1", keyPts.size .. " remaining keypoints"}
cv.imshow{"win1", imgWithSomeKeypoints}
cv.setWindowTitle{'win1', keyPts.size .. ' remaining keypoints'}
cv.imshow{'win1', imgWithSomeKeypoints}
cv.waitKey{0}
20 changes: 10 additions & 10 deletions demo/stitch.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
local cv = require "cv"
local cv = require 'cv'
require 'cv.highgui'
require 'cv.imgcodecs'
require 'cv.stitching'

cv.namedWindow{"Display"}
cv.namedWindow{'Display'}

local imgs = {}
for i = 1,5 do
imgs[i] = cv.imread{"demo/data/stitch/s" .. i .. ".jpg" }
cv.imshow{"Display", imgs[i]}
imgs[i] = cv.imread{'demo/data/stitch/s' .. i .. '.jpg' }
cv.imshow{'Display', imgs[i]}
cv.waitKey{0}
if not imgs[i] then
print("Problem with loading image")
if imgs[i]:nDimension() == 0 then
print('Problem loading image')
os.exit(0)
end
end
Expand All @@ -20,12 +20,12 @@ local stitcher = cv.Stitcher{}

local timer = torch.Timer()
local status, pano = stitcher:stitch{imgs}
print("Processing time: " .. timer:time().real .. " seconds")
print('Processing time: ' .. timer:time().real .. ' seconds')

cv.setWindowTitle{"Display", "Panorama"}
cv.setWindowTitle{'Display', 'Panorama'}
if status == 0 then
cv.imshow{"Display", pano}
cv.imshow{'Display', pano}
cv.waitKey{0}
else
print("Stitching fail")
print('Stitching fail')
end

0 comments on commit adc414c

Please sign in to comment.