【问题标题】:Point Tracking using Optical Flow使用光流的点跟踪
【发布时间】:2014-07-03 08:41:55
【问题描述】:

您好,我正在尝试将点跟踪应用于场景。

现在我想让点只水平移动。有人对此有任何想法吗? 数组“Actual”和“nextfeature”包含相关的 x,y 坐标。我试图从两个数组中得到区别,它没有用。我尝试使用 Farneback 获得光流,但它没有给我一个令人满意的结果。如果有人能给我任何关于如何让点只在水平线上移动的想法,我将不胜感激。

谢谢。

这里是代码。

    private void ProcessFrame(object sender, EventArgs arg)
    {


        PointF[][] Actual = new PointF[0][];

        if (Frame == null) 
        {

            Frame = _capture.RetrieveBgrFrame();

            Previous_Frame = Frame.Copy();

        }

        else
        {

            Image<Gray, byte> grayf = Frame.Convert<Gray, Byte>();

            Actual = grayf.GoodFeaturesToTrack(300, 0.01d, 0.01d, 5);


            Image<Gray, byte> frame1 = Frame.Convert<Gray, Byte>();
            Image<Gray, byte> prev = Previous_Frame.Convert<Gray, Byte>();
            Image<Gray, float> velx = new Image<Gray, float>(Frame.Size);
            Image<Gray, float> vely = new Image<Gray, float>(Previous_Frame.Size);



            Frame = _capture.RetrieveBgrFrame().Resize(300,300,Emgu.CV.CvEnum.INTER.CV_INTER_AREA);

            Byte []status;
            Single[] trer;
            PointF[][] feature = Actual;
            PointF[] nextFeature = new PointF[300];



            Image<Gray, Byte> buf1 = new Image<Gray, Byte>(Frame.Size);
            Image<Gray, Byte> buf2 = new Image<Gray, Byte>(Frame.Size);
            opticalFlowFrame = new Image<Bgr, Byte>(prev.Size);

            Image<Bgr, Byte>  FlowFrame = new Image<Bgr, Byte>(prev.Size);


            OpticalFlow.PyrLK(prev, frame1, Actual[0], new System.Drawing.Size(10, 10), 0, new MCvTermCriteria(20, 0.03d),
                     out nextFeature, out status, out trer);




            for (int x = 0; x < Actual[0].Length ; x++)
            {
                opticalFlowFrame.Draw(new CircleF(new PointF(nextFeature[x].X, nextFeature[x].Y), 1f), new Bgr(Color.Blue), 2);

            }

            new1 = old;
            old = nextFeature;

            Actual[0] = nextFeature;



            Previous_Frame = Frame.Copy();
            captureImageBox.Image = Frame;
            grayscaleImageBox.Image = opticalFlowFrame;


            //cannyImageBox.Image = velx;

            //smoothedGrayscaleImageBox.Image = vely;
        }
    }

【问题讨论】:

    标签: c# opencv image-processing emgucv opticalflow


    【解决方案1】:

    首先...我只能给你一个大概的概念,而不是代码sn-p...

    您可以这样做: (解决此问题的众多可能方法之一)

    1. 获取第零帧并通过goodFeaturesToTrack。收集数组中的点...比如说,initialPoints

    2. 抓取第(零+一)帧。对于从步骤 1 中获取的点,通过 calcOpticalFlowPyrLK 运行它。将下一个点存储在另一个数组中......比如说,nextPoints。还要跟踪 statuserror 向量。

    3. 现在,有了 initialPointsnextPoints,我们离开了 openCV 的舒适,按照自己的方式做事。对于 initialPointsnextPoints 中的每个特征(status 设置为 1 并且 error 低于可接受的阈值),我们计算点之间的梯度。

    4. 仅接受那些倾斜角度约为 0 度或 180 度的水平运动点。现在...矢量方向不会完全位于 0 或 180...所以要考虑一点 +/- 阈值。

    对所有帧重复步骤 1 到 4。

    浏览您发布的代码...您似乎已经完成了第 1 步和第 2 步。

    然而,一旦你获得了矢量nextFeature,你似乎在围绕它画圈。有趣……但不是我们需要的。

    检查是否可以实现梯度计算和过滤。

    【讨论】:

    • 嘿,谢谢你的回答。我设法完成了你提到的步骤。我忘了提到我正在尝试开发一个应用程序,在该应用程序中我可以在道路上行驶时跟踪物体的运动。因此,当我从汽车上拍摄行车记录仪视频时,帧的所有像素都会在向前行驶时向我们移动。如果一个物体在车辆前面水平移动,一些像素会响应这些像素。
    • 好的。在这种情况下,过滤后的特征向量中可能存在许多异常值。
    • 在我的代码中有两个名为“old”和“nextFeature”的数组。在前一帧和醋栗帧中都有点。但是当我调试我的程序时,例如 old[0] 值比 nextFeature[0] 值非常高。我认为这是因为一些轨迹点在它们从框架中消失时会消失。所以我从这两点的切线中得到了我的角度。所以角度不正确吧?
    猜你喜欢
    • 2012-03-30
    • 1970-01-01
    • 2012-04-26
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    相关资源
    最近更新 更多