Matching contours

Hu moment invariants can be used for both object matching and recognition. In this section, we are going to see how to match contours based on Hu moment invariants. OpenCV provides cv2.matchShapes(), which can be used to compare two contours using three comparison methods. All these methods use Hu moment invariants. The three implemented methods are cv2.CONTOURS_MATCH_I1, cv2.CONTOURS_MATCH_I2, and cv2.CONTOURS_MATCH_I3.

If A denotes the first object and B denotes the second object, then the following applies:

are the Hu moments ...

Get Mastering OpenCV 4 with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.