人脸登陆facelogin

人脸登陆:

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 facelogin : Form{//Api_Keypublic static string Api_Key = "OVYw5Ok0y9U8n6CfVPYt0wfZ";//Secret_Keypublic static string Secret_Key = "aCN3lupCarq3rC9G8Rylqz1d36Towp8G";public facelogin(){InitializeComponent();//启动默认在屏幕中间this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;}FilterInfoCollection videoDevices;VideoCaptureDevice videoSource;public int selectedDeviceIndex = 0;public int selectedPICIndex = 0;//窗体加载private void facelogin_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();}/// <summary>/// 点击确定的按钮/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button2_Click(object sender, EventArgs e){//先获取用户名//然后在提取图片//先查询用户名,看看有没有该用户名//有该用户名的话继续判断人脸对应不,没有的话提示没有该用户string name = this.textBox1.Text;Users user = QueryUsersByName(name);if (((string)(user.name))!=""){//有该用户,判断摄入的人脸和人脸库中的对比FaceVerify(SavePicture(),user);}else { //说明没有该用户,提示用户重新输入用户名MessageBox.Show("对不起,检测到没有该用户,请重新输入", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);}}/// <summary>/// 人脸认证【登陆】/// </summary>public  void FaceVerify(string filename,Users users){var client = new Baidu.Aip.Face.Face(Api_Key ,Secret_Key);var image1 = File.ReadAllBytes(filename);var result = client.User.Verify(image1,(users.id).ToString(), new[] { "gr_test" }, 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());string resu = jo_age.ToString();int num1 = resu.IndexOf("\n") + 2;int num2 = resu.LastIndexOf("]") - 8;string ids = resu.Substring(num1, num2);if (ids != null || !ids.Equals("")){double scores_num = double.Parse(ids);if (scores_num > 80){MessageBox.Show("登陆成功,已检测到您的信息", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}else{MessageBox.Show("对不起,脸与账户不对应,请换张脸试试", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);}}}}/// <summary>/// 根据编号查询用户信息/// </summary>/// <param name="id"></param>/// <returns></returns>public static Users QueryUsersByName(string name){Users user = new Users();string sql = "select * from users where name = @name";using (SqlDataReader reader = SqlHelper.ExcuteReader(sql, CommandType.Text, new SqlParameter("@name", name))){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;}/// <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="sender"></param>/// <param name="e"></param>private void close_Click(object sender, EventArgs e){//停止摄像头videoSourcePlayer1.Stop();this.Close();welcome we = new welcome();we.Show();}}
}

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

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

相关文章

插入排序+思路分析

图解 代码实现 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;同时对于有志成为前端架构师的同学来说是必备的知识技能。 但是对于很多…

实习知识整理7:SpringBoot和html+thymeleaf模板的项目的相关配置文件

1. application.yml server: port: 8082servlet:context-path: /project #设置访问地址 http://localhost:8082/project 才可以访问到 static 下 index.htmlspring:datasource: # 数据库driver-class-name: com.mysql.cj.jdbc.Driver # 这是8的配置&#xff0c;5的话不用…

Visual Basic的未来之路

上周&#xff0c;微软宣布了他们改变Visual Basic语言未来发展计划的想法。这次公布给Visual Basic开发人员留下了很多不确定性&#xff0c;但Visual Basic语言的设计者Anthony D.Green说明了这个新策略的一些细节。 Green首先列出了当时使用VB进行开发的四个基础指导原则&…

快速排序+思路分析

图解 代码实现 package com.atguigu.sort;import com.sun.org.apache.xpath.internal.WhitespaceStrippingElementMatcher;import java.util.Arrays;/*** 创建人 wdl* 创建时间 2021/3/22* 描述*/ public class QuickSort {public static void main(String[] args) {//[-9,78,…

jquery sleep函数

function sleep(n) { //n表示的毫秒数 var start new Date().getTime(); while (true) if (new Date().getTime() - start > n) break; } console.log(new Date()); this.sleep(3000); console.log(new Date());

2017 年编程语言排行榜:Python 排第一

站长之家(ChinaZ.com) 7 月 24 日消息&#xff0c;近日根据 IEEE Spectrum 发布的研究报告显示&#xff0c;在 2016 年排名第三的 Python 在今年已经成为世界上最受欢迎的语言&#xff0c;C 和 Java 分别位居第二和第三位。IEEE Spectrum 的排行依据数据记者 Nick Diakopoulos …