Ask Your Question

MSX01's profile - activity

2016-10-29 16:50:06 -0600 received badge  Editor (source)
2016-10-29 09:03:59 -0600 answered a question findContours - unhandled exception

I had the same problem with exceptions in OpenCV3 with VS2012.

The solution in my case was to declare the contour und history variables globaly, and not inside my function.

This throws an exception at findContours:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

DECLDIR long BCBcvCheckPresence(Mat *SourceImage) {

    vector<cv::Mat> contours;
    vector<Vec4i> hierarchy;
    findContours(&SourceImage, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
}

then i tried this and it works without exceptions:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

vector<cv::Mat> contours;     //new position
vector<Vec4i> hierarchy;       //new position

DECLDIR long BCBcvCheckPresence(Mat *SourceImage) {

    findContours(&SourceImage, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
}