简体   繁体   English

带有Visual Studio 2013(C ++)的OpenCV:findContours断点错误

[英]OpenCV with Visual Studio 2013(C++): findContours breakpoint error

I am using OpenCV version 2.4.10. 我正在使用OpenCV版本2.4.10。

When I debug I get the breakpoint error: wkernelbase.pdb not loaded. 调试时出现断点错误:未加载wkernelbase.pdb。

Furthermore, I get this error in the output of Visual Studio: 此外,我在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.

In my application, the command line prints this out: 在我的应用程序中,命令行将其打印出来:

OpenCV Error: Assertion failed <0 <= contourIdx< <int>last> in cv::drawContours, file...\..\..\..\opencv\imgproc\src\contours.cpp, line 1810

Any suggestions as to how to deal with this? 关于如何处理这个有什么建议吗? Here is my code: 这是我的代码:

#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;
}

I know my image is in the correct directory as well. 我知道我的映像也位于正确的目录中。

This is a known compatibility issue between vs2013 and opencv 这是vs2013与opencv之间的已知兼容性问题

Try to replace 尝试更换

vector<vector<Point> > contours;

with

vector<cv::Mat> coutours;

That works in my case. 就我而言,这行得通。

I tried your code. 我尝试了您的代码。

This example (probably) doesn't make sense, but your code works. 这个示例(可能)没有意义,但是您的代码有效。

This entire thing about VC10, VC12, ... can be quite messy. 关于VC10,VC12等的整个内容可能非常混乱。 My suggestion is to try to follow the OpenCV HOWTO for Windows and Visual Studio . 我的建议是尝试遵循Windows和Visual StudioOpenCV HOWTO Maybe that way you will get around the problems you described in your question (or even find out what's wrong). 也许这样您就可以解决问题中描述的问题(甚至找出问题所在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM