question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Detection from WebCam Capture using EmguCV

See original GitHub issue

Hello! Nice wrapper! I tried it over some existing images and worked well but I have a problem using it with capture from my laptop camera. EmguCV is processing the bitmaps well and detects my face without issues but ProcessImage always returns null. The wrapper is initializing properly. Marshal.GetLastWin32Error() returns error code 203. I’m converting the Capture frames from their bitmaps to byte arrays using LockBits. Will put some code samples below so you can test. I’m using the latest Emgu from NuGet version 3.1.0.1.

using (var imageFrame = this.capture.QueryFrame().ToImage<Bgr, Byte>())
            {
                if (imageFrame != null)
                {
                    CoreRectangleCandidate[] yoloObjects = this.yoloWrapper.ProcessImage(BitmapToByteArray(imageFrame.Bitmap));

                    int errorMessage = Marshal.GetLastWin32Error();

                    if (yoloObjects != null)
                    {
                        foreach (CoreRectangleCandidate rect in yoloObjects.Where(wr => wr.objectType == "person"))
                        {
                            imageFrame.Draw(new Rectangle(rect.rectangle.topLeftCorner.x, rect.rectangle.topLeftCorner.y, rect.rectangle.width, rect.rectangle.height),
                                new Bgr(Color.Wheat), 3);
                        }
                    }
}
}

public static byte[] BitmapToByteArray(Bitmap bitmap)
        {

            BitmapData bmpdata = null;

            try
            {
                bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
                int numbytes = bmpdata.Stride * bitmap.Height;
                byte[] bytedata = new byte[numbytes];
                IntPtr ptr = bmpdata.Scan0;

                Marshal.Copy(ptr, bytedata, 0, numbytes);

                return bytedata;
            }
            finally
            {
                if (bmpdata != null)
                    bitmap.UnlockBits(bmpdata);
            }

        }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
tt20496commented, Jun 11, 2019

@tt20496, maill: raslkrut5@mail.ru Thanks for the help.

i’m newbie so I follow this video to finish project: Capture EmguCV: https://www.youtube.com/watch?v=MXjM4iN261s Yolo Detection: https://www.youtube.com/watch?v=G4tNSnIE_lY&list=PLlD7n_T-mUjUuO7cW2TmmdXjxwaEqveE7 and my video: https://www.youtube.com/watch?v=l18z4x6RMfY&feature=youtu.be you can choose your webcam if insted of number Videocapture(); add file weights, cfg, names in forder “net46” Sorry for my bad English.

1reaction
tinohagercommented, Jun 11, 2019

@tt20496 It is possible to share it here? For other users? 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Camera Capture in 7 lines of code
This example has been tested on Emgu CV 4.6.0.0​​ Only a few lines of code are required to perform a camera capture loop....
Read more >
Using Emgu.CV To Detect Faces From Webcam (C#)
The detector is supposed to work on the webcam frames every time timer1 ticks over, and the number of rectangles in the Faces[]...
Read more >
Emgu cv camera / webcam
I have a problem with my project , I think it's about web camera/ camera problem , I have developed my application ,and...
Read more >
Webcam face detection in C# using Emgu CV - Michael Friis
Some time ago I wrote a post on how to do face detection in C# using OpenCV. I've since begun using the Emgu...
Read more >
Emgu CV Code samples
Emgu CV Code samples. 1. Camera Capture and Gray Scale Conversion. //namspace for emgu cv using Emgu.CV; using Emgu.CV.Structure; using Emgu.Util;.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found