Échec de l'Assertion avec accumulateWeighted dans OpenCV

Je suis en utilisant openCV et à essayer de calculer une moyenne mobile de l'arrière-plan, puis en prenant l'image en cours et de soustraction du fond de déterminer le mouvement (de quelque sorte).

Toutefois, lorsque vous exécutez le programme, j'obtiens:

OpenCV Error: Assertion failed (func != 0) in accumulateWeighted, file /home/sebbe/projekt/opencv/trunk/opencv/modules/imgproc/src/accum.cpp, line 431
terminate called after throwing an instance of 'cv::Exception'
what():  /home/sebbe/projekt/opencv/trunk/opencv/modules/imgproc/src/accum.cpp:431: error: (-215) func != 0 in function accumulateWeighted

Je ne peux peut-être voir quels sont les arguments sont mauvais pour accumulateWeighted.

Code inséré ci-dessous:

#include <stdio.h>
#include <stdlib.h>
#include "cv.h"
#include "highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "cxcore.h"

using namespace cv;

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

    Mat  colourFrame;
Mat  frame;
Mat greyFrame;
Mat movingAverage;
Mat difference;
Mat temp;

    int       key = 0;
VideoCapture cap(0);


/* always check */
    if ( !cap.isOpened() ) {
        fprintf( stderr, "Cannot open initialize webcam!\n" );
        return 1;
    }

namedWindow("Camera Window", 0);

//Initialize
cap >> movingAverage;

    while( key != 'q' ) {
      /* get a frame */

  cap >> colourFrame;

  /* Create a running average of the motion and convert the scale */

  accumulateWeighted(colourFrame, movingAverage, 0.02, Mat() );

  /* Take the difference from the current frame to the moving average */
  absdiff(colourFrame, movingAverage, difference);

  /* Convert the image to grayscale */
  cvtColor(difference, greyFrame, CV_BGR2GRAY);

  /* Convert the image to black and white */
  threshold(greyFrame, greyFrame, 70, 255, CV_THRESH_BINARY);

        /* display current frame */
    imshow("Camera Window",greyFrame);

        /* exit if user press 'q' */
        key = cvWaitKey( 1 );
    }

    return 0;
}

OriginalL'auteur Sebastian Abrahamsson | 2011-08-14