Detecting red laser color and get coordinates of the red laser color using open cv cpp code.
I am trying to detect a red laser using open cv cpp code on a mat image. But I find it difficult to track the colour range for red color. I want to detect 7 circles with black border color and then detect in which circle does my red laser hits.
I am currently using the following code.
cv::Mat bgr_image; UIImageToMat(image, bgr_image); cv::Mat hsv_image; cv::cvtColor(bgr_image, hsv_image, cv::COLOR_BGR2HSV);
cv::Mat lower_red_hue_range; cv::Mat upper_red_hue_range; cv::Mat allRedHue;
cv::inRange(hsv_image, cv::Scalar(0, 100, 100), cv::Scalar(10, 255, 255), lower_red_hue_range); cv::inRange(hsv_image, cv::Scalar(160, 100, 100), cv::Scalar(179, 255, 255), upper_red_hue_range); cv::addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0, allRedHue); Moments m = moments(allRedHue, true); Point2f p = Point2f(m.m10/m.m00, m.m01/m.m00); p == p? dict = @{@"xPoint":[NSNumber numberWithFloat:p.x],@"yPoint":[NSNumber numberWithFloat:p.y]} : dict = @{@"xPoint":[NSNumber numberWithFloat:0.0],@"yPoint":[NSNumber numberWithFloat:0.0]};
Please help to find a perfect solution for this problem. I want the accurate coordinates for the red laser light or red objects as I am using cpp code in iOS App.
Have you tried splitting the image into separate r, g, b images? https://docs.opencv.org/2.4/modules/c... What does the r channel look like? Can you share an example image with us?