Home > Mobile >  OpenCV Bitmap constructor is very slow on first process
OpenCV Bitmap constructor is very slow on first process

Time:12-08

I am trying to detect a document from camera and crop it using OpenCV. While I am doing this on my local there is no problem, but when it work on test the row below takes more then 2 minutes. I tried to build my project in release mode but nothing changed. I am using EMGU.CV 4.1.1.3497. The thing what confuses me: it is in eventhandler and it works more then 1 time in a second. It is slow for only first load. Then it works fast.

private void Device_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
    using (Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone())
    {
        using (Image<Bgr, byte> imageCV = new Image<Bgr, byte>(bitmap)) --this row takes 2 minutes on first load
        {
          //finding contour etc.
        }
    }
}

ProcMon Logs: enter image description here

Tried to build on release mod. Tried to add test all of my dll versions on local. Tried it on different devices and cameras.

CodePudding user response:

From the trace it looks like it is reading from \\path\..., I would assume this is a network drive. I would highly recommend that all the program files are run from a local drive instead. I.e. just copy the program to a local folder.

Network drives can have far higher latency than local drives. And if there is many small reads this can add up.

This sounds like it matches your experience, when you run it locally everything works fine. Once it has actually loaded all of the files it also runs fine.

  • Related