I use openCV and try to calculate the moving average of the background, then taking the current frame and subtracting the background to determine the movement (something like).
However, when I run the program, I get:
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
I cannot figure out which arguments are wrong for accumulating.
Code entered below:
#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; }
source share