人脸登陆:

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();}}
}

人脸登陆facelogin相关推荐

  1. 利用百度人脸识别API,实现人脸登陆JavaWeb

    JavaWeb利用百度API实现人脸登陆功能 笔者的完整项目 1,在百度云注册人脸库 2,引入必要的包 3,编写java代码 4,介绍对人脸库的增删改查功能 5,该功能加入到我的项目 (1),界面展示 ...

  2. 微信h5页面实现人脸注册和登陆

    工作中总会遇到一些麻烦的问题,有问题不要怕解决就好了,前段时间要实现微信h5页面人脸注册/登录,本以为很简单的一个东西,没想到居然这么麻烦,写个文章记录下过程和遇到的问题及解决办法: 需求:①人脸注册 ...

  3. 【转】人脸识别功能的用户体验设计优化

    2016-08-09 人脸识别技术是生物特征识别技术的一种,因其相对其它生物特征识别技术的优点而在市场上得到广泛应用.在人脸识别功能优化设计的项目中,主要以"三步走"的流程完成了设 ...

  4. 调用远程摄像头进行人脸识别_人脸识别技术植入手机APP

    随着物联网技术的日益成熟,我们看到已经有很多APP用到了人脸识别技术,特别是金融和互联网领域的应用纷纷加入了人脸识别.表示,人脸识别技术基于人的脸部特征信息进行身份识别,为互联网金融等行业解决在线多维 ...

  5. java实现人脸识别(使用百度云V3版本)

    2017年,开发了第一个版本的人脸识别,当时费时有5天之久终于写出来了,但是只适用于火狐浏览器,别的浏览器都打不开摄像头. 2018年,将人脸识别重新完善,可以支持360.火狐.谷歌等主流浏览器,版本 ...

  6. java实现人脸识别V3版本开发

    有段时间没有写更新公众号了,也许好多人都忘记了自己还关注了这么个公众号. 因为这段时间确实是有其他的事比较忙,还有一个原因就是自己在技术方面没有学习新的东西,所以没有可更新的(包括博客) 今天,我决定 ...

  7. 人脸识别登录:加强系统认证

    识别未来 先看下效果图吧,满足你们的好奇心,哈哈哈 人脸登录成功 人脸登录失败 注册人脸 人脸库 一.创作动机 早在很久之前,公司同事已经实现了在网站的登陆模块加上人脸识别认证登陆功能,自己也就萌生了 ...

  8. 手把手教你实现一个人脸认证登录系统

    ​先看下效果图吧,满足你们的好奇心,哈哈哈 人脸登录成功 人脸登录失败 注册人脸 人脸库 一.创作动机 早在很久之前,公司同事已经实现了在网站的登陆模块加上人脸识别认证登陆功能,自己也就萌生了动手在自 ...

  9. 浅谈一下我对Android实现人脸认证登录的认识

    1.什么是人脸认证登录? (简称TRFA:Tencent Research Face Authentication)是由腾讯研究院研制的. 从功能上来看,人脸认证登录系统是基于终端摄像头的一种身份加密 ...

最新文章

  1. 由文档那些事儿引发的思考 - 领导,您该反思了
  2. Linux - 磁盘操作
  3. GitHub 标星 5000+!学生党学编程,有这份资料就够了!
  4. 移动Sql Server数据库的脚本
  5. JDBC之数据库的连接步骤(六步)
  6. 我们来判断一个php函数是否被定义
  7. python:configparser模块
  8. 学习C/C++的经验谈
  9. kk5.0电脑版 服务器信息,1 月 2017 累积更新 5.0.8308.984 Lync Server 2013 web 组件服务器...
  10. Star Way To Heaven
  11. 操作系统重要知识清单:一起来搞懂进程呀!!
  12. 2019UI设计岗位最常见的面试题
  13. a8处理器相当于骁龙几_曾受人追捧的A8处理器,放在现在是什么水平了?
  14. linux shell ifs,Shell 的 IFS 变量
  15. 微信开发者工具调试大法
  16. UltraEdit 15.10注册码
  17. 使用俄罗斯老大哥的Wrap进行缩裹式半自动重拓扑
  18. 基于javaweb的公文文档收发管理系统
  19. 蒲慕明院士:脑机融合技术或许会成为未来人工智能的一个热门方向
  20. 金融数据分析(八)计算股票的超额收益率

热门文章

  1. python socket编程之双方相互通信简单实例_Python socket实现的简单通信功能示例
  2. python比较三个数_python经典练习题(三)
  3. 递归算法(二)-分治法
  4. 多项式求逆模板(NTT + mod)
  5. P2765 魔术球问题(网络流)
  6. Codeforces Round #740 (Div. 2) E. Bottom-Tier Reversals 构造
  7. AGC038D - Unique Path(建图)
  8. P2617 Dynamic Rankings(整体二分)
  9. [HEOI2016TJOI2016]排序(二分+线段树)
  10. [2.9训练]【CF909C】Python Indentation,【CF909D】Colorful Points,【CF909E】Coprocessor