@@ -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