0

I'am trying to detect moving circles using OpenCV/C++. My code:

   m_capture >> imageRGB;

   cv::cvtColor(imageRGB, imgageGray, cv::COLOR_RGB2GRAY);

   cv::Scalar mu;
   cv::Scalar sigma;
   cv::meanStdDev(imgageGray, mu, sigma);

   cv::Mat imageCanny;

   cv::Canny(imgageGray,
             imageCanny,
             mu.val[0] + sigma.val[0],
             mu.val[0] - sigma.val[0]);

   std::vector<std::vector<cv::Point> > contours;
   std::vector<cv::Vec4i> hierarchy;
   cv::findContours(imageCanny, contours, hierarchy,CV_RETR_TREE, CV_CHAIN_APPROX_NONE);

After this I'am checking is there any circle and is it right circle. If circle is not moving or moving slowly it's okay. https://i.stack.imgur.com/TM4sf.jpg

But if circle moving faster it's became undetectable. https://i.stack.imgur.com/1axJn.jpg

So, can somebody give me advice how to detect moving circle in a better way? UPD: My camera is Logitech c920.

  • can you show the canny images extracted from those input images? probably canny fails because there is too much motion blur – Micka Mar 09 '15 at 12:31
  • @Micka Here I'am don't moving circle http://i.imgur.com/xg0V1wK.png. And here I'am moving http://i.imgur.com/FOIZeXn.png and http://i.imgur.com/lBquYBW.png . I think it's because of camera exposure. And yes, It's blurring. –  Mar 09 '15 at 12:49
  • but approx half the circle is still visible in canny... did you try using houghCircle detection instead of extracting canny/contours first? How do you decide at the moment whether a contour is a circle or not? – Micka Mar 09 '15 at 13:44
  • @Micka `std::valarray circleCenter = {(elExt.center.x + elInt.center.x )/ 2.0, (elExt.center.y + elInt.center.y) / 2.0};` where `cv::RotatedRect elInt = cv::fitEllipse(contours.at(i)); double eInt = elInt.size.width / elInt.size.height; double dInt = (elInt.size.width + elInt.size.height) / 2.0; cv::RotatedRect elExt = cv::fitEllipse(contours.at(iExt)); double eExt = elExt.size.width/elExt.size.height; double dExt = (elExt.size.width + elExt.size.height) / 2.0;` Red point is not circle center BTW –  Mar 09 '15 at 13:51
  • so you assume closed contours... if you want to go on that way you'll need a camera with higher fps (and maybe less exposure time). You could try HoughCircle detection or RANSAC instead. – Micka Mar 09 '15 at 13:54
  • iExt here is a child contour of contours.at(i) –  Mar 09 '15 at 13:55
  • @Micka HoughCircles is better, but still not perfect. Can you give me some links about RANSAC implementation? –  Mar 09 '15 at 14:37
  • check my answer here: http://stackoverflow.com/questions/26222525/opencv-detect-partial-circle-with-noise/26234137#26234137 and my 2nd answer here: http://stackoverflow.com/questions/20698613/detect-semi-circle-in-opencv/20734263#20734263 – Micka Mar 09 '15 at 14:51

1 Answers1

0

You could use a bilateralFilter before finding the canny, this could possible improve the performance of the detection slightly, as it helps keeps the edges sharper.

http://docs.opencv.org/modules/imgproc/doc/filtering.html#void%20bilateralFilter%28InputArray%20src,%20OutputArray%20dst,%20int%20d,%20double%20sigmaColor,%20double%20sigmaSpace,%20int%20borderType%29

Eni
  • 115
  • 8