Ask Your Question

adliner's profile - activity

2017-12-25 10:03:22 -0600 received badge  Notable Question (source)
2016-10-17 06:54:59 -0600 received badge  Popular Question (source)
2015-02-28 15:37:12 -0600 answered a question OpenCV 3.0 BETA - can't open video files

Perhaps some file access permission problem here? Have you tried running with privileged rights? Or maybe you should specify the full path to video file, CWD could be set to some other location than you expect.

2015-02-28 15:25:41 -0600 received badge  Editor (source)
2015-02-28 15:18:48 -0600 asked a question findContours - unhandled exception

Hi guys, I've 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.dll. 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:

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!

UPDATE: Also I tried the code found at: http://stackoverflow.com/questions/84...

int countours(Mat _image) { cv::Mat image = _image; if (!image.data) { std::cout << "Image file not found\n"; return 1; }

//Prepare the image for findContours
cv::cvtColor(image, image, CV_BGR2GRAY);
cv::threshold(image, image, 128, 255, CV_THRESH_BINARY);

//Find the contours. Use the contourOutput Mat so the original image doesn't get overwritten
std::vector<std::vector<cv::Point> > contours;
cv::Mat contourOutput = image.clone();
cv::findContours(contourOutput, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);

//Draw the contours
cv::Mat contourImage(image.size(), CV_8UC3, cv::Scalar(0, 0, 0));
cv::Scalar colors[3];
colors[0] = cv::Scalar(255, 0, 0);
colors[1] = cv::Scalar(0, 255, 0);
colors[2] = cv::Scalar(0, 0, 255);
for (size_t idx = 0; idx < contours.size(); idx++) {
    cv::drawContours(contourImage, contours, idx, colors[idx % 3]);
}

cv::imshow("Input Image", image);
cvMoveWindow("Input Image", 0, 0);
cv::imshow("Contours", contourImage);
cvMoveWindow("Contours", 200, 0);
cv::waitKey(0);

return 0;

}

and I'm also hitting a break point with a 'Critical error detected c0000374' message in debug output.

UPDATE 2: Looks like it's a bug in opencv_world300.dll - I renamed opencv_world300d.dll to opencv_world300.dll and placed it binary directory and it works now. It must be some bug in release version of library, maybe some compiler optimization doesn't work properly.