Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cvCalcOpticalFlowLK issue

So, I'm running a simple cvCalcOpticalFlowLK code but I can't seem to get any flow information nor I can visualize it. Can anyone help me? My code is below:

int main()
{
//First get two images from a AVI file.
CvCapture* pCapture= cvCaptureFromFile("C:\\Users\\Elvan\\Desktop\\UCF Crowd Dataset\\861-13_70.mov");
IplImage *src1=cvQueryFrame(pCapture);

while(IplImage *src2=cvQueryFrame(pCapture))
{

CvSize cvsize;
cvsize.width=src1->width;
cvsize.height=src1->height;


IplImage* Graysrc1=cvCreateImage(cvsize,IPL_DEPTH_8U,1);
cvCvtColor(src1,Graysrc1,CV_RGB2GRAY);

IplImage* Graysrc2=cvCreateImage(cvsize,IPL_DEPTH_8U,1);
cvCvtColor(src2,Graysrc2,CV_RGB2GRAY);


IplImage* flowX=cvCreateImage(cvsize,IPL_DEPTH_32F,1);
IplImage* flowY=cvCreateImage(cvsize,IPL_DEPTH_32F,1);

cvsize.width=3;
cvsize.height=3;

cvCalcOpticalFlowLK(Graysrc1,Graysrc2,cvsize,flowX,flowY);

for (int x=0; x<cvsize.width; x=x+10) {
for (int y=0; y<cvsize.width; y=y+10) {
int vel_x_here = (int)cvGetReal2D( flowX, y, x);
int vel_y_here = (int)cvGetReal2D( flowY, y, x);
cvLine( Graysrc2, cvPoint(x, y), cvPoint(x+vel_x_here,
y+vel_y_here), cvScalarAll(255));
}
}



cvShowImage("Velx",flowX);
cvShowImage("Vely",flowY);
src1=src2;
cvWaitKey(1);

}


return 0;
}