diff --git a/test/helper.rb b/test/helper.rb index 54ab179..8051ebc 100755 --- a/test/helper.rb +++ b/test/helper.rb @@ -14,6 +14,7 @@ class OpenCVTestCase < Test::Unit::TestCase FILENAME_FRUITS = SAMPLE_DIR + 'fruits.jpg' FILENAME_CONTOURS = File.expand_path(File.dirname(__FILE__)) + '/samples/contours.jpg' FILENAME_CHESSBOARD = SAMPLE_DIR + 'chessboard.jpg' + FILENAME_LINES = SAMPLE_DIR + 'lines.jpg' HAARCASCADE_FRONTALFACE_ALT = SAMPLE_DIR + 'haarcascade_frontalface_alt.xml.gz' AVI_SAMPLE = SAMPLE_DIR + 'movie_sample.avi' diff --git a/test/test_cvcontour.rb b/test/test_cvcontour.rb index abb697d..398011e 100755 --- a/test/test_cvcontour.rb +++ b/test/test_cvcontour.rb @@ -146,5 +146,26 @@ class TestCvContour < OpenCVTestCase assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), 1), 0.01) assert_in_delta(31.01, contour.point_polygon_test(CvPoint.new(64, 64), true), 0.01) end -end + def test_match_shapes + img1 = CvMat.load(FILENAME_CONTOURS, CV_LOAD_IMAGE_GRAYSCALE).threshold(127, 255, CV_THRESH_BINARY) + img2 = CvMat.load(FILENAME_LINES, CV_LOAD_IMAGE_GRAYSCALE).threshold(127, 255, CV_THRESH_BINARY) + c1 = img1.find_contours(mode: CV_RETR_EXTERNAL) + c2 = img2.find_contours(mode: CV_RETR_EXTERNAL) + + [CV_CONTOURS_MATCH_I1, CV_CONTOURS_MATCH_I2, CV_CONTOURS_MATCH_I3].each { |method| + assert_in_delta(0, c1.match_shapes(c1, method), 0.01) + assert_in_delta(0, c1.match_shapes(c1, method, nil), 0.01) + + assert(c1.match_shapes(c2, method) > 0) + assert(c1.match_shapes(c2, method, nil) > 0) + } + + assert_raise(TypeError) { + c1.match_shapes(DUMMY_OBJ, CV_CONTOURS_MATCH_I1) + } + assert_raise(TypeError) { + c1.match_shapes(c2, DUMMY_OBJ) + } + end +end