2017-01-20 14 views
1

私はオプティカルフローマップを見つけて構築しましたが、特定のしきい値を下回るベクトルを取り除きたいと思います。OpenCV:calcOpticalFlowFarnebackで得られたベクトルにフィルタを適用するには?

if (prevgray.empty() == false) { 
calcOpticalFlowFarneback(prevgray,gray,flowUmat, 0.4,1,50,2,5,1.2,0); 
flowUmat.copyTo(flow); 

for(int y=0; y<original.rows; y+=7){ 
    for (int x=0;x<original.cols;x+=7){ 

     const Point2f& flowatxy=flow.at<Point2f>(y,x); 
     line(original, Point(x,y), Point(cvRound(x+flowatxy.x*4), cvRound(y+flowatxy.y*4)), Scalar(0,255,0)); 
     theta=atan((flowatxy.y)/(flowatxy.x)); //very unsure of this 
     circle(original, Point(x,y), 0.1, Scalar(0,0,0),-1); 
    } 
} 
gray.copyTo(prevgray); 

    } 
else{gray.copyTo(prevgray);} 

私は、隣接ベクトルに、画像内のすべてのベクトルの平均に各ベクトルを比較する何かを考えていた:これは私が私のFarnebackオプティカルフローを設定している方法です。

答えて

0

特定の閾値を下回るベクトルを削除するには、まず、その長さを見積もる必要があります。長い動きベクトルを破棄する。以下のように見えるよりも、あなたのループ意志:

...  
const Point2f& flowatxy=flow.at<Point2f>(y,x); 
float flowVectorLength = flowatxy.x * flowatxy.x + flowatxy.y * flowatxy.y; 
if(flowVectorLength > threshold * threshold) 
    continue; 
... 

は、実際には、動きベクトルの長さはfloat flowVectorLength = sqrt(flowatxy.x * flowatxy.x + flowatxy.y * flowatxy.y);によって計算する必要がありますが、あなたはthresholdの四角とそれを比較することができ平方根(SQRT)の計算複雑な推定を避けるために。

関連する問題