2

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?

Good game
  • 84
  • 1
  • 9
  • I used that but it cant detect that – Good game Jul 17 '15 at 08:49
  • Have a look [here](http://stackoverflow.com/a/31465462/5008845) and [here](http://stackoverflow.com/a/31281725/5008845) – Miki Jul 17 '15 at 09:48
  • 1
    possible duplicate of [Android OpenCV Color detection](http://stackoverflow.com/questions/31281195/android-opencv-color-detection) – Miki Jul 17 '15 at 09:49
  • Your images are very simple. You can scan the entire image, and save in a vector the white points. If you need the bounding box simply pass this vector to cv::boundingRect(...) – Miki Jul 17 '15 at 23:39
  • scan the image get more time. – Good game Jul 18 '15 at 05:35
  • scan the image lows the FPS – Good game Jul 18 '15 at 05:36
  • If you work directly on memory with pointers it's the fastest thing you cam do. If you don't know where white pixels are, you need to scan the image, or explicitly, or within other opencv functions – Miki Jul 18 '15 at 05:39
  • I don't know where white pixels are.which function of opencv should i use.pay attention that i used color blob detector opencv sample ,but it cannot detect the white point when it comes smaller(you can see in the picture).now maybe there is a way to change this blob detector sample that i don't know , or other opencv functions.can you tell me one of these two ways? – Good game Jul 18 '15 at 13:10
  • If you have a single blob, you don't need blob detection. Just scan your image – Miki Jul 18 '15 at 14:25

1 Answers1

1

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.
Mark Miller
  • 706
  • 4
  • 14
  • I have a white point in a black background and i want to detect the point coordinate. – Good game Jul 17 '15 at 18:43
  • You can find the center of the white shape with the x and y code I supplied. If you're interested in the math behind it, check out the Wikipedia link. – Mark Miller Jul 18 '15 at 04:09
  • I don't know where white pixels are.which function of opencv should i use.pay attention that i used color blob detector opencv sample ,but it cannot detect the white point when it comes smaller(you can see in the picture).now maybe there is a way to change this blob detector sample that i don't know , or other opencv functions.can you tell me one of these two ways? – Good game Jul 18 '15 at 13:10
  • You don't need to use blob detection because you're working with binary images. It is simpler to use the Moments function, which takes the full image, and returns the center of the white points. I can write a demo program if I know what programming language you are using. – Mark Miller Jul 18 '15 at 16:18
  • I use android with opencv – Good game Jul 19 '15 at 06:29
  • @AmirhosseinMafi Updated. – Mark Miller Jul 20 '15 at 03:19
  • @Mark Hi, I have a binary image of an eye with one white circle of iris and white eyelashes, everything else is black. Is it possible to use your code to detect the iris circle? Thanks. – Dania Mar 22 '16 at 15:44