为什么CvInvoke.CalcOpticalFlowFarneback()方法使用了大量内存?

时间:2017-11-23 13:15:47

标签: c# image-processing computer-vision emgucv

我使用CvInvoke.CalcOpticalFlowFarneback()方法来计算光流。但结果是,它使用了大量内存,程序运行缓慢。怎么解决? 感谢您的回复!

public class OpticalFlow : BaseFilter
{
    private Mat prevFrame;
    private long frameCount;
    private bool oldFrameEmpty = true;
    public OpticalFlow()
    {
        TAG = "[Optical Flow Test]";
    }

    protected override Mat ProcessFrame(ref Mat frame)
    {
        frameCount++;
        Mat rez = new Mat();
        frame.CopyTo(rez);
        Mat nextFrame = new Mat();


        CvInvoke.CvtColor(frame, nextFrame, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);
        if (!oldFrameEmpty)
        {
            Image<Gray, byte> prev0 = prevFrame.ToImage<Gray, byte>();
            Image<Gray, byte> next0 = nextFrame.ToImage<Gray, byte>();
            Image<Gray, Single> flowX = new Image<Gray, Single>(rez.Width, rez.Height);
            Image<Gray, Single> flowY = new Image<Gray, Single>(rez.Width, rez.Height);

            CvInvoke.CalcOpticalFlowFarneback(prev0, next0, flowX, flowY, 0.5, 3, 20, 20, 7, 1.5, Emgu.CV.CvEnum.OpticalflowFarnebackFlag.FarnebackGaussian);

            prevFrame = nextFrame.Clone();
            oldFrameEmpty = false;
        }
        if (oldFrameEmpty)
        {
            prevFrame = nextFrame.Clone();
            oldFrameEmpty = false;
        }
        return rez;
    }

0 个答案:

没有答案