Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

The solution in my case was to declare the contor 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));
}

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

The solution in my case was to declare the contor 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));
}