我有一个使用Qt 5.1.1和OpenCV 2.4.6的C++项目。图像处理算法在单独的线程中运行。所有工作正常,但如果我打电话给OpenCV功能findContours()
该程序崩溃与堆栈溢出消息(第一次调用此功能,而不是像它已被调用过几次)“在SARA.exe 0x56ec9a47未处理的异常:0xC00000FD:堆栈溢出。“OpenCV findContours Stack Overflow
我发现有人用same problem,但在他的情况下,它只是一个项目更改为Visual Studio 2010 ......但在我的情况下,我的项目已经在VS2010。
如果我创建一个单独的控制台项目,它只是调用图像处理算法,但我的Qt项目中的线程中的相同代码显示堆栈溢出,算法运行良好!如果我删除findContours()
功能,所有炒锅应该如此。在这两个项目中,我使用相同的库和调试DLL(版本号为xxx246d.dll),并且我正在将该程序编译为调试。
我试图让堆栈通过改变属性更大 - >配置属性 - >链接器 - >系统 - >堆栈保留大小选项,但随后的程序仍然崩溃,有不同的消息,称“未处理除了在SARA.exe 0x76e5c41f:微软C++异常:并发:: scheduler_resource_allocation_error内存位置0x14c7adc8。”
我不认为这是一个代码问题,因为它运行良好作为控制台aplication,但如果有人想看到它,它如下:
QImage SaraVisualControl::findCircles(void)
{
Mat imgInput = imread("M:/Desktop/PsEyeRight1.jpg", CV_LOAD_IMAGE_COLOR);
Mat roiInput(imgInput, Rect(Point(205, 72), Point(419,285)));
Mat imgContours = roiInput.clone();
cvtColor(imgContours, imgContours, CV_BGR2GRAY);
GaussianBlur(imgContours, imgContours, Size(3, 3), 0, 0, 4);
threshold(imgContours, imgContours, 150, 255, THRESH_BINARY); // Ou ler o Otsu uma vez e usar ele
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(imgContours, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, Point(0, 0)); // Program crashes here!
vector<RotatedRect> ellipses;
RotatedRect ellipse;
for(int i = 0; i < contours.size(); i++)
{
if(contours[i].size() >= 5)
{
ellipse = fitEllipse(contours[i]);
ellipses.push_back(ellipse);
}
else
{
Point2f center;
float radius = 0.0;
minEnclosingCircle(contours[i], center, radius);
ellipses.push_back(RotatedRect(center, Size2f(radius, radius), 0.0));
}
}
cvtColor(imgContours, roiInput, CV_GRAY2BGR);
int baseLine = 0;
const double fontScale = 0.5;
const int thickness = 1;
for(int i = 0; i < ellipses.size(); i++)
{
cv::ellipse(roiInput, ellipses[i], CV_RGB(255, 0, 0), 1, 8);
Size textSize = getTextSize(std::to_string((long long)i + 1), FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, &baseLine);
putText(roiInput, std::to_string((long long)i + 1), Point(ellipses[i].center.x - (textSize.width/2), ellipses[i].center.y + (textSize.height/2)), FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale,
Scalar(255, 255, 255), thickness, 8, false);
}
return QImage((uchar*)roiInput.data, roiInput.cols, roiInput.rows, QImage::Format_RGB32);
}
看到这一点:http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html 尝试调用findContours() – azer89
为什么这么之前,使用Canny边缘检测?这个相同的代码在控制台应用程序中运行良好... – mFeinstein
对不起,没有看到。我很久以前遇到过这个问题。在将我的解决方案中的所有项目更改为VC 2010后,问题得到解决。我也使用Qt Qt版本VC 2010也是 – azer89