-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
79 lines (60 loc) · 2.35 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;
using System.Diagnostics;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;
namespace facialrecon
{
public partial class FrmPrincipal:Form {
Image<Bgr, Byte> Frame;
Capture capture;
HaarCascade face;
MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5d, 0.5d);
Image<Gray, byte> result;
Image<Gray, byte> grayFrame = null;
int t;
public FrmPrincipal() {
InitializeComponent();
face = new HaarCascade("haarcascade_frontalface_default.xml");
}
private void button1_Click(object sender, EventArgs e) {
capture= new Capture();
capture.QueryFrame();
Application.Idle+= new EventHandler(FrameCapture);
//disable the button after clicking
button1.Enabled = false;
}
void FrameCapture(object sender, EventArgs e) {
label2.Text = "0";
Frame = capture.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
//convert image to gray scale
grayFrame = Frame.Convert<Gray, Byte>();
//detect the faces
MCvAvgComp[][] faces = grayFrame.DetectHaarCascade(face, 1.2, 10,Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));
//detect each face in the camera and draw a rectangle around it
foreach (MCvAvgComp f in faces[0]) {
//add up the number of faces
t = t + 1;
result = Frame.Copy(f.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
//Draw a rectangle on face detected
Frame.Draw(f.rect, new Bgr(Color.Blue), 2);
label2.Text= faces[0].Length.ToString();
}
t = 0;
imageBoxFrameCapture.Image = Frame;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}