title: How to map optical flow field (float) to pixel data (char) for image warping?
body: <p>I've been playing with the optical flow functions in OpenCV and am stuck. I've successfully generated X and Y optical flow fields/maps using the Farneback method, but I don't know how to apply this to the input image coordinates to warp the images. The resulting X and Y fields are of 32bit float type (0-1.0), but how does this translate to the coordinates of the input and output images? For example, 1.0 of what? The width of the image? The difference between the two?</p>
  
  <p>Plus, I'm not sure what my loop would look like to apply the transform/warp. I've done plenty of loops to change color, but the pixels always remain in the same location. Moving pixels around is new territory for me!</p>
  
  <p>Update: I got this to work, but the resulting image is messy:</p>
  
  <pre><code>//make a float copy of 8 bit grayscale source image
  IplImage *src_img = cvCreateImage(img_sz, IPL_DEPTH_32F, 1);
  cvConvertScale(input_img,src_img,1/255.0); //convert 8 bit to float
  
  //create destination image
  IplImage *dst_img = cvCreateImage(img_sz, IPL_DEPTH_32F, 1);
  
  for(y = 0; y &lt; flow-&gt;height; y++){
  
      //grab flow maps for X and Y
      float* vx = (float*)(velx-&gt;imageData + velx-&gt;widthStep*y);
      float* vy = (float*)(vely-&gt;imageData + vely-&gt;widthStep*y);
  
      //coords for source and dest image
      const float *srcpx = (const float*)(src_img-&gt;imageData+(src_img-&gt;widthStep*y));
      float *dstpx = (float*)(dst_img-&gt;imageData+(dst_img-&gt;widthStep*y));
  
      for(x=0; x &lt; flow-&gt;width; x++)
      {
          int newx = x+(vx[x]);
          int newy = (int)(vy[x])*flow-&gt;width;
          dstpx[newx+newy] = srcpx[x];
      }
  }
  </code></pre>
  
  <p>I could not get this to work. The output was just garbled noise:</p>
  
  <pre><code>cvRemap(src_img,dst_img,velx,vely,CV_INTER_CUBIC,cvScalarAll(0));
  </code></pre>