How to detect circle together with aruco marker?

asked 2018-04-29 09:21:00 -0600

syazshafei gravatar image

updated 2018-04-30 21:36:11 -0600

I am building a robot soccer system using aruco marker as the robot id. The aruco marker already can be detected now i'm having problem to detect the ball. I am using Hough Circle Transform to detect the circle. I am having problem when I combined the aruco code with the hough circle code.

This is the code for hough circle transform

 #ifndef BALL_HPP
 #define BALL_HPP

 #include <vector>
 #include <opencv2/aruco.hpp>
 #include <opencv2/opencv.hpp>

 class Ball
 {  
 private:

  public:
Ball(){}
~Ball(){}

inline cv::Mat Run( cv::Mat input )
{
    cv::Mat gray;
    cv::Mat bw;
    std::vector<cv::Vec3f> circles;

    /// Convert it to gray
    cvtColor( input, gray, CV_BGR2GRAY );

    /// Reduce the noise so we avoid false circle detection
    cv::GaussianBlur( gray, gray, cv::Size( 9, 9 ), 2, 2 );
    // medianBlur( gray, gray, 5 );

    // Threshold
    threshold( gray, bw, 150, 255, 0 );

    // return bw;

    /// Apply the Hough Transform to find the circles
    cv::HoughCircles( bw, circles, CV_HOUGH_GRADIENT, 1, bw.rows / 8, 200, 60, 0, 0 );

    /// Draw the circles detected
    for( size_t i = 0; i < circles.size(); i++ )
    {
        cv::Point center( cvRound(circles[i][0]), cvRound(circles[i][1] ) );
        int radius = cvRound(circles[i][2]);

        // std::cout << radius << std::endl;

        // circle center
        cv::circle( input, center, 3, cv::Scalar( 0, 255, 0 ), -1, 8, 0 );

        // circle outline
        cv::circle( input, center, radius, cv::Scalar( 0, 0, 255 ), 3, 8, 0 );
    }

    return input;
}
 };

#endif // BALL_HPP
edit retag flag offensive close merge delete

Comments

For the circle algorithm to work, you can always alter the image to make everything but the ball pure black, and make the ball pure white. That removes ambiguity and false positives. Trust me, it works.

sjhalayka gravatar imagesjhalayka ( 2018-04-29 19:12:52 -0600 )edit

What do you mean by making everything but the ball pure black and make the ball pure white? Where can i refer to make that?

syazshafei gravatar imagesyazshafei ( 2018-04-29 21:12:03 -0600 )edit

Can I see a test image?

sjhalayka gravatar imagesjhalayka ( 2018-04-30 09:35:32 -0600 )edit

This is the link for the test image As you can see Aruco Marker is already detected but the ball cannot.

syazshafei gravatar imagesyazshafei ( 2018-04-30 21:29:59 -0600 )edit

Thank you but it just for ball tracking. I tried it won't work. I want it detect aruco marker and ball at the same time

syazshafei gravatar imagesyazshafei ( 2018-04-30 22:25:29 -0600 )edit

There is nothing stopping you from doing that. Each is a separate problem, there is nothing combining them but you. Make sure your inputs to one algorithm are not the outputs of another, they should each get the original image.

Der Luftmensch gravatar imageDer Luftmensch ( 2018-05-01 14:06:25 -0600 )edit