Ask Your Question
0

cvCalcOpticalFlowFarneback Error: Assertion failed

asked 2013-12-10 15:02:57 -0600

Ricio91 gravatar image

I I'm trying to use cvCalcOpticalFlowFarneback. this is my code:

int main( int argc, char* argv ) { CvCapture webcam = cvCreateCameraCapture(0); IplImage *prev=NULL; IplImage *next=NULL;

double pyr_scale=0.5;
int levels=1;
int winsize=3;
int iterations=10;
int poly_n=5;
double poly_sigma=1.1;
int flags=0;

if (!webcam){ 
    puts("error!"); 
    return -1;
}

while (1) {
    prev = cvQueryFrame(webcam);
    next = cvQueryFrame(webcam);
    CvMat* flow = cvCreateMat(prev->height, next->width, CV_32FC2);
    cvCalcOpticalFlowFarneback(prev,next,flow,pyr_scale,levels,winsize,iterations,poly_n,poly_sigma,flags);
}

return 0;

}

I get this error: OpenCV Error: Assertion failed (prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1) in unknown function, file ........\ocv\opencv\src\cv\cvoptflowgf.cpp, line 578

where am I doing wrong? thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-12-11 00:00:59 -0600

The assertion means that both images that you pass to the function must have the same size, the only channel and pyrscale parameter must be less then one. In your case the most probable reason is invalid number of channels. cvQueryFrame returns colorful frame with three channels by default. You need to convert it to gray-scale and then pass it to optical flow algorithm.

edit flag offensive delete link more

Comments

thanks for the reply, transform them into gray like this: prev = cvQueryFrame(webcam); next = cvQueryFrame(webcam); cvCvtColor(next,nextGray,CV_RGB2GRAY ); cvCvtColor(prev,prevGray,CV_RGB2GRAY ); flow = cvCreateMat(prev->height, next->width, CV_32FC2); cvCvtColor(flow,flowGray,CV_RGB2GRAY ); cvCalcOpticalFlowFarneback(prevGray,nextGray,flowGray,pyr_scale,levels,winsize,iterations,poly_n,poly_sigma,flags); but I still get an error
OpenCV Error: Null pointer (NULL array pointer is passed) in unknown function, file ........\ocv\opencv\src\cxcore\cxarray.cpp, line 2376

: (do you know something? thank you again

Ricio91 gravatar imageRicio91 ( 2013-12-11 11:50:09 -0600 )edit

Question Tools

Stats

Asked: 2013-12-10 15:02:57 -0600

Seen: 2,183 times

Last updated: Dec 11 '13