As you can see in the image, I would like to compare these contours.
I need my OpenCV program to return TRUE when of these contours are compared to each other. They all kind off look the same but as you can see they are not exactly the same.
The result you see here is what I have returned from the function findContours.
So I am looking for the right approach for similarity for these contours.
Any help would be amazing.
Thank you very much in advance.
OpenCV comes with a function cv. matchShapes() which enables us to compare two shapes, or two contours and returns a metric showing the similarity. The lower the result, the better match it is.
boundingRect() returns the 4 points of the bounding box as shown below. # The first order of the contours. c_0 = contours[0]# Get the 4 points of the bounding rectangle. x, y, w, h = cv2.boundingRect(c_0)# Draw a straight rectangle with the points.
Since OpenCV 3.2, findContours() no longer modifies the source image but returns a modified image as the first of three return parameters. In OpenCV, finding contours is like finding white object from black background. So remember, object to be found should be white and background should be black.
Take a look at cvMatchShapes()
(which used to be call cvMatchContours()
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With