人脸注册:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
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;
using System.Data.SqlClient;
using System.Drawing.Imaging;
using System.IO;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;namespace Camtest
{public partial class faceregiste : Form{//Api_Keypublic static string Api_Key = "OVYw5Ok0y9U8n6CfVPYt0wfZ";//Secret_Keypublic static string Secret_Key = "aCN3lupCarq3rC9G8Rylqz1d36Towp8G";public faceregiste(){InitializeComponent();//启动默认在屏幕中间this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;}FilterInfoCollection videoDevices;VideoCaptureDevice videoSource;public int selectedDeviceIndex = 0;public int selectedPICIndex = 0;//加载项目private void faceregiste_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;//打开摄像头openCamera();}//打开摄像头public void openCamera() {selectedPICIndex = picsize.SelectedIndex;selectedDeviceIndex = comboBoxCameras.SelectedIndex;//连接摄像头。videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];// 枚举所有摄像头支持的像素,设置拍照为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 register_Click(object sender, EventArgs e){Users user = new Users();user.name = this.name.Text;user.id = DateTime.Now.Ticks / 10000;user.password = this.password.Text;user.phone = this.phone.Text;user.age =(int)this.age.Value;user.address = this.address.Text;user.picture = SavePicture() ;//注册人脸通过的话进去if (FaceRegister(user)){int rel = AddUsers(user);//添加信息if (rel > 0){MessageBox.Show("注册成功", "提示信息");}else{MessageBox.Show("添加失败", "提示信息");}}}/// <summary>/// 保存图片/// </summary>public string SavePicture() {if (videoSource == null){return null;}Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();//图片名称,年月日时分秒毫秒.jpgstring fileName = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".jpg";//获取项目的根目录string path = AppDomain.CurrentDomain.BaseDirectory;string picture = path + "\\picture\\" + fileName;//将图片保存在服务器里面bitmap.Save(picture, ImageFormat.Jpeg);bitmap.Dispose();return picture;}//取消的按钮private void close_Click(object sender, EventArgs e){//停止摄像头videoSourcePlayer1.Stop();this.Close();welcome we = new welcome();we.Show();}/// <summary>/// 用户注册/// </summary>/// <param name="users"></param>/// <returns></returns>public int AddUsers(Users users){int rel = 0;string sql = "insert INTO Users VALUES(@id,@name,@age,@phone,@password,@address,@picture)";SqlParameter[] param = {new SqlParameter("@id",users.id),new SqlParameter("@name",users.name),new SqlParameter("@age",users.age),new SqlParameter("@phone",users.phone),new SqlParameter("@password",users.password),new SqlParameter("@address",users.address),new SqlParameter("@picture",users.picture)};rel = SqlHelper.ExecuteNonQuery(sql, CommandType.Text, param);return rel;}//关闭窗体private void faceregiste_FormClosing(object sender, FormClosingEventArgs e){DialogResult r = MessageBox.Show("确定要退出程序?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if (r != DialogResult.OK){e.Cancel = true;}videoSourcePlayer1.Stop();//停止摄像头videoSourcePlayer1.Dispose();}/// <summary>/// 人脸注册/// </summary>/// <param name="picture"></param>public static bool FaceRegister(Users user){var client = new Baidu.Aip.Face.Face(Api_Key, Secret_Key);//当前毫秒数可能是负数,取绝对值var image1 = File.ReadAllBytes(user.picture);var result = client.User.Register(image1, user.id.ToString(), user.name, new[] { "gr_test" });//得到根节点JObject jo_result = (JObject)JsonConvert.DeserializeObject(result.ToString());if ((string)jo_result["error_msg"] != null){MessageBox.Show("对不起,请把脸放上!","提示",MessageBoxButtons.OK,MessageBoxIcon.Stop);return false;}return true;}}
}

人脸注册源码faceregiste相关推荐

  1. Android园区部队人脸识别源码门禁项目讲解

    Android园区部队人脸识别源码门禁项目讲解 这边搞人脸识别相关项目有一段时间,今天抽时间讲述一个经典的人脸识别项目:部队人脸识别门禁系统. 大家都知道部队对人员管理安全要求是相当高的,很多保密的技 ...

  2. android与html注册登录,Android登录注册源码

    Android登录注册源码 资源下载此资源下载价格为2D币,请先登录 资源文件列表 andoird96pk/.classpath , 348 andoird96pk/.project , 847 an ...

  3. 人脸检测源码facedetection

    人脸检测源码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Da ...

  4. Eureka服务注册源码分析

    本文来说下Eureka服务注册源码 文章目录 Eureka-Client注册服务 啥时候会注册 定时器注册 自动注册 DiscoveryClient.register() Eureka-Server接 ...

  5. 人脸检测颜值软件_AI人脸颜值测颜版下载-百度ai测试颜值人脸识别源码下载v1.0 免费版-西西软件下载...

    百度ai测试颜值人脸识别源码这是由官方百度AI精心打造出来的,这款软件将人脸识别氛围V2和V3两个接口,而且用户使用可以参考相应的文档权限来选择接口类型,让广大用户学习到百度AI人脸识别测颜值相关知识 ...

  6. python 人脸识别源码

    Python是一种流行的编程语言,可以用于许多任务,包括人脸识别.以下是使用Python进行人脸识别的基本步骤: 安装必要的库:为了进行人脸识别,您需要安装OpenCV(用于图像处理),dlib(用于 ...

  7. java如何通过grpc连接etcd_grpc通过 etcd 实现服务发现与注册-源码分析

    介绍 下面介绍 jupiter-0.2.7 版本中 grpc 通过 etcd 实现服务发现与注册. 服务发现与注册的实现解析 服务注册 服务注册的流程图: etcd的服务注册代码模块在 jupiter ...

  8. python人脸识别源码_Python 抖音机器人,让你找到漂亮小姐姐

    本项目作者沉迷于抖音无法自拔,常常花好几个小时在抖音漂亮小姐姐身上. 本着高效.直接地找到漂亮小姐姐的核心思想,我用 Python + ADB 做了一个 Python 抖音机器人 Douyin-Bot ...

  9. 并注册烧写钩子 获取启动介质类型_Spark Application的注册 源码剖析

    Spark提交任务最终是以Application方式注册进去的,每个在Spark上运行的job以Application做为单元存在.同时注册到yarn资源管理器中也是同样的Application.那么 ...

最新文章

  1. 应用随机过程张波商豪_Markov链的应用一:MCMC算法
  2. 使用TimeQuest时序分析器
  3. 验证码识别Burp reCAPTCHA插件使用
  4. Linux 下 NFS服务的搭建
  5. 解读Linux命令格式
  6. Ajax基础知识梳理 1
  7. 魔兽美服服务器维护,美服《魔兽世界》低人口密度服务器合并计划最新动态
  8. DAY102 - Rest Framework(七)- 手动编写配置文件、分页器和版本控制
  9. opengl 加载贴图Unknown DIB file format问题
  10. 【优化调度】基于matlab遗传算法求解孤岛型微电网(成本最低) 调度优化问题【含Matlab源码 1163期】
  11. 理财通 for N9
  12. Rufus --工具制作镜像
  13. 数理统计之方差分析及python实现
  14. 内部收益率计算公式用计算机,用excel怎么计算内部收益率?
  15. layui 模板引擎-laytpl(局部渲染)
  16. 如何将word转换成pdf?超实用的使用教程免费分享
  17. unity制作火焰效果
  18. 生鲜在B2C电商模式下存在问题,O2O模式解决生鲜电商物流配送难题
  19. 函数最值题目及答案_二次函数的最值问题举例(附练习答案)
  20. 【踩坑记录】—— app运行闪退(Mac版)

热门文章

  1. Maximum Sum UVA - 108(连续子序列最大和—变形之子矩阵最大和)
  2. html鼠标悬停盒子凸起,css3 transform动画鼠标悬停div容器凸起放大显示
  3. wordList01
  4. Codeforces Round #624 (Div. 3) E. Construct the Binary Tree 思维 + 构造
  5. 2021-2022ACM赛季小总结
  6. P1446 [HNOI2008]Cards
  7. CF1063A Oh Those Palindromes
  8. xay loves trees
  9. 【刷题记录】排列dp
  10. Codeforces Round #709 (Div. 2, based on Technocup 2021 Final Round) 题解