- Grab the video frame.
- Convert the video frame to the HSV color space.
- Split the frame into individual components:
(separate images for H, S, and V). - Apply a threshold to each compenent (hopefully keeping just the dot from the laser). It was originally suggested that just the Hue component be used to search for the laser's dot, but I actually got several false positives doing this. Therefore, using Value in addition to Hue gave me a more reliable result. I can see where finding good threshold values for all 3 components would be a good approach in some situations.
- Finally, perform an AND operation on the 3 images (which "should" cut down on false positives)
I should note that my testing was performed using a red laser pointer and a large white sheet of paper in an well-lit office. Since I was only tracking the dot on the paper, this turned out to be a fairly easy task to accomplish. Finding good threshold values in other situations would be much more difficult.
Download this Python code: (laser_tracker.zip)
5 comments:
Why AND the images? I suppose it depends on your thresholding. How are your images thresholded? Are you thresholding around a reddish hue, high saturation, and high value? That might be better explained in your post.
I've been doing the same thing, but using Python and NumPy:
http://blog.insightvr.com/?p=17
I've actually built three games around using a laser pointer as a weapon...
Hi brian h,
Sorry I haven't gotten back to this in a few days (project deadlines and all...). I AND the separte Hue, Saturation, and Value Images so that I ONLY get pixels that are white in all 3 images.
I found experimentally that I got a few falsely identified blobs in the H image (as well as in the S and V images), but when I perform an AND on all 3 images, it resulted in identifying the blobs that occured in the same place in all three at the same time.
I don't remember the threshold values at the moment, but they're highly dependent on what color you want to track as well as your camera, the lighting in your scene, and probably a dozen other criteria. The thresholds are defined in the code, so just change the values and play around with it until you get something you like. Enjoy.
Sure, ANDing 3 binary images will result in an image that has white in all 3 images. OK, so yes, you are using various thresholds to find your expected hue, sat and value/brightness values.
I spent a lot of time on this myself for my masters thesis. A paper I wrote on that is getting publisher at ICME 2008. Here's a link to the (much longer) thesis. The shorter paper cannot be put on the web w/o special permission from IEEE.
http://brianhammond.com/thesis.pdf
i got this error:
...
File "laser_tracker.py", line 118, in main
cv.cvInRangeS(h_img, hmin, hmax, h_img)
ctypes.ArgumentError: argument 2: type 'exceptions.TypeError': expected CvScalar instance instead of int
i changed the lines 118, 119 and 120 to:
cv.cvInRangeS(h_img, cv.CvScalar(hmin), cv.CvScalar(hmax), h_img)
cv.cvInRangeS(s_img, cv.CvScalar(smin), cv.CvScalar(smax), s_img)
cv.cvInRangeS(v_img, cv.CvScalar(vmin), cv.CvScalar(vmax), v_img)
and now is working, but i'm not sure that the cv.CvScalar produce the correct result with only one argument (CvScalar need from 1 to 4 arguments)...
Do you know why i got this error?
Post a Comment