我正在编写一个函数,用于查找并返回提供给系统的任何图像的中心(它们大多是圆形对象。)
使用 OpenCV3.10 运行 findContours 方法时,该函数在 vector 类中抛出错误。这是我的代码:
cv::Mat image = next_image(cam);
cv::Mat gray; cv::Mat thresh; cv::Mat conv;
cv::Mat canny_output; cv::Mat nImg;
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
//threshold and contour the image
cv::cvtColor(image, conv, cv::COLOR_GRAY2RGB);
cv::cvtColor(conv, gray, CV_BGR2GRAY);
cv::blur(gray, gray, cv::Size(5, 5));
cv::threshold(gray, thresh, 60, 355, cv::THRESH_BINARY);
cv::findContours(thresh, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
Visual Studio 在遇到 findContours(特别是在它使用的 vector 文件中)时抛出未处理的异常,消息说
Unhandled exception at 0x5825AF78 (opencv_core310.dll) in Laser_Tracking.exe: 0xC0000005: Access violation reading location 0xDDDDDDD9.
我目前正在使用 Visual Studios 2019 来运行 OpenCV。
最佳答案
我测试并发现了你的问题。这似乎是 OpenCV 配置的问题。我的环境也是VS2019和OpenCV 3.1.0
在Linker的配置中,我添加了opencv_world310.lib和opencv_world310d.lib。也就是说,我添加了库的release和debug版本,我是在debug模式下运行的,可能对其他函数没有影响,但是findContours()函数就不一样了,所以我改了顺序两个库,或者我们可以删除其中一个库,这取决于您自己的模式。
这是我们配置Visual Studio时遗留的问题。由于没有报错,所以还没有找到问题所在。在这种情况下,我们需要养成良好的配置习惯。
关于c++ - 在 opencv_core310.dll 中使用 findContours 函数时,OpenCV 抛出未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58549268/