I played with optical stream features in OpenCV and got stuck. I have successfully created the fields and maps of the optical flux X and Y using the Farneback method, but I do not know how to apply this to the coordinates of the input image to warp the images. The resulting X and Y fields are 32-bit float (0-1.0), but how does this translate to the coordinates of the input and output images? For example, 1.0 of what? Image width? The difference between the two?
Also, I'm not sure what my loop will look like to apply the / warp transform. I have done many cycles to change the color, but the pixels always remain in one place. Moving pixels around is a new territory for me!
Update: I got this to work, but the resulting image is randomly:
IplImage *src_img = cvCreateImage(img_sz, IPL_DEPTH_32F, 1);
cvConvertScale(input_img,src_img,1/255.0);
IplImage *dst_img = cvCreateImage(img_sz, IPL_DEPTH_32F, 1);
for(y = 0; y < flow->height; y++){
float* vx = (float*)(velx->imageData + velx->widthStep*y);
float* vy = (float*)(vely->imageData + vely->widthStep*y);
const float *srcpx = (const float*)(src_img->imageData+(src_img->widthStep*y));
float *dstpx = (float*)(dst_img->imageData+(dst_img->widthStep*y));
for(x=0; x < flow->width; x++)
{
int newx = x+(vx[x]);
int newy = (int)(vy[x])*flow->width;
dstpx[newx+newy] = srcpx[x];
}
}
I could not get this to work. The output was just distorted noise:
cvRemap(src_img,dst_img,velx,vely,CV_INTER_CUBIC,cvScalarAll(0));
source
share