Ask Your Question
0

How can i know the location of blobs/contour

asked 2017-11-17 00:10:10 -0500

zms gravatar image

updated 2017-11-17 00:10:49 -0500

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?

image descriptionimage descriptionimage description

edit retag flag offensive close merge delete

Comments

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

maybe, minAreaRect , and do something with those coords ?

berak gravatar imageberak ( 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

zms gravatar imagezms ( 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.

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

1 answer

Sort by » oldest newest most voted
1

answered 2017-11-17 03:54:41 -0500

VxW gravatar image

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.

see: https://math.stackexchange.com/questi...

or

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

edit flag offensive delete link more

Comments

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.

zms gravatar imagezms ( 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

VxW gravatar imageVxW ( 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.

zms gravatar imagezms ( 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

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

thanks very much

zms gravatar imagezms ( 2017-11-21 04:36:13 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-11-17 00:10:10 -0500

Seen: 128 times

Last updated: Nov 17 '17