简体   繁体   中英

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

I am using OpenCV version 2.4.10.

When I debug I get the breakpoint error: wkernelbase.pdb not loaded.

Furthermore, I get this error in the output of 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

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. My suggestion is to try to follow the OpenCV HOWTO for Windows and Visual Studio . Maybe that way you will get around the problems you described in your question (or even find out what's wrong).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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