vehicle tracking on OpenCV2.4.11

asked 2016-06-10 04:01:40 -0500

Liphoto gravatar image

I am very new to openCV and am using 2.4.11 on visual studio 2015 I have the below code that I got off a tutorial. The code is supposed to play a video and run back ground subtraction. The code runs at times but at other times I get an

debug assertion failed _block_type_is_valid(phead- nblockuse)

How may I solve this? In addition, I aslso get arn error at

imshow("MOG", fgMaskMOG);

Is there a tutorial I can read that can show me how to buils an application that can count the number of cars passing a a camera as well as get the avarage speed at which the cars are travelling. have trie to google to find tutorials but all I find are video on youtube.

#include<opencv2\opencv.hpp>
    #include<opencv2/core/core.hpp>
    #include<opencv2/highgui/highgui.hpp>
    #include<opencv2/imgproc/imgproc.hpp>
    #include<opencv2\video\background_segm.hpp>

    #include<stdio.h>
    #include<iostream>


    using namespace std;
    using namespace cv;

    ///////////////////////////////////////////////////////////////////////////////////////////////////
    int main() 
    {
        Mat frame;
        Mat resizeF;
        Mat fgMaskMOG;
        Mat fgMaskMOG2;
        Mat fgMaskGMG;

        Ptr<BackgroundSubtractor> pMOG;
        Ptr<BackgroundSubtractor> pMOG2;
        Ptr<BackgroundSubtractorGMG> pGMG;

        pMOG = new BackgroundSubtractor();
        pMOG2 = new BackgroundSubtractorMOG2();
        pGMG = new BackgroundSubtractorGMG();
        //char filename[100] = "C:\\Users\\User\\Documents\\Visual Studio 2015\\Projects\\My OpenCV\\Template\\/video.avi";
        VideoCapture stream1("video 2.mp4");

        Mat element = getStructuringElement(MORPH_RECT, Size(3, 3), Point(1, 1));
        while (true)
        {
            Mat cameraFrame;
            if (!(stream1.read(frame)))
                break;
            resize(frame, resizeF, Size(frame.size().width / 4, frame.size().height / 4));
            pMOG->operator()(resizeF, fgMaskMOG);
            pMOG2->operator()(resizeF, fgMaskMOG2);
            pGMG->operator()(resizeF, fgMaskGMG);
            //morphologyEx(fgMaskGMG, fgMaskGMG, CV_MOP_OPEN, element);

            imshow("Origin", resizeF);
            //imshow("MOG", fgMaskMOG);
            imshow("MOG2", fgMaskMOG2);
            imshow("GMG", fgMaskGMG);

            if (waitKey(30) >= 0)
                break;
        }


        //system("pause");
        return(0);
    }
edit retag flag offensive close merge delete

Comments

you can find example on github

LBerger gravatar imageLBerger ( 2016-06-10 06:56:46 -0500 )edit