NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

* form1.cs

using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;

namespace CameraNVRDVRfaceRecognition
{
public partial class Form1 : Form
{
public VideoCapture _capture;
public CascadeClassifier _faceCascade;
public bool _isProcessing;
public int _frameCounter;

public Form1()
{
InitializeComponent();
}

public void Form1_Load(object sender, EventArgs e)
{
// Load the Haar Cascade classifier
string faceCascadePath = "haarcascade_frontalface_default.xml";
_faceCascade = new CascadeClassifier(faceCascadePath);
}

public void btnStart_Click(object sender, EventArgs e)
{
if (!_isProcessing)
{
// Replace with your local .mp4 file path
string videoFilePath = "path_to_your_video_file.mp4";
_capture = new VideoCapture(videoFilePath);

if (!_capture.IsOpened)
{
MessageBox.Show("Failed to open the video file");
return;
}

_isProcessing = true;
btnStart.Text = "Stop";
_frameCounter = 0;

// Start processing frames
Application.Idle += ProcessFrame;
}
else
{
_isProcessing = false;
btnStart.Text = "Start";
_capture.Stop();
_capture.Dispose();
Application.Idle -= ProcessFrame;
}
}

public void ProcessFrame(object sender, EventArgs e)
{
Mat frame = _capture.QueryFrame();

if (frame == null)
{
// Stop processing when no frames are available
_isProcessing = false;
btnStart.Text = "Start";
_capture.Stop();
_capture.Dispose();
Application.Idle -= ProcessFrame;
return;
}

_frameCounter++;

// Convert the captured frame to grayscale for face detection
using (UMat ugray = new UMat())
{
CvInvoke.CvtColor(frame, ugray, ColorConversion.Bgr2Gray);

// Detect faces in the grayscale frame
Rectangle[] faces = _faceCascade.DetectMultiScale(ugray, 1.1, 5, Size.Empty);

// Draw rectangles around the detected faces
foreach (Rectangle faceRect in faces)
{
CvInvoke.Rectangle(frame, faceRect, new MCvScalar(0, 0, 255), 2);

// Crop the detected face region from the frame
using (Mat faceROI = new Mat(frame, faceRect))
{
// Example: Save the cropped face image
string faceFilename = $"frame_{_frameCounter}_face_{faces.Length}.jpg";
faceROI.Save(faceFilename);
Console.WriteLine($"Cropped face saved as {faceFilename}");
}
}

// Display the processed frame with rectangles around faces in the PictureBox
pictureBox.Image = frame.ToBitmap();
}
}

private void InitializeComponent()
{

}
}
}



* form1.designer.cs


using System.ComponentModel;

namespace FaceRecognitionDVRNVRCameraSystem
{
partial class Form1
{
private Button btnStart; // Declare your button and picture box here
private PictureBox pictureBox;

public Container components { get; private set; }
public object Controls { get; private set; }

private AutoScaleMode AutoScaleMode;

public Size ClientSize { get; private set; }

private void InitializeComponent()
{
this.btnStart = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(12, 12);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(75, 23);
this.btnStart.TabIndex = 0;
this.btnStart.Text = "Start";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click); // Make sure to wire up the Click event handler
//
// pictureBox
//
this.pictureBox.Location = new System.Drawing.Point(12, 41);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(640, 480);
this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// Form1
//
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(664, 533);
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
}

private void btnStart_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}

private void SuspendLayout()
{
throw new NotImplementedException();
}
}
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.