1

I need to create 3 intermediate frames between two frames (prevImg, nextImg), I have found out the motion of each pixel using calcOpticalFlowFarneback() function in opencv

  calcOpticalFlowFarneback(gray1, gray2, flow, pyrScale, pyrLevel, winSize,
                           iter, polyn, sigma, method);

then I have created 3 intermediate frames by calling the function createNewFrame(), with following shift (func. argument) values 0.25, 0.5, 0.75

void createNewFrame(Mat & frame, const Mat & flow, float shift, int & c, Mat & prev, Mat &next)
{
  for (int y = 0; y < mapX.rows; y++)
  {
    for (int x = 0; x < mapX.cols; x++)
    {
      Point2f f = flow.at<Point2f>(y, x);
      mapX.at<float>(y, x) =  x + f.x/shift;
      mapY.at<float>(y, x) =  y + f.y/shift;
    }
  }
  remap(frame, newFrame, mapX, mapY, INTER_LINEAR);
}

But I am not getting proper intermediate frames.. the transition from one frame to other is non smooth (flickering). What is the problem in my code ? What I need to do to get proper intermediate frames ? ?

3
  • interpolation between frames is an active research topic and getting good results is very difficult, particularly on motion/object boundaries. Anyway, your questions implies you are hitting problems earlier. If I understand your algorithm correctly, you are "moving" the pixels of the first image along the motion vectors. Is that correct? What do you mean with 'non-smooth'? Which parts of the intermediate frames do not give the correct result?
    – P.R.
    Commented Jul 28, 2015 at 13:04
  • @user_12 can you give sample images? we might be able to have a better idea of what is wrong with the intermediate frames.
    – AruniRC
    Commented Jul 28, 2015 at 23:46
  • I have added my program in compilable form
    – Deepak
    Commented Jul 29, 2015 at 12:03

1 Answer 1

1
+50

I think you should be multiplying by your variable shift, not dividing by it.

Try replacing your double loop in function createNewFrame by the following one:

  for (int y = 0; y < mapX.rows; y++)
  {
    for (int x = 0; x < mapX.cols; x++)
    {
      Point2f f = flow.at<Point2f>(y, x);
      mapX.at<float>(y, x) =  x + f.x*shift;
      mapY.at<float>(y, x) =  y + f.y*shift;
    }
  }
5
  • still there is a small amount of non smooth transition from one frame to other, what I need to do to resolve that..
    – Deepak
    Commented Jul 30, 2015 at 2:24
  • Unfortunately, the optical flow estimated by calcOpticalFlowFarneback is not perfect. Did you try to visualize it, by setting shift to 1. ?
    – BConic
    Commented Jul 30, 2015 at 5:22
  • I didnt try that... is there any other method to achieve my aim ?.
    – Deepak
    Commented Jul 30, 2015 at 5:26
  • is there any other function in opencv which gives more accurate results than calcOpticalFlowFarneback()
    – Deepak
    Commented Jul 30, 2015 at 5:27
  • There are a few other functions for dense optical flow (see on the OpenCV documentation here), you can check if one of them gives more accurate results. However accurate dense optical flow is still an active field of research, so it is likely none of them will give perfect results...
    – BConic
    Commented Jul 30, 2015 at 6:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.