// in-place median blur for optical flow
void MedianBlurFlow(Mat& flow, const int ksize)
{
Mat channels[2];
split(flow, channels);
medianBlur(channels[0], channels[0], ksize);
medianBlur(channels[1], channels[1], ksize);
merge(channels, 2, flow);
}
void FarnebackPolyExpPyr(const Mat& img, std::vector& poly_exp_pyr,
std::vector& fscales, int poly_n, double poly_sigma)
{
Mat fimg;
for(int k = 0; k < poly_exp_pyr.size(); k++)
{
double sigma = (fscales[k]-1)*0.5;
int smooth_sz = cvRound(sigma*5)|1;
smooth_sz = std::max(smooth_sz, 3);
int width = poly_exp_pyr[k].cols;
int height = poly_exp_pyr[k].rows;
Mat R, I;
img.convertTo(fimg, CV_32F);
GaussianBlur(fimg, fimg, Size(smooth_sz, smooth_sz), sigma, sigma);
resize(fimg, I, Size(width, height), CV_INTER_LINEAR);
FarnebackPolyExp(I, R, poly_n, poly_sigma);
R.copyTo(poly_exp_pyr[k]);
}
}
void calcOpticalFlowFarneback(std::vector& prev_poly_exp_pyr, std::vector& poly_exp_pyr,
std::vector& flow_pyr, int winsize, int iterations)
{
int i, k;
Mat prevFlow, flow;
for( k = flow_pyr.size() - 1; k >= 0; k-- )
{
int width = flow_pyr[k].cols;
int height = flow_pyr[k].rows;
flow.create( height, width, CV_32FC2 );
if( !prevFlow.data )
flow = Mat::zeros( height, width, CV_32FC2 );
else {
resize( prevFlow, flow, Size(width, height), 0, 0, INTER_LINEAR );
flow *= scale_stride;
}
Mat R[2], M;
prev_poly_exp_pyr[k].copyTo(R[0]);
poly_exp_pyr[k].copyTo(R[1]);
FarnebackUpdateMatrices( R[0], R[1], flow, M, 0, flow.rows );
for( i = 0; i < iterations; i++ )
FarnebackUpdateFlow_GaussianBlur( R[0], R[1], flow, M, winsize, i < iterations - 1 );
MedianBlurFlow(flow, 5);
prevFlow = flow;
flow.copyTo(flow_pyr[k]);
}
ifndef OPTICALFLOWH
define OPTICALFLOWH
include "DenseTrackStab.h"
include
using namespace cv;
namespace my {
static void FarnebackPolyExp( const Mat& src, Mat& dst, int n, double sigma ) { int k, x, y;
}
static void FarnebackUpdateMatrices( const Mat& _R0, const Mat& _R1, const Mat& _flow, Mat& matM, int _y0, int _y1 ) { const int BORDER = 5; static const float border[BORDER] = {0.14f, 0.14f, 0.4472f, 0.4472f, 0.4472f};
}
static void FarnebackUpdateFlow_GaussianBlur( const Mat& _R0, const Mat& _R1, Mat& _flow, Mat& matM, int block_size, bool update_matrices ) { int x, y, i, width = _flow.cols, height = _flow.rows; int m = block_size/2; int y0 = 0, y1; int min_update_stripe = std::max((1 << 10)/width, block_size); double sigma = m*0.3, s = 1;
if CV_SSE2
endif
if CV_SSE2
endif
if CV_SSE2
endif
}
// in-place median blur for optical flow void MedianBlurFlow(Mat& flow, const int ksize) { Mat channels[2]; split(flow, channels); medianBlur(channels[0], channels[0], ksize); medianBlur(channels[1], channels[1], ksize); merge(channels, 2, flow); }
void FarnebackPolyExpPyr(const Mat& img, std::vector& poly_exp_pyr,
std::vector& fscales, int poly_n, double poly_sigma)
{
Mat fimg;
}
void calcOpticalFlowFarneback(std::vector& prev_poly_exp_pyr, std::vector& poly_exp_pyr,
std::vector& flow_pyr, int winsize, int iterations)
{
int i, k;
Mat prevFlow, flow;
}
}
endif /OPTICALFLOWH/