Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Contours Moments?

What are moments of a contour? Could someone explain this in simplistic, non-mathematical terms? Possibly with an example? The official explanation is "integration over all the pixels in a contour". I have no idea what integration. And also what can contour moments be used for?

like image 447
fdh Avatar asked Sep 19 '11 21:09

fdh


People also ask

What are moments in OpenCV?

In OpenCV, moments are the average of the intensities of an image's pixels. Segmentation is changing the representation of an image by dividing it into pixel segments to analyze the image easily. After segmentation, we use image OpenCV moments to describe several objects in the image.

What is approxPolyDP in OpenCV?

Working of approxPolyDP() function in OpenCV We make use of a function in OpenCV called approxPolyDP() function to perform an approximation of a shape of a contour. The image of a polygon whose shape of a contour must be approximated is read using the imread() function.

What is contour area OpenCV?

Typically, a specific contour refers to boundary pixels that have the same color and intensity. OpenCV makes it really easy to find and draw contours in images. It provides two simple functions: findContours() drawContours()


1 Answers

Moment of 0th degree for a black/white image with black=0 and white=1: this is simply the sum of the pixels, i.e. the number of white pixels.

Moment of 1st degree for x-axis and some particular point X on the x-axis: this is the sum of the white pixel distances from X. I.e. it is the sum of their positions wrt. X. If you divide this by the number of white pixels (0th moment) you get the average white pixel position wrt. X.

And similarly for y-axis.

This idea generalizes to sumOf( pixelValue(position)*position^degree ). For degree 0 the last part is just 1 so that you simply sum the pixel values. For degree 1 it becomes a sum of positions, which can give you an average position, and for degree 2 it can reportedly give you a kind of direction.

like image 69
Cheers and hth. - Alf Avatar answered Sep 23 '22 20:09

Cheers and hth. - Alf