Hi guys, I just began learning how to use OpenCV library. I'm using VS2013(update 3) + OpenCV 3.0 Beta.
I'm encountering some error when trying to use findContours(). I get some unhandled exceptions in opencv_world300.dl. I've searched the web for findContours() related errors and I know that it should get a single channel B&W image, so that's what I do:
include "stdafx.h"
include "opencv2/core/core.hpp"
include "opencv2/flann/miniflann.hpp"
include "opencv2/imgproc/imgproc.hpp"
include "opencv2/photo/photo.hpp"
include "opencv2/video/video.hpp"
include "opencv2/features2d/features2d.hpp"
include "opencv2/objdetect/objdetect.hpp"
include "opencv2/calib3d/calib3d.hpp"
include "opencv2/ml/ml.hpp"
include "opencv2/highgui/highgui.hpp"
include "opencv2/core/core_c.h"
include "opencv2/highgui/highgui_c.h"
include "opencv2/imgproc/imgproc_c.h"
include <iostream>
include <vector>
using namespace cv; using namespace std;
int _tmain(int argc, _TCHAR* argv[]) { cv::Mat frame, frame_gray, threshImg; cv::Mat back; cv::Mat fore; cv::VideoCapture cap; cap.open(1); if (!cap.isOpened()) { std::cerr << "ERROR: Could not access the camera!" << std::endl; }
Ptr<BackgroundSubtractorMOG2> bg = createBackgroundSubtractorMOG2(500, 16, false);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
cv::namedWindow("Frame");
cv::namedWindow("Foreground");
cv::namedWindow("Background");
for (;;)
{
cap >> frame;
bg->apply(frame, fore);
bg->getBackgroundImage(back);
cv::erode(fore, fore, cv::Mat());
cv::dilate(fore, fore, cv::Mat());
cvtColor(fore, threshImg, CV_BGR2GRAY);
findContours(threshImg, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
cv::imshow("Frame", frame);
cv::imshow("Background", back);
cv::imshow("Foreground", fore);
if (cv::waitKey(30) >= 0) break;
}
return 0;
}
Any clue what I'm doing wrong? :)
Thanks!