I am working with visual-studio and opencv lib and I have been trying to use findContours() but no matter what parameters I give the function it always triggers a break-point,
I have tried to make the image binary (b&w), reinstalling the library in different versions, messing with the linker preferences and anything I'v found on the web.
(this code is one of many i found on the web - they all crush one they get to findContours)
Does anyone know how to solve this problem ?
#include <iostream>
#include <vector>
#include "opencv2/opencv.hpp"
using namespace cv;
using std::vector;
int main()
{
vector<vector<cv::Point>> contours = vector<vector<cv::Point>>();
vector<Vec4i> hierarchy;
Mat frame, cont, threshold_;
VideoCapture capture = VideoCapture(0);
if (!capture.isOpened())
{
return -1;
}
while (true)
{
capture >> frame;
if (frame.empty()) break;
cont = frame.clone();
cvtColor(cont, cont, COLOR_BGR2GRAY);
cv::threshold(cont, cont, 128, 255, THRESH_BINARY);
threshold_ = cont.clone();
findContours(cont, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);
for (unsigned int i = 0; i < contours.size(); i++)
{
drawContours(frame, contours, i, Scalar(0, 0, 255), 2);
}
imshow("Contour", threshold_);
imshow("Video", frame);
if (cv::waitKey(30) == 'q')
{
break;
}
}
return 0;
}