title: OpenCV: Detecting LED color on a very noisy video
body: <p>I'm a newbie in OpenCV.</p>
  
  <p>I need to detect and track a colored LED in my image by getting it's contour.
  I convert my image to HSV to achieve this.</p>
  
  <p>Only problem is my stupid camera has a resolution of 176x144 pixels alongside with that there is plenty of noise.</p>
  
  <p>This is the output I get:</p>
  
  <p><a href="http://imagizer.imageshack.us/v2/766x431q90/r/661/HQSD1L.jpg" rel="nofollow noreferrer">http://imagizer.imageshack.us/v2/766x431q90/r/661/HQSD1L.jpg</a>
  <img src="https://i.stack.imgur.com/ehvbh.jpg" alt="input images"></p>
  
  <p>The code i'm using:</p>
  
  <pre><code>int main () {
  
  // Create HSV track-bar
  cv::namedWindow("track-bar");
  cv::createTrackbar("H max", "track-bar", &amp;maxH, 255);
  cv::createTrackbar("H min", "track-bar", &amp;minH, 255);
  cv::createTrackbar("S max", "track-bar", &amp;maxS, 255);
  cv::createTrackbar("S min", "track-bar", &amp;minS, 255);
  cv::createTrackbar("V max", "track-bar", &amp;maxV, 255);
  cv::createTrackbar("V min", "track-bar", &amp;minV, 255);
  cv::resizeWindow("track-bar", 0, 0);
  
  cv::Mat img;
  cv::VideoCapture cap(0);
  
  while (true) 
  {
      // Get capture
      cap &gt;&gt; img;
  
      // Declaration of hsv image
      cv::Mat hsv;
      cv::cvtColor(img, hsv, cv::COLOR_BGR2HSV_FULL);
  
      // Binalize
      cv::Mat binalized;
      cv::Scalar lower(minH, minS, minV);
      cv::Scalar upper(maxH, maxS, maxV);
      cv::inRange(hsv, lower, upper, binalized);
  
      // Show result
      cv::imshow("binalized", binalized);
  
      // Detect contours
      std::vector&lt;std::vector&lt;cv::Point&gt;&gt; contours;
      std::vector&lt;cv::Vec4i&gt; hierarchy;
  
      // Find largest contour
      int contour_index = -1;
      double max_area = 0.0;
      for (size_t i = 0; i &lt; contours.size(); i++) {
          double area = fabs(cv::contourArea(contours[i]));
          if (area &gt; max_area) {
              contour_index = i;
              max_area = area;
          }
      }
      // Object detected
      if (contour_index &gt;= 0) {
          // Moments
          cv::Moments moments = cv::moments(contours[contour_index], true);
          double marker_y = (int)(moments.m01 / moments.m00);
          double marker_x = (int)(moments.m10 / moments.m00);
  
          // Show X by Y location
          cout &lt;&lt; "X:" &lt;&lt; marker_x &lt;&lt; " Y:" &lt;&lt; marker_y &lt;&lt; endl;
  
          // Show result
          cv::Rect rect = cv::boundingRect(contours[contour_index]);
          cv::rectangle(img, rect, cv::Scalar(0, 255, 0));
      }
  
  
      // Show output
      cv::imshow("image", img);
      cv::waitKey(33);
  }
  </code></pre>
  
  <p>I have tried <code>cv::fastNlMeansDenoisingColoredMulti()</code> without any success. </p>
  
  <p>Any ideas ? </p>