matchShapes using grayscale images opencv [closed]

asked 2015-04-24 13:59:54 -0600

Tonystark124 gravatar image

updated 2015-04-25 12:10:07 -0600

According to the matchShapes documentation, the input can be either gray scale images or contours. But when I tried two gray scale images, I got an assertion failed error. Upon further exploration, I found from here that the Mat object has to be a 1D vector and of type CV_32FC2 or CV_32SC2.

Using this answer, I converted the images to vector array of float after converting them to CV_32FC2. I still get an assertion error.

Can anyone tell me how can I compare 2 grayscale images using matchShapes function?

UPDATE

as asked in comments, I tried with 2 grayscale images. and this is the error I got

OpenCV Error: Assertion failed (contour1.checkVector(2) >= 0 && contour2.checkVector(2) >= 0 && (contour1.depth() == CV_32F || contour1.depth() == CV_32S) && contour1.depth() == contour2.depth()) in matchShapes, file /home/tonystark/Opencv/modules/imgproc/src/contours.cpp, line 1936 terminate called after throwing an instance of 'cv::Exception' what(): /home/tonystark/Opencv/modules/imgproc/src/contours.cpp:1936: error: (-215) contour1.checkVector(2) >= 0 && contour2.checkVector(2) >= 0 && (contour1.depth() == CV_32F || contour1.depth() == CV_32S) && contour1.depth() == contour2.depth() in function matchShapes

Just curious, anything to do with my opencv version? it is 2.4.9

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-07 13:11:28.492753

Comments

2

please try again with the grayscale images, like:

double dist = matchShapes(gray1, gray2, CV_CONTOURS_MATCH_I1, 0);

the CV_32FC2 or CV_32SC2 version expect a vector<Point> or vector<Point2f> , e.g. a single contour from findContours() , not an image.

berak gravatar imageberak ( 2015-04-25 00:44:59 -0600 )edit
1

@berak please check edit.

Tonystark124 gravatar imageTonystark124 ( 2015-04-25 12:09:07 -0600 )edit

oh, wait, indeed it does not work on 2.4.9, only on 3.0.

berak gravatar imageberak ( 2015-04-25 12:44:10 -0600 )edit

@berak and can you please tell me how accurate it is? And are there functions in 3.0, that help in achieving tasks much, easier and better compared to 2.4.9? Any suggestions would help.

Tonystark124 gravatar imageTonystark124 ( 2015-04-26 00:48:00 -0600 )edit
2

3.0 has a shape module for this purpose

berak gravatar imageberak ( 2015-04-26 01:23:33 -0600 )edit

arigatho @berak

Tonystark124 gravatar imageTonystark124 ( 2015-04-26 13:27:02 -0600 )edit

@Tonystark124@berak Is this working now (from python)?

jtlz2 gravatar imagejtlz2 ( 2017-07-19 06:26:20 -0600 )edit

@jtlz sure it's working, op misunderstood the constraints.

if you have further questions, please start your own !

berak gravatar imageberak ( 2017-07-19 07:32:35 -0600 )edit

@berak - question awaiting moderation.... Right now I get:

 ret = cv2.matchShapes(img1,img2,1,0.0)

cv2.error: /tmp/opencv-20170224-1869-10nlf6f/opencv-2.4.13.2/modules/imgproc/src/contours.cpp:1941: error: (-215) contour1.checkVector(2) >= 0 && contour2.checkVector(2) >= 0 && (contour1.depth() == CV_32F || contour1.depth() == CV_32S) && contour1.depth() == contour2.depth() in function matchShapes

jtlz2 gravatar imagejtlz2 ( 2017-07-19 08:01:28 -0600 )edit