Laser Detection with OpenCV and C ++

I want to track the point of the laser beam (which is on the wall) using a webcam, and I use openCV to complete this task. can anyone suggest me a way to do this using C ++.

Thanks!

+7
c ++ opencv background-subtraction feature-detection webcam
source share
6 answers

You have three options, depending on the stability of your background and what you want to do with the image.

You can make your image so dark that the only thing you can see is a laser dot. You can do this by closing the aperture and / or reducing shutter time. Even with cheap webcams, this can usually be done in the driver. Once you do this, finding a laser dot is very simple. You make the image as dark as possible because usually the point at which the laser is shining is too bright for the camera to pick up. This means that you cannot distinguish between a light laser dot and other light objects in the image. By making it darker, you can now do it.

If you have another use for your image (showing it to people) and your background is stable, you can also use the average of the last few video images as a โ€œbackgroundโ€, and then find a place where there is a big difference between this background and the newest image . This is usually a laser pointer (again, if your background is stable enough).

Finally, if your background is unstable and you do not want your image to be very dark, your last option is to look for all the bright bright pixels and are brighter in the red channel than in the green and blue (if you use a red laser). This system will continue to be distracted by white spots, but not so much as just finding bright pixels. If the center of your laser pointer spot really appears bright white, regardless of the color of the laser, then this method will allow you to find the โ€œringsโ€ around this bright spot (the outer part of the point where the laser is not as bright as it is in the center so that it displayed with the actual laser color in the image). You can then use simple morphological operations (possibly closing ) to fill these circles.

+7
source share

Let's say you use a laser in one of these colors: red, green, blue. If the laser dot seems very bright (in at least one channel, like red), then a simple threshold image / channel, say greyvalue 200, will leave you with a few candidates for laser light. If other channels are dark (er) in this area, then you know that it is a bright light of the correct color. Slight filtering by size, and you have a good chance of finding a place.

+4
source share

If you insert an IR filter on your webcam, your projection will not be raised, which will greatly facilitate the detection of a laser point (using simple background subtraction, etc.). Assuming the laser pointer emits infrared light ...

+3
source share

As suggested in other answers, finding a color might be a good idea. You should consider looking for a specific color range. The best way to do this is to convert the image to the HSL or HSV color space.

cv::cvtColor(src, hsv, COLOR_BGR2HSV); 

Additional information on Wikipedia .

Then you have three channels: hue (= color), saturation, and lightness (or value).

With cv::inRange(hsv, cv::Scalar(159, 135, 165), cv::Scalar(179, 255, 200), inRange); Now you can create a black and white image that shows which pixels are in the color scheme. Scalars are low and high values โ€‹โ€‹for each channel.

In this example, you get pixels with a color of 159 to 179 (hue), a saturation between 135 and 255, and a value between 165 and 200.

Perhaps this can improve your tracking.

+1
source share

How about this code

https://www.youtube.com/watch?v=MKUWnz_obqQ

https://github.com/niitsuma/detect_laser_pointer

In this code, the observed HSV color is compared with the registered color using the Holing criterion t square

+1
source share

try the Maching Template. first you point to a specific place so that the temple can be made. Then you just look for it.

Or, as jilles de wit said, you can distinguish the last 2 frames, maybe the difference will show you the pointer.

Convert the last 2 frames to grayscale, then apply the SUB function.

0
source share

All Articles