Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in WebcamFacePose sample #87

Closed
jmtaijiquan opened this issue Mar 13, 2019 · 4 comments
Closed

Exception in WebcamFacePose sample #87

jmtaijiquan opened this issue Mar 13, 2019 · 4 comments
Assignees

Comments

@jmtaijiquan
Copy link

Summary of your issue

The sample code of WebcamFacePose throws exception randomly.

Environment

Windows .NET 4.6.1

What did you do when you faced the problem?

Run the application for multiple times and the application will throw exceptions randomly: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

What did you intend to be?

I modified the code with data type "Byte" for method call Dlib.LoadImageData(). The application seems working fine now.

@takuya-takeuchi
Copy link
Owner

perhaps, temp Mat is 8bit channel sent from webcam.
sample code does not take care of channel value.

But I never seen 8 bit channel webcam.
Is it IR camera?

@jmtaijiquan
Copy link
Author

I am using Logitech C920.

@jmtaijiquan
Copy link
Author

Oops... I still see the same exception randomly on the same line of code. This method is called by another thread.

    private List<Bitmap> DetectFacesWithDlib(Bitmap image)
    {
        List<Bitmap> detectedFaces = new List<Bitmap>();

        // Create Mat from image
        using (Mat srcImage = OpenCvSharp.Extensions.BitmapConverter.ToMat(image))
        using (Mat grayImage = new Mat())
        {
            // Convert to gray image
            Cv2.CvtColor(srcImage, grayImage, ColorConversionCodes.BGRA2GRAY);
            Cv2.EqualizeHist(grayImage, grayImage);

            // Turn OpenCV's Mat into something dlib can deal with.  Note that this just
            // wraps the Mat object, it doesn't copy anything. 
            var array = new byte[grayImage.Width * grayImage.Height * grayImage.ElemSize()];
            Marshal.Copy(grayImage.Data, array, 0, array.Length);
            using (var cimg = Dlib.LoadImageData<Byte>(array, (uint)grayImage.Height, (uint)grayImage.Width, (uint)(grayImage.Width * grayImage.ElemSize())))
            {
                // Detect faces 
                var faces = _faceDetector.Operator(cimg);

@takuya-takeuchi
Copy link
Owner

@jmtaijiquan I run WebcamFacePose once again for 10 min.
But it works fine. Sure, I didn't change any code.
Does issue you reported first use DetectFacesWithDlib method?

Could you show me all source code occur problem if you can?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants