# How can i know the location of blobs/contour

I had tried few methods to get the location of the contour or blobs from a moving image. Yet still could not achieve. Below are the images. I had tried using contour hierarchy but the numbering of the hierarchy does not consistent as I'm using area size and perimeter to distinguish the blobs location. Still not successful.

The only thing that i want to know is whether the smaller blobs position is at the top of the bigger blobs or at the bottom of the bigger blobs as in image 3. Anyone can help?

edit retag close merge delete

" I had tried using contour hierarchy" -- there is no hierarchy here.

maybe, minAreaRect , and do something with those coords ?

( 2017-11-17 03:45:38 -0500 )edit

hi Berak,

what i meant for hierarchy is this one. But maybe I'm wrong.

void findContours(InputOutputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())

Parameters: hierarchy – Optional output vector, containing information about the image topology. It has as many elements as the number of contours. For each i-th contour contours[i] , the elements hierarchy[i][0] , hiearchy[i][1] , hiearchy[i][2] , and hiearchy[i][3] are set to 0-based indices in contours of the next and previous contours at the same hierarchical level, the first child contour and the parent contour, respectively. If for the contour i there are no next, previous, parent, or nested contours, the corresponding elements of hierarchy[i] will be negatve

( 2017-11-17 12:53:21 -0500 )edit

"nested contours" -- that's the keyword, here. your images don't have any of that

think of an "O", there's an outer ring and and an inner one, again not at all your problem here.

( 2017-11-17 12:59:10 -0500 )edit

Sort by » oldest newest most voted

Hi,

I would fit a line through the big blob (or take the maxima points of the big blob, i.e. highest and lowest to specify a line) and check afterwards if e.g. the center of gravity of the small blobs is on the left or right side of the line.

or

https://stackoverflow.com/questions/1...

more

Hi VxW, at the moment i had successfully draw the line (top most - bottom most) in the bigger contour. the center gravity is referring to the centroid?

from the link answer, i tried to understand - what is the vectors of (AB,AM) and i understand M(X,Y) is the new centroid?

Use the sign of the determinant of vectors (AB,AM), where M(X,Y) is the query point: position = sign((Bx - Ax) * (Y - Ay) - (By - Ay) * (X - Ax)) It is 0 on the line, and +1 on one side, -1 on the other side.

( 2017-11-19 23:26:53 -0500 )edit

Yes, M is the centroid or the query point and AB,AM the vector.

Or...

public bool isLeft(Point a, Point b, Point c){
return ((b.X - a.X)*(c.Y - a.Y) - (b.Y - a.Y)*(c.X - a.X)) > 0;
}


Where a = line point 1; b = line point 2; c = point to check against (from here

( 2017-11-20 03:17:14 -0500 )edit

Hi, I'm a bit confuse here what does it mean of Point a, Point b, Point c? is it a coordinate pair?

For example from the big contours i got this line draw from TopMost [ 1, 53 ] BottomMost [ 373, 190 ] and my centroid of the contour that I want to check the position is [118.741, 79.795] centroid mc[0].

M(X,Y) is the centroid coordinate, but a, b and c, I don't really understand. Sorry.

( 2017-11-20 06:23:25 -0500 )edit
1

a.x = 1 a.y = 53 b.x=373 b.y=190 c.x=118 c.y=79

if I'm using the formula above I get the value -6357, which should be on the right side

( 2017-11-20 06:51:34 -0500 )edit

thanks very much

( 2017-11-21 04:36:13 -0500 )edit

Official site

GitHub

Wiki

Documentation