因为我是opencv的新手,所以我一直在尝试从相机中检测圆形区域。 而且,我完全按照文档中的原样复制了代码,但它仍然总是给运行时错误。 "断言失败(半径> = 0&&厚度< = MAX_THICKNESS&& 0< = shift&& shift< = XY_SHIFT)在cv :: circle中,文件C:\ build \ master_winpack- build-win64-vc14 \ opencv \ modules \ imgproc \ src \ drawing.cpp,第1877行" 加 " opencv_trial.exe中0x00007FF913AB3C58处的未处理异常:Microsoft C ++异常:cv ::内存位置0x00000070F96EEF30处的异常。"
我的代码有点像:
int main() {
Mat image; //matrice for original image
Mat image_hsv; //matrice for hsv image
Mat image_gray;
Mat red_hue_image; //matrice for binary image
VideoCapture cap;
int camOpen = cap.open(CV_CAP_ANY);
vector<Vec3f> circles;
while (true) {
cap >> image; //intake the input of camera
if(!image.empty()) //check if camera is working
{
imshow("window", image); //showing of image
cvtColor(image,image_hsv,CV_RGB2HSV); // conversion of rgbimage to hsv
cvtColor(image,image_gray,CV_RGB2GRAY);
GaussianBlur(image_hsv,image_hsv,Size(9,9),2,2);
imshow("hsv",image_hsv); //showing of hsv image
imshow("gray",image_gray);
inRange(image_hsv,Scalar(110,100,100),Scalar(130,255,255),red_hue_image); //binary-ing for red color to be white, all others black
imshow("processed image",red_hue_image);
///////////////////////////////////////////////////
HoughCircles(image_gray,circles,CV_HOUGH_GRADIENT,1.0,image_gray.rows/8,100,100,0,1000);
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]);
// draw the circle center
circle( image_gray, center, 3, Scalar(0,255,0), -1, 8, 0 );
// draw the circle outline
circle( image_gray, center, radius, Scalar(0,0,255), 3, 8, 0 );
Vec3i c = circles[i];
circle( image, Point(c[0], c[1]), c[2], Scalar(0,0,255), 3, LINE_AA);
circle( image, Point(c[0], c[1]), 2, Scalar(0,255,0), 3, LINE_AA);
}
imshow("circles", image);
}
//延迟33ms 如果(waitKey(5)== 27){
break;
}
}
return 0;
}
如果我删除houghcircle行,我没有得到任何运行时错误,我可以看到我的camerea打开。 但是在那条线上,程序崩溃了。 拜托,任何人都可以帮我吗?
答案 0 :(得分:0)
此功能
HoughCircles(image_gray,circles,CV_HOUGH_GRADIENT,1.0,image_gray.rows/8,100,100,0,1000);
具体是最后2个参数......最小半径和最大半径,
尝试使用较小的值,如:
HoughCircles(image_gray,circles,CV_HOUGH_GRADIENT,1.0,image_gray.rows/8,100,20,0,0);