c++ - which one the following centroid is the centroid of object in image? -


i want mass center of circle shape binary image, output give more 1 mass center. i'm using code opencv web tutorial document image moment , modified little bit. fyi, i'm using c++ api opencv.

and output is:

aq38s.jpg

i expect, text output give maybe 3 centroid 3 contour, reality 7 contours (contours[0],...,contours[6]).

which 1 centroid? or, 1 contour area of circle shape?

then modified code, remove contours (because real picture noise, , want specific contours, circle shape, must remove other contours, line , character) using:

contours.erase() 

i want centroid area contour between 100 till 500.

but, output become strange..

xndlz.jpg

the centroids fly anywhere contours.
then, still, there 5 centroid 5 contours (contours[0],...,contours[4]).

what must do? want centroid of circle shape (above number 3). i'm need advice. thank much! :d

*sorry bad english..

what do:

  1. find contours (and store in vector of point) (cv::findcontours)
  2. apply custom particle filter. is, function tell whether contour valid. that, need base decision on morphological features such as

    • circularity
    • convexity
    • aspect ratio

take @ like that have visual examples: can calculate circularity area (cv::contourarea) , perimeter (cv::arclength) while convexity involve computing convex hull (cv::convexhull). step should result in new vector containing valid (e.i. circular contours).

your contourarea(contours[i], false) < 100 start, not tell whether contour circle.

after that, can calculate centre of gravity (and display it) of each element of new vector. make sense ?

finally, not use contours.erase() large vectors. think iteratively erasing heavy job cpu. instead, store contours in new preallocated vector. performance detail.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -