Reputation: 84
I use opencv color blob detection to detect a small white point with the black background. when the point is big it can detect it ,but when the point comes small ,it cannot detect. I think there is a parameter that we can set it for small point in color blob detection sample ,but i couldn't found that.any body know that? or any body know a better and faster way to detect that white color? pay attention : in the camera there is just a white point and all of the background is black.
this is the picture of when the object is big(the camera is near to the object):
http://www.axgig.com/images/14410928700656745289.png
and this is when the object is small(the camera is far from the object):
http://www.axgig.com/images/00768609020826910230.png
I want to detect the coordinate of the white point.How?
Upvotes: 2
Views: 1172
Reputation: 706
If the entire rest of the background is black and your region of interest is white, you can find the center by using the Moments function in the Imgproc module. You can read about the math behind it at Wikipedia, but to put it simply, sums the weighted position of all nonzero points. Once you have your Moments
structure, you can compute the center by:
x = moments.m10 / moments.m00
y = moments.m01 / moments.m00
In your case, using Android and OpenCV, this is the code you will use:
// inputMat is the Mat that you took screenshots of earlier in the question.
Moments moments = Imgproc.moments(inputMat, true);
float center_x = moments.m10 / moments.m00;
float center_y = moments.m01 / moments.m00;
// now center_x and center_y have the coordinates of the center of the blob.
Upvotes: 1