【问题标题】:OpenCV: How to apply a filter on vectors obtained through calcOpticalFlowFarneback?OpenCV:如何对通过 calcOpticalFlowFarneback 获得的向量应用过滤器?
【发布时间】:2017-01-20 09:43:23
【问题描述】:

我已经找到并构建了一个光流图,现在我想删除任何低于某个阈值的向量。这就是我设置 Farneback 光流的方式:

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);}

我正在考虑将每个向量与相邻向量或图像中所有向量的平均值进行比较。

【问题讨论】:

    标签: c++ opencv opticalflow


    【解决方案1】:

    要删除任何低于某个阈值的向量,您首先需要估计长度,例如丢弃长运动向量。您的循环将如下所示:

    ...    
    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); 计算,但为了避免平方根 (sqrt) 的计算复杂估计,您可以将其与threshold 的平方进行比较。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-26
      相关资源
      最近更新 更多