title: How to detect red laser light using open cv and get x,y coordinates
body: <p>I've been using the following code to detect red laser light and get the coordinates for it, but facing a problem in getting the accurate coordinates.</p>
  
  <p>Below is the code I tried to get to a solution for my problem.</p>
  
  <p>I want the accurate coordinates for the red laser light or red objects as I am using cpp code in iOS App.</p>
  
  <hr>
  
  <pre><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]};
  </code></pre>