I want to find alike blobs (almost of the same size and on the same开发者_StackOverflow line). Here is a sample image.
I'm using c# and opencv.
I would suggest doing a Blob detection and determine the center of gravity and the area of the blob. I am assuming that the rectangels in the image would be filled with black? If not then this step has to put before the blob extraction. With this coordinates you can calculate the difference between the points and a line. By moving the line in the image you get different "error". See here how to calculate this error (just one example)
When minimizing this error, then you have you line.
To calculate the error you might also consider first to filter the blob coordinates by the size of the blobs (only about the same size)
As you mentioned, if only same size and lying on the same line (approximately) are the criteria then here's another way of going about it.
Find connected components (guess you could loosely call that blob detecting, not sure) using the OpenCV function cvFindContours(). This link provides working code to do that.
Compute the Bounding Rectangle of each contour as you step through the list of all contours present in the picture.
The Bounding Rectangle is essentially a CvRect struct containing the x-position, y-position, width and height of the smallest rectangle that encloses the selected contour/feature.
typedef struct CvRect { int x; int y; int width; int height; } CvRect;
Naturally for your picture I'd compare the y-positions of the contours are select the ones that are close.
- Additionally the width and height fields in the structure will tell you about the similarity in size.
Note: same area may not always indicate same size. eg. a*b=ab, also (a/4)*(4b)=ab but hardly of same size. Code samples are in C but I think figuring it out in C# won't be too hard. Hope this works for you!
精彩评论