Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detecting objects in OpenCV

I've got problem with detecting orange ball in OpenCV. In the pictures you see results after function inRange and the second one is thresholding. In both ways HoughCirles don't see circle which is seen in front of both pictures. They are not in good quality because of the camera, but I think that function should have no problem in recognizing circle. Thank you for all help. My code:

  `enter code here`                 
       CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours
        VideoCapture cap(0);
        if (!cap.isOpened())// if supposed not success, 
        {
                cout<<" cannot open the videofile"<<endl;// exit program
            return -1;
        }

        bool bSuccess = cap.read(src);
        if (!bSuccess)
            {
                cout<<"cannot read the frame from video file"<<endl;
                break;
            }
        imwrite("temp1.jpg",src);

        imwrite("tempblu.jpg",src);
        Mat hsv_src
        cvtColor(src, hsv_src, COLOR_BGR2HSV );
        imwrite("tempcol.jpg",hsv_src);
        inRange(hsv_src, Scalar(0, 120, 120), Scalar(30, 255, 255), hsv_src);
        imwrite("temprange.jpg",hsv_src);

          /// Reduce the noise so we avoid false circle detection
         GaussianBlur( hsv_src, hsv_src, Size(9, 9), 2, 2 );

          vector<Vec3f> circles;

          /// Apply the Hough Transform to find the circles
          HoughCircles( hsv_src, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );

          /// Draw the circles detected
          for( size_t i = 0; i < circles.size(); i++ )
          {
              Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
              int radius = cvRound(circles[i][2]);
              // circle center
              circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
              // circle outline
              circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
           }

          /// Show your results
          cout<<"Circles found: "<<circles.size()<<endl;
          namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
          imshow( "Hough Circle Transform Demo", src );

image description

image description

Detecting objects in OpenCV

I've got problem with detecting orange ball in OpenCV. In the pictures you see results after function inRange and the second one is thresholding. thresholding (which is now not in the code). In both ways HoughCirles don't see circle which is seen in front of both pictures. They are not in good quality because of the camera, camera (you can see the noise), but I think that function should have no problem in recognizing circle. Thank you for all help. My code:

  `enter code here`                 
       CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours
        VideoCapture cap(0);
        if (!cap.isOpened())// if supposed not success, 
        {
                cout<<" cannot open the videofile"<<endl;// exit program
            return -1;
        }

        bool bSuccess = cap.read(src);
        if (!bSuccess)
            {
                cout<<"cannot read the frame from video file"<<endl;
                break;
            }
        imwrite("temp1.jpg",src);

        imwrite("tempblu.jpg",src);
        Mat hsv_src
        cvtColor(src, hsv_src, COLOR_BGR2HSV );
        imwrite("tempcol.jpg",hsv_src);
        inRange(hsv_src, Scalar(0, 120, 120), Scalar(30, 255, 255), hsv_src);
        imwrite("temprange.jpg",hsv_src);

          /// Reduce the noise so we avoid false circle detection
         GaussianBlur( hsv_src, hsv_src, Size(9, 9), 2, 2 );

          vector<Vec3f> circles;

          /// Apply the Hough Transform to find the circles
          HoughCircles( hsv_src, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );

          /// Draw the circles detected
          for( size_t i = 0; i < circles.size(); i++ )
          {
              Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
              int radius = cvRound(circles[i][2]);
              // circle center
              circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
              // circle outline
              circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
           }

          /// Show your results
          cout<<"Circles found: "<<circles.size()<<endl;
          namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
          imshow( "Hough Circle Transform Demo", src );

image description

image description

image description

click to hide/show revision 3
retagged

Detecting objects in OpenCV

I've got problem with detecting orange ball in OpenCV. In the pictures you see results after function inRange and the second one is thresholding (which is now not in the code). In both ways HoughCirles don't see circle which is seen in front of both pictures. They are not in good quality because of the camera (you can see the noise), but I think that function should have no problem in recognizing circle. Thank you for all help. My code:

  `enter code here`                 
       CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours
        VideoCapture cap(0);
        if (!cap.isOpened())// if supposed not success, 
        {
                cout<<" cannot open the videofile"<<endl;// exit program
            return -1;
        }

        bool bSuccess = cap.read(src);
        if (!bSuccess)
            {
                cout<<"cannot read the frame from video file"<<endl;
                break;
            }
        imwrite("temp1.jpg",src);

        imwrite("tempblu.jpg",src);
        Mat hsv_src
        cvtColor(src, hsv_src, COLOR_BGR2HSV );
        imwrite("tempcol.jpg",hsv_src);
        inRange(hsv_src, Scalar(0, 120, 120), Scalar(30, 255, 255), hsv_src);
        imwrite("temprange.jpg",hsv_src);

          /// Reduce the noise so we avoid false circle detection
         GaussianBlur( hsv_src, hsv_src, Size(9, 9), 2, 2 );

          vector<Vec3f> circles;

          /// Apply the Hough Transform to find the circles
          HoughCircles( hsv_src, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );

          /// Draw the circles detected
          for( size_t i = 0; i < circles.size(); i++ )
          {
              Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
              int radius = cvRound(circles[i][2]);
              // circle center
              circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
              // circle outline
              circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
           }

          /// Show your results
          cout<<"Circles found: "<<circles.size()<<endl;
          namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
          imshow( "Hough Circle Transform Demo", src );

image description

image description

image description