人脸检测源码facedetection
来源:互联网 发布:女士电脑双肩包 知乎 编辑:程序博客网 时间:2024/06/10 20:11
人脸检测源码:
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(); //启动默认在屏幕中间 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(); } //关闭窗体 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]; // 枚举所有摄像头支持的像素,设置拍照为1920*1080 foreach (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 handler videoSourcePlayer1.Start(); } //保存图片 private void button2_Click(object sender, EventArgs e) { if (videoSource == null) return; Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame(); //图片名称,年月日时分秒毫秒.jpg string fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg"; //获取项目的根目录 String path = AppDomain.CurrentDomain.BaseDirectory; //将图片保存在服务器里面 bitmap.Save(path + "\\picture\\" + fileName, ImageFormat.Jpeg); bitmap.Dispose(); //进行面部特征识别 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(); } }}
阅读全文
0 0
- 人脸检测源码facedetection
- 使用FaceDetection进行人脸识别
- facedetection
- OpenCV人脸检测(完整源码+思路)
- haar 人脸检测跟踪源码整理
- opencv 人脸检测源码解析
- dlib人脸检测源码解析
- 2017年人脸检测、人脸对齐、人脸识别源码
- android4.0 FaceDetection笔记
- android4.0 FaceDetection笔记 .
- seetaface FaceDetection模块
- faceDetection对比实验
- 人脸识别(不是检测,而是识别,源码下载)
- 人脸检测源码解析——1、训练参数
- 人脸检测源码解析——2、概要流程
- 人脸检测源码解析——3、准备数据
- 人脸检测源码解析——5、加载数据
- 一个OpenCV实现的人脸检测的源码
- centos7 git 2.8安装-配置
- properties文件编码问题
- 【编程随想】聊聊分布式散列表(DHT)的原理——以 Kademlia(Kad) 和 Chord 为例
- 深入理解Java之线程池
- 欢迎使用CSDN-Markdown语法帮助
- 人脸检测源码facedetection
- Html5更新版笔记
- Java线程池ThreadPoolExecutor使用和分析(一)
- PS、设计网页、啤酒配方 人工智能还有不会做的么?| 漫读
- 完美机器人性伴侣触动了谁的神经?女权主义还是社会伦理 | 探讨
- 人工智能进化史:从麦卡锡到“索菲亚” | 精选
- 人脸注册源码faceregiste
- 虚拟现实、云技术、人工智能 未来的教育会有啥不一样 | 观察
- 1072. 开学寄语(20)