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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

记录一下:调试了虹软的人脸识别sdk,存到数据库中

發(fā)布時(shí)間:2023/12/10 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 记录一下:调试了虹软的人脸识别sdk,存到数据库中 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

虹軟的人臉識(shí)別sdk

  • 前言
  • 一、虹軟是什么?
  • 二、使用步驟
    • 1.引入庫(kù)
    • 2.讀入數(shù)據(jù)
  • 總結(jié)
    • 更新架構(gòu)
    • 更新數(shù)據(jù)庫(kù)(增加圖片存儲(chǔ))


前言

最近偶爾看到了虹軟sdk開放了活體檢測(cè)的功能,以前記得19年的時(shí)候就關(guān)注過虹軟的人臉識(shí)別免費(fèi)開放的消息?,F(xiàn)在正好拿來(lái)玩玩。

案例僅供參考

一、虹軟是什么?

虹軟是計(jì)算機(jī)視覺行業(yè)領(lǐng)先的算法服務(wù)提供商及解決方案供應(yīng)商,服務(wù)于世界各地的客戶,將領(lǐng)先的計(jì)算機(jī)視覺技術(shù)商業(yè)化應(yīng)用在智能手機(jī)、智能汽車、智能家居、智能零售、互聯(lián)網(wǎng)視頻等領(lǐng)域,并且仍在不斷探索新的領(lǐng)域與方向。

開放了人臉識(shí)別,人證核驗(yàn)和活體檢測(cè)的sdk

二、使用步驟

1.引入庫(kù)

1.使用C# 作為開發(fā)語(yǔ)言,選擇了C++的sdk

去他們官網(wǎng)注冊(cè)好賬號(hào)后,可以選擇不同的環(huán)境以及不同的sdk

2.

