當(dāng)前位置:
首頁 >
人脸检测源码facedetection
發(fā)布時間:2023/12/3
37
豆豆
生活随笔
收集整理的這篇文章主要介紹了
人脸检测源码facedetection
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
人臉檢測源碼:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using AForge; using AForge.Controls; using AForge.Imaging; using AForge.Video; using AForge.Video.DirectShow; using face;namespace Camtest {public partial class facedetection : Form{/// <summary>/// 人臉檢測/// </summary>public facedetection(){InitializeComponent();//啟動默認(rèn)在屏幕中間this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;}FilterInfoCollection videoDevices;VideoCaptureDevice videoSource;public int selectedDeviceIndex = 0;public int selectedPICIndex = 0;/// <summary>/// 加載窗體/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void Form1_Load(object sender, EventArgs e){// 刷新可用相機的列表videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);comboBoxCameras.Items.Clear();for (int i = 0; i < videoDevices.Count; i++){comboBoxCameras.Items.Add(videoDevices[i].Name.ToString());}if (comboBoxCameras.Items.Count > 0)comboBoxCameras.SelectedIndex = 0;picsize.SelectedIndex = 0;this.label4.Text = this.label5.Text = this.label7.Text = this.label9.Text = this.label11.Text = this.label13.Text = "正在識別";this.label4.ForeColor = Color.Red;this.label5.ForeColor = Color.Red;this.label7.ForeColor = Color.Red;this.label9.ForeColor = Color.Red;this.label11.ForeColor = Color.Red;this.label13.ForeColor = Color.Red;openCan();}//關(guān)閉窗體private void Form1_FormClosing(object sender, FormClosingEventArgs e){DialogResult r = MessageBox.Show("確定要退出程序?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if (r != DialogResult.OK){e.Cancel = true;}videoSourcePlayer1.Stop();//停止攝像頭videoSourcePlayer1.Dispose();}//實時顯示照片private void videoSourcePlayer1_Click(object sender, EventArgs e){}/// <summary>/// 打開攝像頭/// </summary>public void openCan(){selectedPICIndex = picsize.SelectedIndex;selectedDeviceIndex = comboBoxCameras.SelectedIndex;//連接攝像頭。videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];// 枚舉所有攝像頭支持的像素,設(shè)置拍照為1920*1080foreach (VideoCapabilities capab in videoSource.VideoCapabilities){if (selectedPICIndex == 0){if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080){videoSource.VideoResolution = capab;break;}if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720){videoSource.VideoResolution = capab;break;}}else{if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720){videoSource.VideoResolution = capab;break;}}}videoSourcePlayer1.VideoSource = videoSource;// set NewFrame event handlervideoSourcePlayer1.Start();}//保存圖片private void button2_Click(object sender, EventArgs e){if (videoSource == null)return;Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();//圖片名稱,年月日時分秒毫秒.jpgstring fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";//獲取項目的根目錄String path = AppDomain.CurrentDomain.BaseDirectory;//將圖片保存在服務(wù)器里面bitmap.Save(path + "\\picture\\" + fileName, ImageFormat.Jpeg);bitmap.Dispose();//進(jìn)行面部特征識別facemodel facem = face_test.FaceDetect(path + "\\picture\\" + fileName);this.label4.Text = facem.age; //年齡this.label5.Text = facem.beauty; //漂亮度string expression = facem.expression;//表情if (expression.Equals("0")){this.label7.Text = "不笑";}else if (expression.Equals("1")){this.label7.Text = "微笑";}else if (expression.Equals("2")){this.label7.Text = "大笑";}string gender = facem.gender;//性別if (gender.Equals("male")){this.label9.Text = "男";}else{this.label9.Text = "女";}string glasses = facem.glasses;//是否戴眼鏡if (glasses.Equals("0")){this.label11.Text = "無眼鏡";}else if (glasses.Equals("1")){this.label11.Text = "普通眼鏡";}else{this.label11.Text = "墨鏡";}string race = facem.race;//人種if (race.Equals("yellow")){this.label13.Text = "黃人";}else if (race.Equals("white")){this.label13.Text = "白人";}else if (race.Equals("black")){this.label13.Text = "黑人";}else if (race.Equals("arabs")){this.label13.Text = "棕人";}}//取消的按鈕private void close_Click(object sender, EventArgs e){//停止攝像頭videoSourcePlayer1.Stop();this.Close();welcome we = new welcome();we.Show();}} }總結(jié)
以上是生活随笔為你收集整理的人脸检测源码facedetection的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 雷州半岛在哪 雷州半岛位置组成讲解
- 下一篇: 人脸注册源码faceregiste