Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Computer Vision Workshop

You're reading from  The Computer Vision Workshop

Product type Book
Published in Jul 2020
Publisher Packt
ISBN-13 9781800201774
Pages 568 pages
Edition 1st Edition
Languages
Authors (3):
Hafsa Asad Hafsa Asad
Profile icon Hafsa Asad
Vishwesh Ravi Shrimali Vishwesh Ravi Shrimali
Profile icon Vishwesh Ravi Shrimali
Nikhil Singh Nikhil Singh
Profile icon Nikhil Singh
View More author details
Toc

Contour Matching

In this section, we will learn how to numerically find the difference between the shapes of two different contours. This difference is found based on Hu moments. Hu moments (also known as Hu moment invariants) of a contour are seven numbers that describe the shape of a contour.

Note

Visit https://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html for more details.

Hu moments can be computed using OpenCV in the following way:

Image moments can be computed with the following command:

img_moments= cv2.moments(image)

The cv2.HuMoments OpenCV function is given the following moments as input:

hu_moments= cv2.HuMoments(img_moments)

This array is then flattened to get the feature vector for the Hu moments:

hu_moments= hu_moments.flatten()

This feature vector has a row with seven columns (seven numeric values).

Hu moment vectors of some sample contour shapes are shown in the following table:

...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}