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 );
Providing your original image would help.
I've added firts photo. As you can see there is noise stripe on the left side but still ball is visible.
CvMemStorage *storage = cvCreateMemStorage(0);
O please, step away from old deprecated C functionality ... the library has moved on and focusses on C++ now. Your headaches might stop when using the proper functionality :)But I even don't use object storage. So what's its impact?
I just balance settings in HoguhCircles and it's quite okey, but I must test it on robot. Do you have any experience with Blob function?
I tried with this manual: http://www.learnopencv.com/blob-detec... ,but it's not quite working :(