ocnuybear
New member
- Joined
- Mar 30, 2023
- Messages
- 4
- Programming Experience
- 5-10
Can someone please help correct this code:
Need to track Full Body People, not the usual faces and it is very hard to find c# code for that specificly.
Visual Studio 2022 Community Edition complains about 2 problems:
1. 'VideoCaptureDevice' does not contain a definition for 'GetCurrentVideoFrame'
2. Argument 1: cannot convert from 'System.Drawing.Bitmap' to 'byte[*,*,*]'
Just need to get the FrameCode correct so that it displays the captured video feed using yhe webcam please assist?
Need to track Full Body People, not the usual faces and it is very hard to find c# code for that specificly.
C#:
using System;
using System.Diagnostics.Tracing;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
namespace Webcam
{
public partial class Form1 : Form
{
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoDevice;
private CascadeClassifier haarCascade;
public Form1()
{
InitializeComponent();
InitializeVideoDevices();
// Initialize the Haar Cascade Classifier with the haarcascade_fullbody.xml file
haarCascade = new CascadeClassifier("haarcascade_fullbody.xml");
}
private void InitializeVideoDevices()
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count == 0)
{
MessageBox.Show("No video devices found.");
return;
}
videoDevice = new VideoCaptureDevice(videoDevices[0].MonikerString);
videoDevice.NewFrame += VideoDevice_NewFrame;
}
private void VideoDevice_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap frame = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = frame;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnStartCamera_Click(object sender, EventArgs e)
{
using (Bitmap frame = (Bitmap)EventArgs.Frame.Clone())
{
// Convert the frame to grayscale
using (Image<Gray, byte> grayFrame = new Image<Gray, byte>(frame))
{
// Detect persons in the frame
Rectangle[] persons = haarCascade.DetectMultiScale(grayFrame, 1.1, 3, new Size(50, 50), Size.Empty);
// Draw rectangles around detected persons
using (Graphics g = Graphics.FromImage(frame))
{
foreach (Rectangle person in persons)
{
g.DrawRectangle(Pens.Red, person);
}
}
}
// Update PictureBox with the processed frame
pictureBox1.Image = frame;
}
}
private void btnStopCamera_Click(object sender, EventArgs e)
{
if (videoDevice != null && videoDevice.IsRunning)
{
videoDevice.SignalToStop();
videoDevice.WaitForStop();
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
btnStopCamera_Click(null, null);
}
}
}
Visual Studio 2022 Community Edition complains about 2 problems:
1. 'VideoCaptureDevice' does not contain a definition for 'GetCurrentVideoFrame'
2. Argument 1: cannot convert from 'System.Drawing.Bitmap' to 'byte[*,*,*]'
Just need to get the FrameCode correct so that it displays the captured video feed using yhe webcam please assist?