From 7876ac5d67b12e206a68db17c4034df52fa2f060 Mon Sep 17 00:00:00 2001 From: z8018 <1282578289@qq.com> Date: 星期五, 06 六月 2025 09:23:38 +0800 Subject: [PATCH] 1 --- project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceManager.cs | 380 +++++++++++++++++++++++++++--------------------------- 1 files changed, 190 insertions(+), 190 deletions(-) diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceManager.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceManager.cs index 2ec8018..882c6c8 100644 --- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceManager.cs +++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceManager.cs @@ -1,209 +1,209 @@ -锘縰sing OpenCvSharp; -using System; -using System.Runtime.InteropServices; -/** - * 澶囨敞锛堜汉鑴告暟鎹簱绠$悊璇存槑锛夛細 - * 浜鸿劯鏁版嵁搴撲负閲囩敤sqlite3鐨勬暟鎹簱锛屼細鑷姩鐢熸垚涓�涓猟b鐩綍澶癸紝涓嬮潰鏈夋暟鎹簱face.db鏂囦欢淇濆瓨鏁版嵁搴� - * 鍙敤sqliteExpert涔嬬被鐨勫彲瑙嗗寲宸ュ叿鎵撳紑鏌ョ湅,浜﹀彲鐢ㄥ懡浠よ锛屾柟娉曡鑷鐧惧害銆� - * 璇ユ暟鎹簱浠呬粎鍙�傚簲浜�5w浜哄乏鍙崇殑浜鸿劯搴擄紝涓旇璁¤〃鏍肩瓑灞炰簬灏忓瀷閫氱敤鍖栥�� - * 鑻ヤ笉鑳芥弧瓒冲鎴蜂釜鎬у寲闇�姹傦紝瀹㈡埛鍙嚜琛岃璁℃暟鎹簱淇濆瓨鏁版嵁銆傚畻鏃ㄥ氨鏄瘡涓汉鑴稿浘鐗囨彁鍙栦竴涓壒寰佸�间繚瀛樸�� - * 浜鸿劯1:1,1:N姣斿鍙婅瘑鍒疄闄呭氨鏄壒寰佸�肩殑姣斿銆�1:1鍙鎻愬彇2寮犱笉鍚岀殑鍥剧墖鐗瑰緛鍊艰皟鐢╟ompare_feature姣斿銆� - * 1锛歂鏄彁鍙栦竴涓壒寰佸�煎拰鏁版嵁搴撲腑宸蹭繚瀛樼殑N涓壒寰佸�间竴涓�姣斿(姣斿閫熷害寰堝揩锛屼笉鐢ㄦ媴蹇冩晥鐜囬棶棰�)锛� - * 鏈�缁堝彇鍒嗘暟楂樼殑鍊间负鏈�楂樼浉浼煎害銆� - * 鐩镐技搴﹁瘑鍒殑鍒嗘暟鍙嚜琛屾祴璇曟牴鎹疄楠岀粨鏋滄嫙瀹氾紝涓�鑸帹鑽愮浉浼煎害澶т簬80鍒嗕负鍚屼竴浜恒�� - * - */ -namespace FaceAI -{ - class FaceManager - { - // 浜鸿劯娉ㄥ唽(浼犵壒寰佸��,鐗瑰緛鍊煎彲鍙傝�僃aceFeature.cs鎻愬彇锛屼害鍙弬鑰僃aceCompare.cs鏌ョ湅鐗瑰緛鍊肩殑姣斿) - [DllImport("BaiduFaceApi.dll", EntryPoint = "user_add", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr user_add(ref BDFaceFeature f1, string user_id, string group_id, - string user_info=""); +锘�//using OpenCvSharp; +//using System; +//using System.Runtime.InteropServices; +///** +// * 澶囨敞锛堜汉鑴告暟鎹簱绠$悊璇存槑锛夛細 +// * 浜鸿劯鏁版嵁搴撲负閲囩敤sqlite3鐨勬暟鎹簱锛屼細鑷姩鐢熸垚涓�涓猟b鐩綍澶癸紝涓嬮潰鏈夋暟鎹簱face.db鏂囦欢淇濆瓨鏁版嵁搴� +// * 鍙敤sqliteExpert涔嬬被鐨勫彲瑙嗗寲宸ュ叿鎵撳紑鏌ョ湅,浜﹀彲鐢ㄥ懡浠よ锛屾柟娉曡鑷鐧惧害銆� +// * 璇ユ暟鎹簱浠呬粎鍙�傚簲浜�5w浜哄乏鍙崇殑浜鸿劯搴擄紝涓旇璁¤〃鏍肩瓑灞炰簬灏忓瀷閫氱敤鍖栥�� +// * 鑻ヤ笉鑳芥弧瓒冲鎴蜂釜鎬у寲闇�姹傦紝瀹㈡埛鍙嚜琛岃璁℃暟鎹簱淇濆瓨鏁版嵁銆傚畻鏃ㄥ氨鏄瘡涓汉鑴稿浘鐗囨彁鍙栦竴涓壒寰佸�间繚瀛樸�� +// * 浜鸿劯1:1,1:N姣斿鍙婅瘑鍒疄闄呭氨鏄壒寰佸�肩殑姣斿銆�1:1鍙鎻愬彇2寮犱笉鍚岀殑鍥剧墖鐗瑰緛鍊艰皟鐢╟ompare_feature姣斿銆� +// * 1锛歂鏄彁鍙栦竴涓壒寰佸�煎拰鏁版嵁搴撲腑宸蹭繚瀛樼殑N涓壒寰佸�间竴涓�姣斿(姣斿閫熷害寰堝揩锛屼笉鐢ㄦ媴蹇冩晥鐜囬棶棰�)锛� +// * 鏈�缁堝彇鍒嗘暟楂樼殑鍊间负鏈�楂樼浉浼煎害銆� +// * 鐩镐技搴﹁瘑鍒殑鍒嗘暟鍙嚜琛屾祴璇曟牴鎹疄楠岀粨鏋滄嫙瀹氾紝涓�鑸帹鑽愮浉浼煎害澶т簬80鍒嗕负鍚屼竴浜恒�� +// * +// */ +//namespace FaceAI +//{ +// class FaceManager +// { +// // 浜鸿劯娉ㄥ唽(浼犵壒寰佸��,鐗瑰緛鍊煎彲鍙傝�僃aceFeature.cs鎻愬彇锛屼害鍙弬鑰僃aceCompare.cs鏌ョ湅鐗瑰緛鍊肩殑姣斿) +// [DllImport("BaiduFaceApi.dll", EntryPoint = "user_add", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr user_add(ref BDFaceFeature f1, string user_id, string group_id, +// string user_info=""); - // 浜鸿劯娉ㄥ唽(浼爋pencv鍥剧墖甯�,鐗瑰緛鍊煎彲鍙傝�僃aceFeature.cs鎻愬彇锛屼害鍙弬鑰僃aceCompare.cs鏌ョ湅鐗瑰緛鍊肩殑姣斿) - [DllImport("BaiduFaceApi.dll", EntryPoint = "user_add_by_mat", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr user_add_by_mat(IntPtr mat, string user_id, string group_id, - string user_info = ""); +// // 浜鸿劯娉ㄥ唽(浼爋pencv鍥剧墖甯�,鐗瑰緛鍊煎彲鍙傝�僃aceFeature.cs鎻愬彇锛屼害鍙弬鑰僃aceCompare.cs鏌ョ湅鐗瑰緛鍊肩殑姣斿) +// [DllImport("BaiduFaceApi.dll", EntryPoint = "user_add_by_mat", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr user_add_by_mat(IntPtr mat, string user_id, string group_id, +// string user_info = ""); - // 浜鸿劯鏇存柊(浼犲浘鐗囧抚) - [DllImport("BaiduFaceApi.dll", EntryPoint = "user_update", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr user_update(IntPtr mat, string user_id, string group_id, - string user_info = ""); +// // 浜鸿劯鏇存柊(浼犲浘鐗囧抚) +// [DllImport("BaiduFaceApi.dll", EntryPoint = "user_update", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr user_update(IntPtr mat, string user_id, string group_id, +// string user_info = ""); - // 鐢ㄦ埛鍒犻櫎 - [DllImport("BaiduFaceApi.dll", EntryPoint = "user_delete", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr user_delete(string user_id, string group_id); - // 缁勬坊鍔� - [DllImport("BaiduFaceApi.dll", EntryPoint = "group_add", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr group_add(string group_id); - // 缁勫垹闄� - [DllImport("BaiduFaceApi.dll", EntryPoint = "group_delete", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr group_delete(string group_id); - // 鏌ヨ鐢ㄦ埛淇℃伅 - [DllImport("BaiduFaceApi.dll", EntryPoint = "get_user_info", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr get_user_info(string user_id, string group_id); +// // 鐢ㄦ埛鍒犻櫎 +// [DllImport("BaiduFaceApi.dll", EntryPoint = "user_delete", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr user_delete(string user_id, string group_id); +// // 缁勬坊鍔� +// [DllImport("BaiduFaceApi.dll", EntryPoint = "group_add", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr group_add(string group_id); +// // 缁勫垹闄� +// [DllImport("BaiduFaceApi.dll", EntryPoint = "group_delete", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr group_delete(string group_id); +// // 鏌ヨ鐢ㄦ埛淇℃伅 +// [DllImport("BaiduFaceApi.dll", EntryPoint = "get_user_info", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr get_user_info(string user_id, string group_id); - // 鏌ヨ鐢ㄦ埛鍥剧墖 - [DllImport("BaiduFaceApi.dll", EntryPoint = "get_user_image", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern int get_user_image(IntPtr out_mat, string user_id, string group_id); +// // 鏌ヨ鐢ㄦ埛鍥剧墖 +// [DllImport("BaiduFaceApi.dll", EntryPoint = "get_user_image", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern int get_user_image(IntPtr out_mat, string user_id, string group_id); - // 鐢ㄦ埛缁勫垪琛ㄦ煡璇� - [DllImport("BaiduFaceApi.dll", EntryPoint = "get_user_list", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr get_user_list(string group_id, int start = 0, int length = 100); - // 缁勫垪琛ㄦ煡璇� - [DllImport("BaiduFaceApi.dll", EntryPoint = "get_group_list", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr get_group_list(int start = 0, int length = 100); +// // 鐢ㄦ埛缁勫垪琛ㄦ煡璇� +// [DllImport("BaiduFaceApi.dll", EntryPoint = "get_user_list", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr get_user_list(string group_id, int start = 0, int length = 100); +// // 缁勫垪琛ㄦ煡璇� +// [DllImport("BaiduFaceApi.dll", EntryPoint = "get_group_list", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern IntPtr get_group_list(int start = 0, int length = 100); - // 鏁版嵁搴撲汉鑴告暟閲忔煡璇� - [DllImport("BaiduFaceApi.dll", EntryPoint = "db_face_count", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - public static extern int db_face_count(string group_id); +// // 鏁版嵁搴撲汉鑴告暟閲忔煡璇� +// [DllImport("BaiduFaceApi.dll", EntryPoint = "db_face_count", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// public static extern int db_face_count(string group_id); - // 娴嬭瘯浜鸿劯娉ㄥ唽 - public void test_user_add() - { - // 浜鸿劯娉ㄥ唽 - string user_id = "test_user"; - string group_id = "test_group"; - string file_name = "../images/1.jpg"; +// // 娴嬭瘯浜鸿劯娉ㄥ唽 +// public void test_user_add() +// { +// // 浜鸿劯娉ㄥ唽 +// string user_id = "test_user"; +// string group_id = "test_group"; +// string file_name = "../images/1.jpg"; - string user_info = "user_info"; - // 鎻愬彇浜鸿劯鐗瑰緛鍊兼暟缁勶紙澶氫汉浼氭彁鍙栧涓汉鐨勭壒寰佸�硷級 -/* - FaceFeature feature = new FaceFeature(); - BDFaceFeature[] feaList1 = feature.test_get_face_feature_by_path(file_name - if (feaList1 == null) - { - Console.WriteLine("get feature fail"); - return; - } - // 鍋囪娴嬭瘯鐨勫浘鐗囨槸1涓汉锛� - BDFaceFeature f1 = feaList1[0]; - // 浜鸿劯娉ㄥ唽 (浼犵壒寰佸�间汉鑴告敞鍐岋紝璇ユ柟娉曟敞鍐屼笉淇濆瓨浜鸿劯鍥剧墖鍏ュ簱) - IntPtr ptr = user_add(ref f1, user_id, group_id, user_info); - string buf = Marshal.PtrToStringAnsi(ptr); - Console.WriteLine("user_add res is:" + buf); -*/ - // 閫氳繃鍥剧墖甯т汉鑴告敞鍐岋紙鍙湁璇ユ柟娉曡繘琛岀殑浜鸿劯娉ㄥ唽锛屼汉鑴稿簱鎵嶄細淇濆瓨浜鸿劯鍥剧墖) - Mat mat = Cv2.ImRead(file_name); - IntPtr mptr = user_add_by_mat(mat.CvPtr, user_id, group_id, user_info); - string mbuf = Marshal.PtrToStringAnsi(mptr); - Console.WriteLine("user_add_by_mat res is:" + mbuf); - } +// string user_info = "user_info"; +// // 鎻愬彇浜鸿劯鐗瑰緛鍊兼暟缁勶紙澶氫汉浼氭彁鍙栧涓汉鐨勭壒寰佸�硷級 +///* +// FaceFeature feature = new FaceFeature(); +// BDFaceFeature[] feaList1 = feature.test_get_face_feature_by_path(file_name +// if (feaList1 == null) +// { +// Console.WriteLine("get feature fail"); +// return; +// } +// // 鍋囪娴嬭瘯鐨勫浘鐗囨槸1涓汉锛� +// BDFaceFeature f1 = feaList1[0]; +// // 浜鸿劯娉ㄥ唽 (浼犵壒寰佸�间汉鑴告敞鍐岋紝璇ユ柟娉曟敞鍐屼笉淇濆瓨浜鸿劯鍥剧墖鍏ュ簱) +// IntPtr ptr = user_add(ref f1, user_id, group_id, user_info); +// string buf = Marshal.PtrToStringAnsi(ptr); +// Console.WriteLine("user_add res is:" + buf); +//*/ +// // 閫氳繃鍥剧墖甯т汉鑴告敞鍐岋紙鍙湁璇ユ柟娉曡繘琛岀殑浜鸿劯娉ㄥ唽锛屼汉鑴稿簱鎵嶄細淇濆瓨浜鸿劯鍥剧墖) +// Mat mat = Cv2.ImRead(file_name); +// IntPtr mptr = user_add_by_mat(mat.CvPtr, user_id, group_id, user_info); +// string mbuf = Marshal.PtrToStringAnsi(mptr); +// Console.WriteLine("user_add_by_mat res is:" + mbuf); +// } - // 娴嬭瘯浜鸿劯鏇存柊 - public void test_user_update() - { - string user_id = "test_user"; - string group_id = "test_group"; - string file_name = "../images/1.jpg"; - Mat mat = Cv2.ImRead(file_name); - string user_info = "user_info"; - // 浜鸿劯鏇存柊 - IntPtr ptr = user_update(mat.CvPtr, user_id, group_id, user_info); - string buf = Marshal.PtrToStringAnsi(ptr); - Console.WriteLine("user_update res is:" + buf); - } +// // 娴嬭瘯浜鸿劯鏇存柊 +// public void test_user_update() +// { +// string user_id = "test_user"; +// string group_id = "test_group"; +// string file_name = "../images/1.jpg"; +// Mat mat = Cv2.ImRead(file_name); +// string user_info = "user_info"; +// // 浜鸿劯鏇存柊 +// IntPtr ptr = user_update(mat.CvPtr, user_id, group_id, user_info); +// string buf = Marshal.PtrToStringAnsi(ptr); +// Console.WriteLine("user_update res is:" + buf); +// } - // 娴嬭瘯鐢ㄦ埛鍒犻櫎 锛堢敤鎴峰垹闄ゅ悗锛屼汉鑴告暟鎹篃琚垹闄わ級 - public void test_user_delete() - { - string user_id = "test_user"; - string group_id = "test_group"; - IntPtr ptr = user_delete(user_id, group_id); - string buf = Marshal.PtrToStringAnsi(ptr); - Console.WriteLine("user_delete res is:" + buf); - } +// // 娴嬭瘯鐢ㄦ埛鍒犻櫎 锛堢敤鎴峰垹闄ゅ悗锛屼汉鑴告暟鎹篃琚垹闄わ級 +// public void test_user_delete() +// { +// string user_id = "test_user"; +// string group_id = "test_group"; +// IntPtr ptr = user_delete(user_id, group_id); +// string buf = Marshal.PtrToStringAnsi(ptr); +// Console.WriteLine("user_delete res is:" + buf); +// } - // 缁勬坊鍔� - public void test_group_add() - { - string group_id = "test_group2"; - IntPtr ptr = group_add(group_id); - string buf = Marshal.PtrToStringAnsi(ptr); - Console.WriteLine("group_add res is:" + buf); - } +// // 缁勬坊鍔� +// public void test_group_add() +// { +// string group_id = "test_group2"; +// IntPtr ptr = group_add(group_id); +// string buf = Marshal.PtrToStringAnsi(ptr); +// Console.WriteLine("group_add res is:" + buf); +// } - // 缁勫垹闄� - public void test_group_delete() - { - string group_id = "test_group2"; - IntPtr ptr = group_delete(group_id); - string buf = Marshal.PtrToStringAnsi(ptr); - Console.WriteLine("group_delete res is:" + buf); - } +// // 缁勫垹闄� +// public void test_group_delete() +// { +// string group_id = "test_group2"; +// IntPtr ptr = group_delete(group_id); +// string buf = Marshal.PtrToStringAnsi(ptr); +// Console.WriteLine("group_delete res is:" + buf); +// } - // 鏌ヨ鐢ㄦ埛淇℃伅 - public void test_get_user_info() - { - string user_id = "test_user"; - string group_id = "test_group"; - IntPtr ptr = get_user_info(user_id , group_id); - string buf = Marshal.PtrToStringAnsi(ptr); - Console.WriteLine("get_user_info res is:" + buf); - } +// // 鏌ヨ鐢ㄦ埛淇℃伅 +// public void test_get_user_info() +// { +// string user_id = "test_user"; +// string group_id = "test_group"; +// IntPtr ptr = get_user_info(user_id , group_id); +// string buf = Marshal.PtrToStringAnsi(ptr); +// Console.WriteLine("get_user_info res is:" + buf); +// } - // 鏌ヨ鐢ㄦ埛鍥剧墖 - public void test_get_user_image() - { - string user_id = "test_user"; - string group_id = "test_group"; - Mat out_mat = new Mat(); - int res = get_user_image(out_mat.CvPtr, user_id, group_id); - if (res == 0) - { - Console.WriteLine("get_user_image success"); - // 鍥剧墖淇濆瓨鍒版湰鍦� - out_mat.ImWrite("user.jpg"); - } - else - { - Console.WriteLine("get_user_image error{0}:", res); - } +// // 鏌ヨ鐢ㄦ埛鍥剧墖 +// public void test_get_user_image() +// { +// string user_id = "test_user"; +// string group_id = "test_group"; +// Mat out_mat = new Mat(); +// int res = get_user_image(out_mat.CvPtr, user_id, group_id); +// if (res == 0) +// { +// Console.WriteLine("get_user_image success"); +// // 鍥剧墖淇濆瓨鍒版湰鍦� +// out_mat.ImWrite("user.jpg"); +// } +// else +// { +// Console.WriteLine("get_user_image error{0}:", res); +// } - } +// } - // 鐢ㄦ埛缁勫垪琛ㄦ煡璇� - public void test_get_user_list() - { - string group_id = "test_group"; - IntPtr ptr = get_user_list(group_id); - string buf = Marshal.PtrToStringAnsi(ptr); - Console.WriteLine("get_user_list res is:" + buf); - } +// // 鐢ㄦ埛缁勫垪琛ㄦ煡璇� +// public void test_get_user_list() +// { +// string group_id = "test_group"; +// IntPtr ptr = get_user_list(group_id); +// string buf = Marshal.PtrToStringAnsi(ptr); +// Console.WriteLine("get_user_list res is:" + buf); +// } - // 缁勫垪琛ㄦ煡璇� - public void test_get_group_list() - { - IntPtr ptr = get_group_list(); - string buf = Marshal.PtrToStringAnsi(ptr); - Console.WriteLine("get_group_list res is:" + buf); - } +// // 缁勫垪琛ㄦ煡璇� +// public void test_get_group_list() +// { +// IntPtr ptr = get_group_list(); +// string buf = Marshal.PtrToStringAnsi(ptr); +// Console.WriteLine("get_group_list res is:" + buf); +// } - // 浜鸿劯搴撴暟閲忔煡璇� - public void test_db_face_count() - { - string group_id = "test_group"; - // 鍙傛暟浼犵粍id琛ㄧず鏌ヨ缁勯兘浜鸿劯鏁伴噺 - int count = db_face_count(group_id); - Console.WriteLine("count is:" + count); - string group_id2 = null; - // 鍙傛暟浼爊ull琛ㄧず鏌ユ暣涓簱 - int count2 = db_face_count(group_id2); - Console.WriteLine("all count is:" + count2); - } - } -} +// // 浜鸿劯搴撴暟閲忔煡璇� +// public void test_db_face_count() +// { +// string group_id = "test_group"; +// // 鍙傛暟浼犵粍id琛ㄧず鏌ヨ缁勯兘浜鸿劯鏁伴噺 +// int count = db_face_count(group_id); +// Console.WriteLine("count is:" + count); +// string group_id2 = null; +// // 鍙傛暟浼爊ull琛ㄧず鏌ユ暣涓簱 +// int count2 = db_face_count(group_id2); +// Console.WriteLine("all count is:" + count2); +// } +// } +//} -- Gitblit v1.9.3