OpenCV: MatchShapes totally wrong

Viewed 1976

I'm using the cv2.matchShapes() function in OpenCV to find the shape in an image most similar to another shape.

It's giving me some weird results, e.g. when I match the shape (a circular coin) against the shape of a sweater it returns 0.09, a close score, and a better score than when it matches against an actual coin. output output

This is my code:

    for contour in cnts:

    box = bounding_box(contour)
    orig = image.copy()
    cv2.drawContours(orig, [contour, reference_contour],
            -1, (0, 0, 255), 2)
    cv2.putText(
            orig, "SIMILARITY: {0:.4f}".format(
                cv2.matchShapes(
                    contour, reference_contour, 1, 0.0)
                ),
            (10, 70), cv2.FONT_HERSHEY_SIMPLEX, 0.65, (255, 0, 0), 2)
    cv2.imshow("coin_metric_cnn.py", orig)
    cv2.waitKey(0)

Am I doing something wrong?

0 Answers
Related