我正在嘗試檢測圈子,但我發現甚至沒有圈子。我的代碼如下。任何人都知道如何修改DetectCircle()方法使檢測更加準確,請和感謝正在檢測的隨機圈子
void detectCircle(IplImage * img)
{
int edge_thresh = 1;
IplImage *gray = cvCreateImage(cvSize(img->width,img->height), 8, 1);
IplImage *edge = cvCreateImage(cvSize(img->width,img->height), 8, 1);
cvCvtColor(img, gray, CV_BGR2GRAY);
gray->origin = 1;
// color threshold
cvThreshold(gray,gray,100,255,CV_THRESH_BINARY);
// smooths out image
cvSmooth(gray, gray, CV_GAUSSIAN, 11, 11);
// get edges
cvCanny(gray, edge, (float)edge_thresh, (float)edge_thresh*3, 5);
// detects circle
CvSeq* circle = cvHoughCircles(edge, cstorage, CV_HOUGH_GRADIENT, 1,
edge->height/50, 5, 35);
// draws circle and its centerpoint
float* p = (float*)cvGetSeqElem(circle, 0);
if(p==null){ return;}
cvCircle(img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(255,0,0), -1, 8, 0);
cvCircle(img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(200,0,0), 1, 8, 0);
cvShowImage ("Snooker", img);
}
你爲什麼叫'cvCanny',如果你不算賬使用'edge'結果裏面的像素? – Niki
是的,這是一個錯誤。有變化,但仍然隨機檢測圓圈 – user966890
平滑後嘗試127與另一個閾值。 – Adrian