matchShapes using grayscale images opencv [closed]
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
please try again with the grayscale images, like:
the CV_32FC2 or CV_32SC2 version expect a
vector<Point>
orvector<Point2f>
, e.g. a single contour fromfindContours()
, not an image.@berak please check edit.
oh, wait, indeed it does not work on 2.4.9, only on 3.0.
@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.
3.0 has a shape module for this purpose
arigatho @berak
@Tonystark124@berak Is this working now (from python)?
@jtlz sure it's working, op misunderstood the constraints.
if you have further questions, please start your own !
@berak - question awaiting moderation.... Right now I get:
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