Skip to content

Commit 76d06ad

Browse files
committed
add tests for CvContour#match_shapes
1 parent 7a08fef commit 76d06ad

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

test/helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class OpenCVTestCase < Test::Unit::TestCase
1414
FILENAME_FRUITS = SAMPLE_DIR + 'fruits.jpg'
1515
FILENAME_CONTOURS = File.expand_path(File.dirname(__FILE__)) + '/samples/contours.jpg'
1616
FILENAME_CHESSBOARD = SAMPLE_DIR + 'chessboard.jpg'
17+
FILENAME_LINES = SAMPLE_DIR + 'lines.jpg'
1718
HAARCASCADE_FRONTALFACE_ALT = SAMPLE_DIR + 'haarcascade_frontalface_alt.xml.gz'
1819
AVI_SAMPLE = SAMPLE_DIR + 'movie_sample.avi'
1920

test/test_cvcontour.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,26 @@ def test_point_polygon_test
146146
assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), 1), 0.01)
147147
assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), true), 0.01)
148148
end
149-
end
150149

150+
def test_match_shapes
151+
img1 = CvMat.load(FILENAME_CONTOURS, CV_LOAD_IMAGE_GRAYSCALE).threshold(127, 255, CV_THRESH_BINARY)
152+
img2 = CvMat.load(FILENAME_LINES, CV_LOAD_IMAGE_GRAYSCALE).threshold(127, 255, CV_THRESH_BINARY)
153+
c1 = img1.find_contours(mode: CV_RETR_EXTERNAL)
154+
c2 = img2.find_contours(mode: CV_RETR_EXTERNAL)
155+
156+
[CV_CONTOURS_MATCH_I1, CV_CONTOURS_MATCH_I2, CV_CONTOURS_MATCH_I3].each { |method|
157+
assert_in_delta(0, c1.match_shapes(c1, method), 0.01)
158+
assert_in_delta(0, c1.match_shapes(c1, method, nil), 0.01)
159+
160+
assert(c1.match_shapes(c2, method) > 0)
161+
assert(c1.match_shapes(c2, method, nil) > 0)
162+
}
163+
164+
assert_raise(TypeError) {
165+
c1.match_shapes(DUMMY_OBJ, CV_CONTOURS_MATCH_I1)
166+
}
167+
assert_raise(TypeError) {
168+
c1.match_shapes(c2, DUMMY_OBJ)
169+
}
170+
end
171+
end

0 commit comments

Comments
 (0)