3
#include "opencv/cvaux.h"
#include "opencv2/opencv.hpp"
#include "opencv2/opencv_modules.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "ctype.h"
#include "stdio.h"

int main(int argc, char* argv[])
{

    /* Start capturing */
    CvCapture* capture = 0;

    /*//Capture from CAM
    if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
    capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
    else if( argc == 2 )*/

    capture = cvCaptureFromAVI( "pool.avi"  );

    if( !capture )
    {
        fprintf(stderr,"Could not initialize...\n");
        return -1;
    }

    /* Capture 1 video frame for initialization */
    IplImage* videoFrame = NULL;

    videoFrame = cvQueryFrame(capture);

    if(!videoFrame)
    {
        printf("Bad frame \n");
        exit(0);
    }

    // Create windows
    cvNamedWindow("BG", 1);
    cvNamedWindow("FG", 1);
    //cvNamedWindow("Blobs", 1);
    //cvNamedWindow( "Contours",1);

    // Select parameters for Gaussian model.
    CvFGDStatModelParams* params = new CvFGDStatModelParams;
    params->Lcc=64; /* Quantized levels per 'color co-occurrence' component.  Power of two, typically 16, 32 or 64.         */
    params->N1cc=25; /* Number of color co-occurrence vectors used to model normal background color variation at a given pixel. */
    params->N2cc=40; /* Number of color co-occurrence vectors retained at given pixel.  Must be > N1cc, typically ~ 5/3 of N1cc.    */
    /* Used to allow the first N1cc vectors to adapt over time to changing background.              */
    params->is_obj_without_holes=TRUE; /* If TRUE we ignore holes within foreground blobs. Defaults to TRUE.                        */ 
    params->perform_morphing=1;/* Number of erode-dilate-erode foreground-blob cleanup iterations.                      */
    /* These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1.            */
    params->alpha1=0.1; /* How quickly we forget old background pixel values seen.  Typically set to 0.1                */
    params->alpha2=0.005; /* "Controls speed of feature learning". Depends on T. Typical value circa 0.005.                 */
    params->alpha3=0.1; /* Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1.             */
    params->delta=2; /* Affects color and color co-occurrence quantization, typically set to 2.                 */
    params->T=0.9; /* "A percentage value which determines when new features can be recognized as new background." (Typically 0.9).*/
    params->minArea=15; /* Discard foreground blobs whose bounding box is smaller than this threshold.                  */

    CvBGStatModel* bgModel = cvCreateFGDStatModel(videoFrame ,params);

    //Write FG in a file
    CvVideoWriter *writer = 0;
    int isColor = 1;
    int fps     = 25;  
    int frameW  = 640; 
    int frameH  = 480; 
    writer=cvCreateVideoWriter("out.avi",CV_FOURCC('D', 'I', 'V', 'X'),
                           fps,cvSize(frameW,frameH),isColor); 


    int key=-1;
    while(key != 'q')
    {
        // Grab a fram
        videoFrame = cvQueryFrame(capture);

        if( !videoFrame )
            { 
            break;}

        // Update model
        cvUpdateBGStatModel(videoFrame,bgModel);

        // Display results
        cvShowImage("BG", bgModel->background);
        cvShowImage("FG", bgModel->foreground);

    // Write foreground in AVI formet
    cvWriteFrame(writer,bgModel->foreground);

        key = cvWaitKey(10);
    }

    cvDestroyWindow("BG");
    cvDestroyWindow("FG");
    //cvDestroyWindow("Blobs");
    //cvDestroyWindow("Contours");

    cvWaitKey(0);

    cvReleaseBGStatModel( &bgModel );
    cvReleaseCapture(&capture);
    cvReleaseVideoWriter(&writer);

    return 0;
}

私はopencv2.3.1とビジュアルスタジオ2010を使用しています

バックグラウンド減算/フォアグラウンド抽出に FGD アルゴリズムを実装しようとしています。

私はすでに MOG アルゴリズムを正常に実装しています。次に、関数とパラメーターを MOG から FGD に変更します。

プロジェクトは Visual Studio で正常にコンパイルされましたが、機能しています: cvShowImage("BG", bgModel->background); 次のエラーが発生します。

hello_opencv_231.exe の 0x000007feef085d09 で未処理の例外: 0xC0000005: アクセス違反書き込み場所 0xffffffffcc40b40e0。

これが何かわかりません...何かアイデアはありますか?

ご協力いただきありがとうございます!

4

2 に答える 2