人脸注册源码faceregiste

人脸注册:

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

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

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

相关文章

LC67---删除有序链表中重复的元素---牛客---JAVA

import java.util.*;/** public class ListNode {* int val;* ListNode next null;* }*/public class Solution {/*** * param head ListNode类 * return ListNode类*/public ListNode deleteDuplicates (ListNode head) {if(headnull)return head;ListNode temp head;wh…

破坏双亲委派机制的那些事

转载自 破坏双亲委派机制的那些事 前言 今天重读《深入理解Java虚拟》这本书&#xff0c;读到破坏双亲委派机制这一小节&#xff0c;其中有一段话&#xff0c;如下 双亲委派模型的第二次“被破坏”是由这个模型自身的缺陷所导致的&#xff0c;双亲委派很好地解决了各个类加…

Windows 容器

什么是容器 它们是隔离、资源控制且可移植的操作环境。 基本上&#xff0c;容器是一个隔离的位置&#xff0c;应用程序可在其中运行&#xff0c;而不会影响系统的其他部分&#xff0c;并且系统也不会影响该应用程序。 容器是虚拟化的下一个演化。 如果你在容器内&#xff0c;看…

人脸认证源码faceIdentify

人脸认证&#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; 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…