我使用的是 OpenCV 2.4.10 版。
调试时出现断点错误:未加载 wkernelbase.pdb。
此外,我在 Visual Studio 的输出中得到了这个错误:
First-chance exception at 0x7543C42D in Perspective.exe: Microsoft C++ exception: cv::Exception at memory location 0x003FEDDC.
Unhandled exception at 0x7543C42D in Perspective.exe: Microsoft C++ exception: cv::Exception at memory location 0x003FEDDC.
在我的应用程序中,命令行打印出来:
OpenCV Error: Assertion failed <0 <= contourIdx< <int>last> in cv::drawContours, file...\..\..\..\opencv\imgproc\src\contours.cpp, line 1810
关于如何处理这个问题有什么建议吗?这是我的代码:
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main()
{
Mat image;
image = imread("shape.jpg", 1);
namedWindow("Display window", CV_WINDOW_AUTOSIZE);
imshow("Display window", image);
Mat gray;
cvtColor(image, gray, CV_BGR2GRAY);
Canny(gray, gray, 100, 200, 3);
/// Find contours
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
RNG rng(12345);
findContours(gray, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// Draw contours
Mat drawing = Mat::zeros(gray.size(), CV_8UC3);
for (int i = 0; i < contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
drawContours(drawing, contours, i, color, 2, 8, hierarchy, 0, Point());
}
imshow("Result window", drawing);
waitKey(0);
return 0;
}
我知道我的图片也在正确的目录中。
最佳答案
这是vs2013和opencv之间已知的兼容性问题
尝试替换
vector<vector<Point> > contours;
与
vector<cv::Mat> coutours;
这对我来说很有效。
关于c++ - 带有 Visual Studio 2013(C++) 的 OpenCV : findContours breakpoint error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30514037/