準(zhǔn)備幾張照片,我準(zhǔn)備了三張照片。 ![在這里插入圖片描述](https://img-blog.csdnimg.cn/20201202085634135.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d1eWFuZzE5OTU=,size_16,color_FFFFFF,t_70) 以下是建表語(yǔ)句: ![在這里插入圖片描述](https://img-blog.csdnimg.cn/20201202085831428.png) ![在這里插入圖片描述](https://img-blog.csdnimg.cn/20201202090028917.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d1eWFuZzE5OTU=,size_16,color_FFFFFF,t_70)

username 是人員名字
userfeature 是特征,特征值在虹軟的2.2版本里面使用intptr存儲(chǔ)的,3.0 則使用byte[ ]存儲(chǔ)。3.0會(huì)比較方便。直接轉(zhuǎn)換成basestring 存儲(chǔ)即可。
userfeaturesize 是字符數(shù)量

2.讀入數(shù)據(jù)


在注冊(cè)人臉這,添加以下代碼。

public class UserModel{public string username { get; set; }public string userfeature { get; set; }public int userfeaturesize { get; set; }} //創(chuàng)建數(shù)據(jù)庫(kù)對(duì)象SqlSugarClient db = new SqlSugarClient(new ConnectionConfig(){ConnectionString = ConnectionStringObject.ConnectionString,//連接符字串DbType = DbType.Sqlite,IsAutoCloseConnection = true,InitKeyType = InitKeyType.Attribute//從特性讀取主鍵自增信息}); UserModel usermodel = new UserModel(){username = "women2",userfeature = Convert.ToBase64String(feature.feature),userfeaturesize = feature.featureSize};db.Insertable(usermodel).ExecuteCommand();

在后面,在demo的基礎(chǔ)上添加了后臺(tái)按鈕。

//初始化的時(shí)候讀取 public bool InitUserFaces(){try{SqlSugarClient db = new SqlSugarClient(new ConnectionConfig(){ConnectionString = ConnectionStringObject.ConnectionString,//連接符字串DbType = DbType.Sqlite,IsAutoCloseConnection = true,InitKeyType = InitKeyType.Attribute//從特性讀取主鍵自增信息});UserFaces = db.Queryable<UserModel>().ToList();db.Close();db.Dispose();return true;}catch (Exception ex){return false;//throw;}}public List<UserModel> UserFaces = new List<UserModel>();try{ 創(chuàng)建數(shù)據(jù)庫(kù)對(duì)象SqlSugarClient db = new SqlSugarClient(new ConnectionConfig(){ConnectionString = ConnectionStringObject.ConnectionString,//連接符字串DbType = DbType.Sqlite,IsAutoCloseConnection = true,InitKeyType = InitKeyType.Attribute//從特性讀取主鍵自增信息});var facelist = db.Queryable<UserModel>().ToList();//在點(diǎn)擊開始的時(shí)候再坐下初始化檢測(cè),防止程序啟動(dòng)時(shí)有攝像頭,在點(diǎn)擊攝像頭按鈕之前將攝像頭拔掉的情況initVideo();//必須保證有可用攝像頭if (filterInfoCollection.Count == 0){MessageBox.Show("未檢測(cè)到攝像頭,請(qǐng)確保已安裝攝像頭或驅(qū)動(dòng)!");return;}if (rgbVideoSource.IsRunning || irVideoSource.IsRunning){btnStartVideo.Text = "啟用攝像頭";//關(guān)閉攝像頭if (irVideoSource.IsRunning){irVideoSource.SignalToStop();irVideoSource.Hide();}if (rgbVideoSource.IsRunning){rgbVideoSource.SignalToStop();rgbVideoSource.Hide();}//“選擇識(shí)別圖”、“開始匹配”按鈕可用,閾值控件禁用ControlsEnable(true, chooseImgBtn, matchBtn, chooseMultiImgBtn, btnClearFaceList);txtThreshold.Enabled = false;exitVideoRGBFR = true;exitVideoRGBLiveness = true;}else{if (isCompare){//比對(duì)結(jié)果清除for (int i = 0; i < imagesFeatureList.Count; i++){imageList.Items[i].Text = string.Format("{0}號(hào)", i);}lblCompareInfo.Text = string.Empty;isCompare = false;}//“選擇識(shí)別圖”、“開始匹配”按鈕禁用,閾值控件可用,顯示攝像頭控件txtThreshold.Enabled = true;rgbVideoSource.Show();irVideoSource.Show();ControlsEnable(false, chooseImgBtn, matchBtn, chooseMultiImgBtn, btnClearFaceList);btnStartVideo.Text = "關(guān)閉攝像頭";//獲取filterInfoCollection的總數(shù)int maxCameraCount = filterInfoCollection.Count;//如果配置了兩個(gè)不同的攝像頭索引if (rgbCameraIndex != irCameraIndex && maxCameraCount >= 2){//RGB攝像頭加載rgbDeviceVideo = new VideoCaptureDevice(filterInfoCollection[rgbCameraIndex < maxCameraCount ? rgbCameraIndex : 0].MonikerString);rgbVideoSource.VideoSource = rgbDeviceVideo;rgbVideoSource.Start();//IR攝像頭irDeviceVideo = new VideoCaptureDevice(filterInfoCollection[irCameraIndex < maxCameraCount ? irCameraIndex : 0].MonikerString);irVideoSource.VideoSource = irDeviceVideo;irVideoSource.Start();//雙攝標(biāo)志設(shè)為trueisDoubleShot = true;}else{//僅打開RGB攝像頭,IR攝像頭控件隱藏rgbDeviceVideo = new VideoCaptureDevice(filterInfoCollection[rgbCameraIndex <= maxCameraCount ? rgbCameraIndex : 0].MonikerString);rgbVideoSource.VideoSource = rgbDeviceVideo;rgbVideoSource.Start();irVideoSource.Hide();}//啟動(dòng)兩個(gè)檢測(cè)線程exitVideoRGBFR = false;exitVideoRGBLiveness = false;videoRGBLiveness();//videoRGBFR();videoRGBFRServer();}}catch (Exception ex){LogUtil.LogInfo(GetType(), ex);}private void videoRGBFRServer(){int index = 10000;ThreadPool.QueueUserWorkItem(new WaitCallback(delegate {while (true){//index--;//if (index == 0)//{// index = 10000;// existNewFace = true;//}if (exitVideoRGBFR){return;}try{//if (ableReadFaceInfo && existNewFace && handleQueue.Contains(faceIDTemp) && !livenessResult.Equals(livenessInitValue))if (ableReadFaceInfo && existNewFace && !livenessResult.Equals(livenessInitValue)){ableReadFR = false;if (livenessResult.Equals(1) && rect.left != 0 && rect.right != 0 && rect.top != 0 && rect.bottom != 0){int result = -1;float similarity = 0f;for (int i = 0; i < frMatchTime; i++){if (exitVideoRGBFR){break;}Console.WriteLine(string.Format("faceid:{0},特征搜索第{1}次\r\n", "999", i + 1));Bitmap bitmapTemp = rgbVideoSource.GetCurrentVideoFrame();if (bitmapTemp == null){break;}//提取人臉特征FaceFeature feature = FaceUtil.ExtractFeature(videoRGBImageEngine, bitmapTemp, maxFace);similarity = 0f;result = compareFeatureServer(feature, out similarity);//得到比對(duì)結(jié)果if (result > -1){break;}}if (!result.Equals(-1)){//將比對(duì)結(jié)果放到顯示消息中,用于最新顯示trackRGBUnit.message = string.Format(" {0}號(hào) {1},{2},Faceid:{3}", result, similarity, string.Format("RGB{0}", CommonUtil.TransLivenessResult(livenessResult)), UserFaces[result].username);}else{//顯示消息trackRGBUnit.message = string.Format("RGB{0},Faceid:{1}", CommonUtil.TransLivenessResult(livenessResult), result);}}else{//顯示消息trackRGBUnit.message = string.Format("RGB{0},Faceid:{1}", CommonUtil.TransLivenessResult(livenessResult), "999");}}}catch (Exception ex){Console.WriteLine(ex.Message);}finally{ableReadFR = true;}}}));}/// <summary>/// 得到feature比較結(jié)果/// </summary>/// <param name="feature"></param>/// <returns></returns>private int compareFeatureServer(FaceFeature feature, out float similarity){int result = -1;similarity = 0f;try{//如果人臉庫(kù)不為空,則進(jìn)行人臉匹配if (UserFaces != null && UserFaces.Count > 0){for (int i = 0; i < UserFaces.Count; i++){//調(diào)用人臉匹配方法,進(jìn)行匹配videoRGBImageEngine.ASFFaceFeatureCompare(feature,new FaceFeature() {feature = Convert.FromBase64String( UserFaces[i].userfeature),featureSize = UserFaces[i].userfeaturesize } , out similarity);if (similarity >= threshold){result = i;break;}}}}catch (Exception ex){LogUtil.LogInfo(GetType(), ex);}return result;}
ok 程序到這里就修改完成了。每次程序啟動(dòng)之后,會(huì)從bin文件夾下面的.db文件里面讀取出所有的人臉。然后每次通過攝像頭去匹配。 已測(cè)試,效果挺好,識(shí)別的很快。就是還有一些小問題。但是總體來(lái)說效果很好。

總結(jié)

gitee,代碼地址:人臉識(shí)別

更新架構(gòu)

這是官方的樣例demo介紹,本文也是幾乎差不多的原理,目前實(shí)現(xiàn)了小型智慧工地的人臉識(shí)別系統(tǒng)的設(shè)計(jì)。

以后有機(jī)會(huì)的話會(huì)更新成下圖右邊的c/s系統(tǒng)設(shè)計(jì)

更新數(shù)據(jù)庫(kù)(增加圖片存儲(chǔ))



總共兩張表

總結(jié)

以上是生活随笔為你收集整理的记录一下:调试了虹软的人脸识别sdk,存到数据库中的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。