Find Contour method giving Error opencv

155 Views Asked by At

I am trying to create a bounding rectangle across a moving object. However, I get my Deb Session failed with an expression : _pFirstBlock == pHead

Here is my code. Need help!

This is my process video function. I am using background subtraction.

   void processVideo(char* videoFilename) {
       //create the capture object
       VideoCapture capture(videoFilename);
       if (!capture.isOpened()){
           //error in opening the video input
       cerr << "Unable to open video file: " << videoFilename <<endl;
       exit(EXIT_FAILURE);
}
//read input data. ESC or 'q' for quitting
while ((char)keyboard != 'q' && (char)keyboard != 27){
    //read the current frame
    if (!capture.read(frame)) {
        cerr << "Unable to read next frame." << endl;
        cerr << "Exiting..." << endl;
        exit(EXIT_FAILURE);
    }
    //update the background model
    //AND HERE!!!
    pMOG->operator()(frame, fgMaskMOG);
    dilate(fgMaskMOG, x, NULL);
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;

    findContours(x, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(2 ,0));


    vector<vector<Point> > contours_poly(contours.size());
    vector<Rect> boundRect(contours.size());

    for (int i = 0; i < contours.size(); i++)
    {

        approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
        boundRect[i] = boundingRect(Mat(contours_poly[i]));

    }


    // Draw polygonal contour + bonding rects + circles
    Mat drawing = Mat::zeros(x.size(), CV_8UC3);
    for (int i = 0; i< contours.size(); i++)
    {


        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
        drawContours(drawing, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point());
        rectangle(drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0);

    }
0

There are 0 best solutions below