How to detect circle together with aruco marker?
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
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.
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?
Can I see a test image?
This is the link for the test image As you can see Aruco Marker is already detected but the ball cannot.
https://www.pyimagesearch.com/2015/09...
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
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.