简体   繁体   中英

Is Emgu CV QueryFrame method asynchronous?

I am currently using the EmguCV QueryFrame method to capture frames. The code is something like this, inside my processFrame method:

using(Image<Bgr, Byte> imgOriginal = _capture.QueryFrame()){
    if(imgOriginal == null) return;
        using(Image<Gray, Byte> grayImg = imgOriginal.Convert<Gray, Byte>()){
            //some stuff with grayImg
        }
}

The problem I'm facing is that I keep getting an OutOfMemory exception. Upon further inspection with MemProfiler , I find that a Byte[,,] object of namespace System uses up exponentially more memory than anything else. The only Byte[,,] I can think of is the Bgr frame imgOriginal that is captured.

This leads me to believe that the Capture object keeps on querying new frames even if the code within the using block has not finished executing. Is this true? Or is there some other reason? Is there any way to solve this?

Any help would be appreciated. Thank you.

What version of EMGU are you using?

Try this:

Mat frame = new Mat();
_capture.Retrieve(frame, 0);

For converting to grayscale:

Mat grayFrame = new Mat();
CvInvoke.CvtColor(frame, grayFrame, ColorConversion.Bgr2Gray);

Also, you can try to check how it works in the examples section of EMGU.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM