人脸认证源码faceIdentify

人脸认证:

using AForge.Video.DirectShow;
using face;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace Camtest
{public partial class faceIdentify : Form{public faceIdentify(){InitializeComponent();//启动默认在屏幕中间this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;}//Api_Keypublic static string Api_Key = "OVYw5Ok0y9U8n6CfVPYt0wfZ";//Secret_Keypublic static string Secret_Key = "aCN3lupCarq3rC9G8Rylqz1d36Towp8G";FilterInfoCollection videoDevices;VideoCaptureDevice videoSource;public int selectedDeviceIndex = 0;public int selectedPICIndex = 0;//窗体加载private void faceIdentify_Load(object sender, EventArgs e){//显示为正在检测this.label1.Text = this.label2.Text = this.label6.Text = this.label9.Text = "正在识别";// 刷新可用相机的列表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();}/// <summary>/// 签到的按钮/// 先保存图片,然后进行比较,获取的id,查询/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void qiandao_Click(object sender, EventArgs e){Users users = FaceIdentifys(SavePicture());this.label1.Text = users.age.ToString();this.label2.Text = users.name;this.label6.Text = users.phone;this.label9.Text = users.address;if (users.picture != null){this.pictureBox1.Image = Image.FromFile(users.picture, false);}}//关闭窗口private void faceIdentify_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="filename"></param>public static Users FaceIdentifys(string filename){long id = 0;string ids = "";double scores_num = 0;Users user = new Users();var client = new Baidu.Aip.Face.Face(Api_Key, Secret_Key);var image1 = File.ReadAllBytes(filename);var result = client.User.Identify(image1, new[] { "gr_test" }, 1, 1);//先判断脸是不是在上面,在继续看有匹配的没,否则提示放上脸//得到根节点JObject jo_result = (JObject)JsonConvert.DeserializeObject(result.ToString());if ((string)jo_result["error_msg"] != null){MessageBox.Show("对不起,请把脸放上!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);}else{//检测到脸//得到result节点JArray jo_age = (JArray)JsonConvert.DeserializeObject(jo_result["result"].ToString());foreach (var val in jo_age){id = long.Parse(((JObject)val)["uid"].ToString());  //获取uidstring scores = ((JObject)val)["scores"].ToString();//获取scoresint num1 = scores.IndexOf("\n") + 2;int num2 = scores.LastIndexOf("]")-8;ids = scores.Substring(num1, num2);scores_num =double.Parse(ids);}if (scores_num > 80){user = QueryUsersById(id);if (user.id != 0){MessageBox.Show("签到成功,已检测到您的信息", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}else{MessageBox.Show("对不起,系统根据您的脸未检测到信息", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);}}else {MessageBox.Show("对不起,系统根据您的脸未检测到信息", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);}}return user;}/// <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;}/// <summary>/// 根据编号查询用户信息/// </summary>/// <param name="id"></param>/// <returns></returns>public static Users QueryUsersById(long id){Users user = new Users();string sql = "select * from users where id = @id";using (SqlDataReader reader = SqlHelper.ExcuteReader(sql, CommandType.Text, new SqlParameter("@id", id))){if (reader.Read()){user.id = long.Parse(reader[0].ToString());user.name = reader[1].ToString();user.age = Convert.ToInt32(reader[2]);user.phone = reader[3].ToString();user.password = reader[4].ToString();user.address = reader[5].ToString();user.picture = reader[6].ToString();}}return user;}//取消的按钮private void close_Click(object sender, EventArgs e){//停止摄像头videoSourcePlayer1.Stop();this.Close();welcome we = new welcome();we.Show();}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/326894.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

选择排序+推导过程

图解 代码实现 package com.atguigu.sort;import java.util.Arrays; import java.util.List;/*** 创建人 wdl* 创建时间 2021/3/21* 描述*/ public class SelectSort {public static void main(String[] args) {int []arr{101,34,119,1};System.out.println("排序前"…

Echart折线图 柱状图

echat_百度搜索 Examples - Apache ECharts Examples - Apache ECharts Examples - Apache ECharts 修改左侧的数据 点击右侧下载可以得到html页面 Examples - Apache ECharts Examples - Apache ECharts

Streaming的算法Reservoir Sampling

转载自 这是一个惊艳了我的算法题 Reservoir Sampling( Reservoir sampling ) 这是我在今年求职过程中面试的时候被问到的&#xff0c;因为之前很少接触Streaming的算法&#xff0c;在听到这个题目的时候被惊呆了&#xff0c;根本不能理解&#xff1a; 给一个Streaming…

软件定义数据中心—Windows Server SDDC技术与实践

《软件定义数据中心—Windows Server SDDC技术与实践》是国内第一本讲解微软Windows Server 软件定义数据中心的中文图书&#xff0c;书中系统、全面地介绍了微软Windows Server 软件定义数据中心各个模块&#xff08;SDS/SDN/SDC/容器&#xff09;的概念、技术和架构&#xff…

人脸登陆facelogin

人脸登陆&#xff1a; using AForge.Video.DirectShow; using face; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Dr…

插入排序+思路分析

图解 代码实现 package com.atguigu.sort;import java.util.Arrays;/*** 创建人 wdl* 创建时间 2021/3/22* 描述*/ public class InsertSort {public static void main(String[] args) {int[] arr{101,34,119,1};insertSort(arr);}//插入排序public static void insertSort(in…

.NET 十五岁,谈谈我眼中的.NET

2002年2月13日&#xff0c;第一个版本随着visual studio.net的发布&#xff0c;今天已经走过15年, .net团队写了一篇文章&#xff0c;里面有一个视频&#xff0c;Anders Hejlsberg已是白发苍苍的老人&#xff0c;我也从刚出校门的码农长成软件开发工程师&#xff0c;我爱编程。…

中国朝代及首都

朝 代 起 讫 都 城 今 地 夏 约前2146-1675年 安邑 山西夏县 ①商 约前1675-1029年 亳 河南商丘 周 西周 ②约前1029-771年 镐京 陕西西安 东周 前770-256年 洛邑 河南洛阳 秦 前221-207年 咸阳 陕西咸阳 汉 ③西汉 前206—公元25 长安 陕西西安 东汉 25—220 洛阳 河南洛阳 三…

什么注解可以改变BigDecimal类型的字段返回的小数位数?

什么注解可以改变BigDecimal类型的字段返回的小数位数&#xff1f;_myme95的博客-CSDN博客 问题背景&#xff1a;我在数据库里有一个字段&#xff0c;是decimal(20,15)类型&#xff0c;但是我在代码里返回数据给前端时&#xff0c;我要返回5位小数给前端。那么怎么转换BigDecim…

ThreadLocal的非数据安全用法

启发于同学处理的bug&#xff0c;他遇到的问题是&#xff1a; “有三台Tomcat服务器&#xff0c;其中有一台Tomcat服务器出现这种情况&#xff1a;一个用户A登录了系统&#xff0c;如果有新的用户B接着登录系统&#xff0c;会把用户A的登录信息给替换成新用户B的信息。这造成无…

理解并从头搭建redis集群

部分开发人员工作当中只是在应用中使用redis&#xff0c;比如用来做数据结果的缓存。而且现在有很多不错的redis客户端工具(redisson)&#xff0c;基本上可以不用关注redis命令就可以完成相当部分的功能。所以可能会对如下这些问题关注点不够&#xff1a; 如何容灾&#xff1f;…

希尔排序+过程分析

图解 代码实现 package com.atguigu.sort;import java.util.Arrays;/*** 创建人 wdl* 创建时间 2021/3/22* 描述*/ public class ShellSort {public static void main(String[] args) {int[] arr {8, 9, 1, 7, 2, 3, 5, 4, 6, 0};shellSort(arr);}//使用逐步推导的方式来编写…

mybatis报错Type interface xxx.Dao is not...

今天在做mybatis的时候&#xff0c;遇到一个错误&#xff0c;大家看看这个错误吧&#xff1a;org.apache.ibatis.binding.BindingException: Type interface cn.mybatis_chop10_1.dao.IEmpDao is not known to the MapperRegistry.我前找找后找找&#xff0c;就是找不出来&…

win10打字突然变成繁体

win10打字突然变成繁体 按住CtrlShiftF&#xff0c;即可在繁体与为简体间切换。

Java 程序员必须掌握的 5 个注解

转载自 Java 程序员必须掌握的 5 个注解 自 JDK5 推出以来&#xff0c;注解已成为Java生态系统不可缺少的一部分。虽然开发者为Java框架&#xff08;例如Spring的Autowired&#xff09;开发了无数的自定义注解&#xff0c;但编译器认可的一些注解非常重要。 在本文中&#xff…

Docker4Dev#7 使用 Windows Container运行ASP.NET MVC 2 + SQLExpress 应用

上一篇Windows Container文章中给大家介绍了如何使用Windows Container运行一个传统的.net 4.5 web应用程序&#xff0c;当时我们使用了默认的Visual Studio模版创建了一个简单的项目&#xff0c;而且没有链接数据库。我相信使用.net进行应用开发的程序员们一定在想&#xff0c…

Mybatis+MySQL动态分页查询数据经典案例

最近在用Mybatis做项目的时候遇到了不少问题&#xff0c;今天我就在这和大家分享一下&#xff0c;稀稀拉拉的研究了两天&#xff0c;终于搞好了&#xff01;开发人员&#xff1a;1111开发软件&#xff1a;Myeclipse用到的框架技术&#xff1a;Mybatis数据库&#xff1a;MySql主…

希尔排序+移位法(吊打交换法)

package com.atguigu.sort;import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date;/*** 创建人 wdl* 创建时间 2021/3/22* 描述*/ public class ShellSort {public static void main(String[] args) { // int[] arr {8, 9, 1, 7, 2, 3, …

那些年的骗子

中午一觉睡醒之后&#xff0c;忽然发现多年不联系的初中同学给我发了个消息&#xff0c;觉得事情没那么简单&#xff1a;正好我的公众号需要大量的用户&#xff0c;我就顺水推舟了&#xff01;一看到QQ的安全提示&#xff0c;我就感觉事情确实不妙&#xff01;初步推断对方是个…

干货 | 彻底弄懂 HTTP 缓存机制及原理

转载自 干货 | 彻底弄懂 HTTP 缓存机制及原理 前言 Http 缓存机制作为 web 性能优化的重要手段&#xff0c;对于从事 Web 开发的同学们来说&#xff0c;应该是知识体系库中的一个基础环节&#xff0c;同时对于有志成为前端架构师的同学来说是必备的知识技能。 但是对于很多…