From ee5e3a086a5dc145e7f5df3de32e0e072c183949 Mon Sep 17 00:00:00 2001 From: z8018 <1282578289@qq.com> Date: 星期五, 06 六月 2025 15:19:40 +0800 Subject: [PATCH] 1 --- project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceFeature.cs | 238 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 119 insertions(+), 119 deletions(-) diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceFeature.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceFeature.cs index 7f38d29..a0cd4ee 100644 --- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceFeature.cs +++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_Common/FaceAI/FaceFeature.cs @@ -1,133 +1,133 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Runtime.InteropServices; -using System.IO; -using OpenCvSharp; +锘�//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; +//using System.Runtime.InteropServices; +//using System.IO; +////using OpenCvSharp; -// 鎻愬彇浜鸿劯鐗瑰緛鍊� -namespace FaceAI -{ - // 浜鸿劯鐗瑰緛鍊肩粨鏋勪綋 - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct BDFaceFeature - { - public int size; - // 浜鸿劯鐨勭壒寰佸�硷紝鎻愬彇鍑烘潵鍚庢槸128涓猣loat鐨勬诞鐐瑰�� - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] - public float[] data;// = new float[128]; - } - // 浜鸿劯鐗瑰緛鍊肩粨鏋勪綋 - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct BDDepthFeature - { - public int size; - // 浜鸿劯鐨勬繁搴︾壒寰佸�硷紝鎻愬彇鍑烘潵鍚庢槸256涓猣loat鐨勬诞鐐瑰�� - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] - public float[] data;// = new float[256]; - } - class FaceFeature - { - // 鎻愬彇浜鸿劯鐗瑰緛鍊� - [DllImport("BaiduFaceApi.dll", EntryPoint = "face_feature", CharSet = CharSet.Ansi - , CallingConvention = CallingConvention.Cdecl)] - // 杩斿洖num涓虹壒寰佸�肩殑浜烘暟,type涓�0琛ㄧず鎻愬彇鐢熸椿鐓х殑鐗瑰緛鍊硷紝1琛ㄧずnir鐨勭壒寰佸�� - public static extern int face_feature(IntPtr feature, IntPtr box, IntPtr mat, int type); +//// 鎻愬彇浜鸿劯鐗瑰緛鍊� +//namespace FaceAI +//{ +// // 浜鸿劯鐗瑰緛鍊肩粨鏋勪綋 +// [StructLayout(LayoutKind.Sequential, Pack = 1)] +// public struct BDFaceFeature +// { +// public int size; +// // 浜鸿劯鐨勭壒寰佸�硷紝鎻愬彇鍑烘潵鍚庢槸128涓猣loat鐨勬诞鐐瑰�� +// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] +// public float[] data;// = new float[128]; +// } +// // 浜鸿劯鐗瑰緛鍊肩粨鏋勪綋 +// [StructLayout(LayoutKind.Sequential, Pack = 1)] +// public struct BDDepthFeature +// { +// public int size; +// // 浜鸿劯鐨勬繁搴︾壒寰佸�硷紝鎻愬彇鍑烘潵鍚庢槸256涓猣loat鐨勬诞鐐瑰�� +// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] +// public float[] data;// = new float[256]; +// } +// class FaceFeature +// { +// // 鎻愬彇浜鸿劯鐗瑰緛鍊� +// [DllImport("BaiduFaceApi.dll", EntryPoint = "face_feature", CharSet = CharSet.Ansi +// , CallingConvention = CallingConvention.Cdecl)] +// // 杩斿洖num涓虹壒寰佸�肩殑浜烘暟,type涓�0琛ㄧず鎻愬彇鐢熸椿鐓х殑鐗瑰緛鍊硷紝1琛ㄧずnir鐨勭壒寰佸�� +// public static extern int face_feature(IntPtr feature, IntPtr box, IntPtr mat, int type); - public void test_face_feature() - { - long t_begin = TimeUtil.get_time_stamp(); - BDFaceFeature[] fea1 = test_get_face_feature_by_path("../images/2.jpg"); - long t_end = TimeUtil.get_time_stamp(); - Console.WriteLine("get feature time cost is:" + (t_end - t_begin)); - } +// public void test_face_feature() +// { +// long t_begin = TimeUtil.get_time_stamp(); +// BDFaceFeature[] fea1 = test_get_face_feature_by_path("../images/2.jpg"); +// long t_end = TimeUtil.get_time_stamp(); +// Console.WriteLine("get feature time cost is:" + (t_end - t_begin)); +// } - // 鑾峰彇鐗瑰緛鍊硷紝浼犲叆鍥剧墖璺緞 - public BDFaceFeature[] test_get_face_feature_by_path(string img_path) - { - // 鐗瑰緛鍊肩殑闀垮害锛�128涓猣loat鍊� - int dim_count = 128; - Mat mat = Cv2.ImRead(img_path); - // 鍋囪鎻愬彇鐨勪汉鏁帮紝闇�瑕佹瘮瀹為檯鐨勪汉鏁板锛屽洜涓洪渶瑕佹彁鍙栧垎閰嶅唴瀛� - int faceNum = 5; - BDFaceFeature[] feaList = new BDFaceFeature[faceNum]; - for(int i = 0; i < faceNum; i++) - { - feaList[i].data = new float[dim_count]; - feaList[i].size = 0; - } +// // 鑾峰彇鐗瑰緛鍊硷紝浼犲叆鍥剧墖璺緞 +// public BDFaceFeature[] test_get_face_feature_by_path(string img_path) +// { +// // 鐗瑰緛鍊肩殑闀垮害锛�128涓猣loat鍊� +// int dim_count = 128; +// Mat mat = Cv2.ImRead(img_path); +// // 鍋囪鎻愬彇鐨勪汉鏁帮紝闇�瑕佹瘮瀹為檯鐨勪汉鏁板锛屽洜涓洪渶瑕佹彁鍙栧垎閰嶅唴瀛� +// int faceNum = 5; +// BDFaceFeature[] feaList = new BDFaceFeature[faceNum]; +// for(int i = 0; i < faceNum; i++) +// { +// feaList[i].data = new float[dim_count]; +// feaList[i].size = 0; +// } - if (mat.Empty()) - { - return null; - } +// if (mat.Empty()) +// { +// return null; +// } - int sizeFeature = Marshal.SizeOf(typeof(BDFaceFeature)); - IntPtr ptFea = Marshal.AllocHGlobal(sizeFeature * faceNum); +// int sizeFeature = Marshal.SizeOf(typeof(BDFaceFeature)); +// IntPtr ptFea = Marshal.AllocHGlobal(sizeFeature * faceNum); - // 鏋勯�犺繑鍥炵殑浜鸿劯妗嗘暟鎹� - BDFaceBBox[] info = new BDFaceBBox[faceNum]; - int sizeBox = Marshal.SizeOf(typeof(BDFaceBBox)); - IntPtr ptBox = Marshal.AllocHGlobal(sizeBox * faceNum); - // 杩斿洖num涓虹壒寰佸�肩殑浜烘暟,type涓�0琛ㄧず鎻愬彇鐢熸椿鐓х殑鐗瑰緛鍊硷紝1琛ㄧず璇佷欢鐓х殑鐗瑰緛鍊硷紝2琛ㄧずnir鐨勭壒寰佸�� - int type = 0; - int num = face_feature(ptFea, ptBox, mat.CvPtr, type); - if (num <= 0) - { - return null; - } - Console.WriteLine("face num is:{0}", num); - // 璇风‘淇漟aceNum澶т簬num, faceNum涓篶#鏈熸湜鐨勬娴嬩汉鏁帮紝闇�瑕侀鍏堝垎閰嶅唴瀛橈紝鍚﹀垯鏃犳硶鑾峰彇 - if (num > faceNum) - { - num = faceNum; - } - for (int index = 0; index < num; index++) - { - IntPtr ptrF = new IntPtr(); - IntPtr ptrB = new IntPtr(); - if (8 == IntPtr.Size) - { - ptrF = (IntPtr)(ptFea.ToInt64() + sizeFeature * index); - ptrB = (IntPtr)(ptBox.ToInt64() + sizeBox * index); - } - else if (4 == IntPtr.Size) - { - ptrF = (IntPtr)(ptFea.ToInt32() + sizeFeature * index); - ptrB = (IntPtr)(ptBox.ToInt32() + sizeBox * index); - } - feaList[index] = (BDFaceFeature)Marshal.PtrToStructure(ptrF, typeof(BDFaceFeature)); - Console.WriteLine("feaList[index].size is:{0}", feaList[index].size); +// // 鏋勯�犺繑鍥炵殑浜鸿劯妗嗘暟鎹� +// BDFaceBBox[] info = new BDFaceBBox[faceNum]; +// int sizeBox = Marshal.SizeOf(typeof(BDFaceBBox)); +// IntPtr ptBox = Marshal.AllocHGlobal(sizeBox * faceNum); +// // 杩斿洖num涓虹壒寰佸�肩殑浜烘暟,type涓�0琛ㄧず鎻愬彇鐢熸椿鐓х殑鐗瑰緛鍊硷紝1琛ㄧず璇佷欢鐓х殑鐗瑰緛鍊硷紝2琛ㄧずnir鐨勭壒寰佸�� +// int type = 0; +// int num = face_feature(ptFea, ptBox, mat.CvPtr, type); +// if (num <= 0) +// { +// return null; +// } +// Console.WriteLine("face num is:{0}", num); +// // 璇风‘淇漟aceNum澶т簬num, faceNum涓篶#鏈熸湜鐨勬娴嬩汉鏁帮紝闇�瑕侀鍏堝垎閰嶅唴瀛橈紝鍚﹀垯鏃犳硶鑾峰彇 +// if (num > faceNum) +// { +// num = faceNum; +// } +// for (int index = 0; index < num; index++) +// { +// IntPtr ptrF = new IntPtr(); +// IntPtr ptrB = new IntPtr(); +// if (8 == IntPtr.Size) +// { +// ptrF = (IntPtr)(ptFea.ToInt64() + sizeFeature * index); +// ptrB = (IntPtr)(ptBox.ToInt64() + sizeBox * index); +// } +// else if (4 == IntPtr.Size) +// { +// ptrF = (IntPtr)(ptFea.ToInt32() + sizeFeature * index); +// ptrB = (IntPtr)(ptBox.ToInt32() + sizeBox * index); +// } +// feaList[index] = (BDFaceFeature)Marshal.PtrToStructure(ptrF, typeof(BDFaceFeature)); +// Console.WriteLine("feaList[index].size is:{0}", feaList[index].size); - for (int k = 0; k < feaList[index].size; k++) - { - Console.WriteLine("feature is {0}:", feaList[index].data[k]); - } +// for (int k = 0; k < feaList[index].size; k++) +// { +// Console.WriteLine("feature is {0}:", feaList[index].data[k]); +// } - info[index] = (BDFaceBBox)Marshal.PtrToStructure(ptrB, typeof(BDFaceBBox)); +// info[index] = (BDFaceBBox)Marshal.PtrToStructure(ptrB, typeof(BDFaceBBox)); - // 绱㈠紩鍊� - Console.WriteLine("detect score is:{0}", info[index].index); - // 缃俊搴� - Console.WriteLine("detect score is:{0}", info[index].score); - // 浜鸿劯瀹藉害 - Console.WriteLine("detect mWidth is:{0}", info[index].width); - // 涓績鐐筙,Y鍧愭爣 - Console.WriteLine("detect mCenter_x is:{0}", info[index].center_x); - Console.WriteLine("detect mCenter_y is:{0}", info[index].center_y); - } - // 缁樺埗浜鸿劯妗� - FaceDraw.draw_rects(ref mat, faceNum, info); +// // 绱㈠紩鍊� +// Console.WriteLine("detect score is:{0}", info[index].index); +// // 缃俊搴� +// Console.WriteLine("detect score is:{0}", info[index].score); +// // 浜鸿劯瀹藉害 +// Console.WriteLine("detect mWidth is:{0}", info[index].width); +// // 涓績鐐筙,Y鍧愭爣 +// Console.WriteLine("detect mCenter_x is:{0}", info[index].center_x); +// Console.WriteLine("detect mCenter_y is:{0}", info[index].center_y); +// } +// // 缁樺埗浜鸿劯妗� +// FaceDraw.draw_rects(ref mat, faceNum, info); - //mat.ImWrite("detect.jpg"); - mat.Release(); - return feaList; - } +// //mat.ImWrite("detect.jpg"); +// mat.Release(); +// return feaList; +// } - } -} +// } +//} -- Gitblit v1.9.3