本文介绍了findcontours opencv中的分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图检测一个球并画出界限。它显示错误
I am trying to detect a ball and draw boundaries to it. It shows the error
segmentation fault (core dumped)
错误在这里,
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
Mat itt = Mat::zeros( imgThresholded.size(), CV_8UC1 );
itt = imgThresholded*255;
Canny( itt ,itt, 10, 30, 3 );
vector<vector<Point> > contours_poly( contours.size() );
vector<Point2f>center( contours.size() );
vector<float>radius( contours.size() );
vector<Rect> boundRect( contours.size() );
imshow("canny", itt);
//CIRCLE HOUGH
//vector<Vec3f> circles;
findContours( itt, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
for( int i = 0; i < contours.size(); i++ )
{
Scalar color = Scalar(255,255,255);
if( contours[i].size() > points )
{approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
boundRect[i] = boundingRect( Mat(contours_poly[i]) );
minEnclosingCircle( (Mat)contours_poly[i], center[i], radius[i] );
circle( imgOriginal, center[i], (int)radius[i],color, 2, 8, 0 );
}
}
我不能理解segfault。
I am not able to understand where there is segfault.
推荐答案
在findContours之后声明其他向量,如下所示。有关进一步参考,您可以在此处。希望这解决了你的错误。我遇到了同样的错误,并得到了解决方案为这个在我已经提到的链接。
Declare other vectors after findContours as shown below. For further reference you can see here. Hope this resolves you error. I have faced the same error and got the solution for this in the link I have mentioned.
findContours( itt, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
vector<vector<Point> > contours_poly( contours.size() );
vector<Point2f>center( contours.size() );
vector<float>radius( contours.size() );
vector<Rect> boundRect( contours.size() );
这篇关于findcontours opencv中的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!