Skip to content

Commit adc414c

Browse files
committed
A little change to demos (#126)
1 parent f9f7469 commit adc414c

7 files changed

+42
-22
lines changed

demo/LineSegmentDetector.lua

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ end
1010

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

13+
if image:nDimension() == 0 then
14+
print('Problem loading image\n')
15+
os.exit(0)
16+
end
17+
1318
local detector = cv.LineSegmentDetector{}
1419
local lines = detector:detect{image}
1520
image = detector:drawSegments{image, lines}

demo/denoising.lua

+5
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ end
1010

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

13+
if image:nDimension() == 0 then
14+
print('Problem loading image\n')
15+
os.exit(0)
16+
end
17+
1318
cv.imshow{"Denoised image", cv.fastNlMeansDenoising{image}}
1419
cv.waitKey{0}

demo/filtering.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ end
1010

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

13-
if not image then
14-
print("Problem loading image\n")
13+
if image:nDimension() == 0 then
14+
print('Problem loading image\n')
1515
os.exit(0)
1616
end
1717

demo/imshow.lua

+5
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@ if not arg[1] then
88
end
99

1010
local im = cv.imread {arg[1] or 'demo/data/lena.jpg', cv.IMREAD_GRAYSCALE}
11+
if im:nDimension() == 0 then
12+
print('Problem loading image\n')
13+
os.exit(0)
14+
end
15+
1116
cv.imshow {"Hello, Lua!", im}
1217
cv.waitKey {0}

demo/inpainting.lua

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ end
1212
local image = cv.imread{arg[1] or 'demo/data/lena.jpg', cv.IMREAD_COLOR}
1313
local mask = cv.imread{arg[2] or 'demo/data/inpainting/lena_mask.jpg', cv.IMREAD_GRAYSCALE}
1414

15+
if image:nDimension() == 0 or mask:nDimension() == 0 then
16+
print('Problem loading image\n')
17+
os.exit(0)
18+
end
19+
1520
cv.namedWindow{"Display"}
1621
cv.setWindowTitle{"Display", "Image + mask"}
1722
cv.imshow{"Display", cv.addWeighted{image, 0.5, cv.cvtColor{mask, nil, cv.COLOR_GRAY2BGR}, 0.5, 0}}

demo/descriptors.lua renamed to demo/keypoints.lua

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ require 'cv.imgcodecs'
44
require 'cv.highgui'
55

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

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

13-
if not image then
14-
print("Problem loading image\n")
13+
if image:nDimension() == 0 then
14+
print('Problem loading image\n')
1515
os.exit(0)
1616
end
1717

18-
cv.namedWindow{"win1"}
19-
cv.setWindowTitle{"win1", "Original image"}
20-
cv.imshow{"win1", image}
18+
cv.namedWindow{'win1'}
19+
cv.setWindowTitle{'win1', 'Original image'}
20+
cv.imshow{'win1', image}
2121
cv.waitKey{0}
2222

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

2626
-- show keypoints to the user
2727
local imgWithAllKeypoints = cv.drawKeypoints{image, keyPts}
28-
cv.setWindowTitle{"win1", keyPts.size .. " keypoints by AGAST"}
29-
cv.imshow{"win1", imgWithAllKeypoints}
28+
cv.setWindowTitle{'win1', keyPts.size .. ' keypoints by AGAST'}
29+
cv.imshow{'win1', imgWithAllKeypoints}
3030
cv.waitKey{0}
3131

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

3636
-- show again, with reduced number of keypoints
3737
local imgWithSomeKeypoints = cv.drawKeypoints{image, keyPts}
38-
cv.setWindowTitle{"win1", keyPts.size .. " remaining keypoints"}
39-
cv.imshow{"win1", imgWithSomeKeypoints}
38+
cv.setWindowTitle{'win1', keyPts.size .. ' remaining keypoints'}
39+
cv.imshow{'win1', imgWithSomeKeypoints}
4040
cv.waitKey{0}

demo/stitch.lua

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
local cv = require "cv"
1+
local cv = require 'cv'
22
require 'cv.highgui'
33
require 'cv.imgcodecs'
44
require 'cv.stitching'
55

6-
cv.namedWindow{"Display"}
6+
cv.namedWindow{'Display'}
77

88
local imgs = {}
99
for i = 1,5 do
10-
imgs[i] = cv.imread{"demo/data/stitch/s" .. i .. ".jpg" }
11-
cv.imshow{"Display", imgs[i]}
10+
imgs[i] = cv.imread{'demo/data/stitch/s' .. i .. '.jpg' }
11+
cv.imshow{'Display', imgs[i]}
1212
cv.waitKey{0}
13-
if not imgs[i] then
14-
print("Problem with loading image")
13+
if imgs[i]:nDimension() == 0 then
14+
print('Problem loading image')
1515
os.exit(0)
1616
end
1717
end
@@ -20,12 +20,12 @@ local stitcher = cv.Stitcher{}
2020

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

25-
cv.setWindowTitle{"Display", "Panorama"}
25+
cv.setWindowTitle{'Display', 'Panorama'}
2626
if status == 0 then
27-
cv.imshow{"Display", pano}
27+
cv.imshow{'Display', pano}
2828
cv.waitKey{0}
2929
else
30-
print("Stitching fail")
30+
print('Stitching fail')
3131
end

0 commit comments

Comments
 (0)