【问题标题】:Can’t use optical flow function不能使用光流功能
【发布时间】:2020-05-09 19:12:05
【问题描述】:

我在 Visual Studio 2019 和 emgucv 3.3.0.2824 中使用。 在这个版本的 emgucv 中,我找不到光流算法。我知道在 emgucv 2.4.9.1847 版本中有opticalflow.hs 函数。但在我的版本中,我没有成功使用光流算法。在我的代码中,我将视频分割成帧并将每一帧转换为灰度。现在我想将这些帧用于光流算法。这样我的输出将是一个灰度视频,而我正在移动的对象将被标记为红色或绿色方块。

提前感谢任何可以提供帮助的人。

这是代码(在私有 async void ReadAllFrames() func 中):

private async void ReadAllFrames()
{
    Mat m = new Mat();
    //read all the frames
    while (isReadingFrames == true && FrameNo < TotalFrame)
    {
        FrameNo += Convert.ToInt16(numericUpDown1.Value);
        capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, FrameNo);
        capture.Read(m);//read the frame that we choose in the upper line
        pictureBox2.Image = m.Bitmap;
        Bitmap img = null;
        if (FrameNo < TotalFrame)
        {
            img = new Bitmap(pictureBox2.Image);
        }
        if (FrameNo < TotalFrame)
        {
            imgInput = new Image<Bgr, byte>(m.Bitmap);
            Image<Gray, byte> imgOutput =
                new Image<Gray, byte>(m.Bitmap.Width, m.Bitmap.Height, new Gray(0));
            imgOutput = imgInput.Convert<Gray, byte>();
            pictureBox3.Image = imgOutput.Bitmap;
            await Task.Delay(1000 / Convert.ToInt16(Fps));
            label1.Text = FrameNo.ToString() + "/" + TotalFrame.ToString();
        }
    }
}

【问题讨论】:

    标签: c# emgucv opticalflow


    【解决方案1】:

    我用这个:

      protected  TrackingPoint[] TrackFrame(Mat lastImage,Mat currentImage, PointF[] pointToLookFor,int index)
            {
                PointF[] nextPts;
                byte[] status;
                float[] errors;                
                CvInvoke.CalcOpticalFlowPyrLK(lastImage, currentImage, pointToLookFor, new Size(30, 30), 1, new MCvTermCriteria(20, 0.03), out nextPts, out status, out errors);
                var returnList = new List<TrackingPoint>();
                for(int i=0;i<status.Length;i++)
                {
                    returnList.Add(new TrackingPoint()
                    {
                        index=index,
                        status = status[i] == 1 ? true : false,
                        toPoint = nextPts[i],
                        fromPoint = pointToLookFor[i]
    
                    }
                        );
                }            
    
                return returnList.ToArray();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 2017-12-16
      相关资源
      最近更新 更多