EmguCV Access Violation Exception while using BlobFromImage

Viewed 410

I've been trying for a long time to implement pose detection in EmguCV without success. I have a successful program in C++ using OpenCV. When I tried to translate it in C#, I couldn't go over the "BlobFromImage" because I get an Exception ("Access Violation")... I tried multiple things, I'm compiling in x64, and the image is correct (I can show it without problem as an image). Before that I was using Mat instead of UMat, but it's just the same. Emgu version: 4.2.0.3662 (also tried with other versions, still getting the same error. If it can help, see the code below:

    private void Prova()
    {
        VideoCapture cap = new VideoCapture(videoFile);

        if (!cap.IsOpened)
        {
            Debug.WriteLine("Unable to connect to camera");
            return;
        }

        UMat frame;
        int frameWidth = (int)cap.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth);
        int frameHeight = (int)cap.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight);

        VideoWriter video = new VideoWriter("Output-Skeleton-Davide-MPI-GPU-168.avi", VideoWriter.Fourcc('M', 'J', 'P', 'G'), new System.Drawing.Size(frameWidth, frameHeight), false);

        Net net = Emgu.CV.Dnn.DnnInvoke.ReadNetFromCaffe("./pose_deploy_linevec.prototxt", "./pose_iter_160000.caffemodel");
        net.SetPreferableBackend(Emgu.CV.Dnn.Backend.Default);
        net.SetPreferableTarget(Emgu.CV.Dnn.Target.OpenCL);

        frame = cap.QueryFrame().GetUMat(Emgu.CV.CvEnum.AccessType.ReadWrite);

        if (frame.Rows != 0 && frame.Cols != 0)
        {
            // Exception thrown here...
            Emgu.CV.UMat inpBlob = Emgu.CV.Dnn.DnnInvoke.BlobFromImage(frame).GetUMat(Emgu.CV.CvEnum.AccessType.ReadWrite);

            net.SetInput(inpBlob);
        }
    }

I know that I could call the c++ code from C#, but I would rather do it from C# alone. Thanks a lot

0 Answers
Related