Detection from WebCam Capture using EmguCV
See original GitHub issueHello! 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:
- Created 5 years ago
- Comments:20 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@tt20496 It is possible to share it here? For other users? 😄