日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

人脸认证源码faceIdentify

發布時間:2023/12/3 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 人脸认证源码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();}} }

總結

以上是生活随笔為你收集整理的人脸认证源码faceIdentify的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。