c++ - 带有 Visual Studio 2013(C++) 的 OpenCV : findContours breakpoint error

标签 c++ visual-studio-2010 opencv visual-studio-2012

我使用的是 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/

相关文章:

c++ - 宏 htonl 将内部逗号解释为参数分隔符

c++ - 派生类未被识别为协变

.net - 自动将源代码文件移动到 Visual Studio 2008/2010 中的项目文件夹,这些文件作为链接添加并驻留在项目文件夹之外

c++ - 如何使正在等待某个事件的 C++ 程序出现响应?

c++ - 如何在 std::string 中存储 const char*?

visual-studio-2010 - 为什么 Visual Studio 解决方案不再绑定(bind)到 Visualsvn

c# - bool 作为 CheckBox 的数据源(Bool 在另一个线程中更新而不是它正在影响的线程)

java - onPictureTaken() 错误,问题是无法将 RGB 转换为灰色,程序停止从 cvtcolor() 函数运行。?

python - OpenCV:如何获取cv2.fisheye.un DistorImage后一个点的位置?

c++ - cv::FileStorage 在 Qt 中不起作用