我需要在两帧之间创建3个中间帧(prevImg, nextImg),我已经找到了opencv
中使用calcOpticalFlowFarneback()
函数的每个像素的运动
calcOpticalFlowFarneback(gray1, gray2, flow, pyrScale, pyrLevel, winSize,
iter, polyn, sigma, method);
然后我通过调用函数createNewFrame()创建了3个中间帧,下面是shift (func)。参数)值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);
}
但我没有得到适当的中间帧…从一帧到另一帧的过渡是不平滑的(闪烁)。我的代码有什么问题?我要怎么做才能得体中间帧?div ?
我认为你应该乘以你的变量shift
,而不是除以它
尝试用下面的函数替换createNewFrame
中的双循环:
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;
}
}