1 | initial version |
For Hu-Moments you need to compute the moments first. Moments you can compute of contours as in your example (i.e. a vector of points) or of images (or part of images) (cv::Mat of type CV_8UC1 oder CV_32FC1), see http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moment#cv2.HuMoments
Example:
// From the example you posted, you already know how to compute the contours
// so let's take just the first one and compute the moments
cv::Moments mom = cv::moments(contours[0]);
double hu[7];
cv::HuMoments(mom, hu); // now in hu are your 7 Hu-Moments
For your second question: For what do you want to use the moments? Moments give you certain statistics about your image, like the sum of gray-values or center of gravity. Hu-Moments are also rotational invariant. So, they may be nice features depending on your application.