1
z8018
2025-06-06 7876ac5d67b12e206a68db17c4034df52fa2f060
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
//using System;
//using System.Runtime.InteropServices;
//using System.IO;
//using OpenCvSharp;
 
//// 人脸比对(备注:人脸比对,实际上是人脸的特征值比对,提取出人脸特征值,用compare_feature方法比对)
//namespace FaceAI
//{  
//    // 人脸比较1:1、1:N、抽取人脸特征值、按特征值比较等
//    public class FaceCompare       
//    {
//        //  提取人脸特征值(传图片文件路径) 
//        /// <summary>
//        /// 提取人脸特征值,为512个浮点值,已加密
//        /// </summary>
//        /// <param name="file_name">图片信息,数据大小小于10M,传入图片文件路径</param>
//        /// <param name="length">通过引用返回特征值的长度,若为2048表示提取正确,其他值表示提取了错误的特征值</param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "get_face_feature", CharSet = CharSet.Ansi
//            , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr get_face_feature(string file_name, ref int length);
//        // 提取人脸特征值(传二进制图片buffer)
//        /// <summary>
//        /// 提取人脸特征值,为2048个byte (传入二进制图片buffer)
//        /// </summary>
//        /// <param name="buf"></param>
//        /// <param name="size"></param>
//        /// <param name="length"></param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "get_face_feature_by_buf", CharSet = CharSet.Ansi
//            , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr get_face_feature_by_buf(byte[] buf, int size, ref int length);
//        //// 获取人脸特征值(传入opencv视频帧及人脸信息,适应于多人脸)
//        ///// <summary>
//        ///// 获取人脸特征值(传入opencv视频帧及人脸信息,适应于多人脸)
//        ///// </summary>
//        ///// <param name="mat"></param>
//        ///// <param name="info"></param>
//        ///// <param name="feaptr"></param>
//        ///// <returns></returns>
//        //[DllImport("BaiduFaceApi.dll", EntryPoint = "get_face_feature_by_face", CharSet = CharSet.Ansi
//        //    , CallingConvention = CallingConvention.Cdecl)]
//        //public static extern int get_face_feature_by_face(IntPtr mat, ref TrackFaceInfo info, ref IntPtr feaptr);
//        // 人脸1:1比对(传图片文件路径)
//        /// <summary>
//        /// 人脸对比接口(传入图片文件路径)
//        /// </summary>
//        /// <param name="file_name1">需要对比的第一张图片,小于10M,传入图片文件路径</param>
//        /// <param name="file_name2">需要对比的第二张图片,小于10M,传入图片文件路径</param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "match", CharSet = CharSet.Ansi
//            , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr match(string file_name1, string file_name2);
//        // 人脸1:1比对(传二进制图片buffer)
//        /// <summary>
//        /// 人脸对比接口(传入二进制图片buffer)
//        /// </summary>
//        /// <param name="buf1">需要对比的第一张图片,小于10M</param>
//        /// <param name="size1">图片1的大小</param>
//        /// <param name="buf2">需要对比的第二张图片,小于10M</param>
//        /// <param name="size2">图片2的大小</param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "match_by_buf", CharSet = CharSet.Ansi
//            , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr match_by_buf(byte[] buf1, int size1, byte[] buf2, int size2);
//        // 人脸1:1比对(传opencv视频帧)
//        /// <summary>
//        /// 人脸1:1比对(传opencv视频帧)
//        /// </summary>
//        /// <param name="img1"></param>
//        /// <param name="img2"></param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "match_by_mat", CharSet = CharSet.Ansi
//            , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr match_by_mat(IntPtr img1, IntPtr img2);// byte[] buf1, int size1, byte[] buf2, int size2);
//        // 人脸1:1比对(传人脸特征值和二进制图片buffer)
//        /// <summary>
//        /// 人脸对比接口(传入二进制图片buffer)
//        /// </summary>
//        /// <param name="feature">文件特征</param>
//        /// <param name="fea_len"></param>
//        /// <param name="buf2"></param>
//        /// <param name="size2"></param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "match_by_feature", CharSet = CharSet.Ansi
//            , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr match_by_feature(byte[] feature, int fea_len, byte[] buf2, int size2);
//        // 特征值比对(传2个人脸的特征值)
//        /// <summary>
//        /// 特征值比对
//        /// </summary>
//        /// <param name="f1"></param>
//        /// <param name="f1_len"></param>
//        /// <param name="f2"></param>
//        /// <param name="f2_len"></param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "compare_feature", CharSet = CharSet.Ansi
//            , CallingConvention = CallingConvention.Cdecl)]
//        public static extern float compare_feature(byte[] f1, int f1_len, byte[] f2, int f2_len);
//        // 1:N人脸识别(传图片文件路径和库里的比对)
//        /// <summary>
//        /// 人脸识别,提供1:N查找 (传入图片文件路径)
//        /// </summary>
//        /// <param name="image">图片信息,数据大小小于10M,传入图片文件路径</param>
//        /// <param name="group_id_list">组id列表。默认至少填写一个group_id,从指定的group中进行查找。需要同时查询多个group,用逗号分隔,上限10个</param>
//        /// <param name="user_id">用户id,若指定了某个user,则只会与指定group下的这个user进行对比;若user_id传空字符串” ”,则会与此group下的所有user进行1:N识别</param>
//        /// <param name="user_top_num">识别后返回的用户top数,默认为1,最多返回50个结果</param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "identify", CharSet = CharSet.Ansi
//           , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr identify(string image, string group_id_list, string user_id, int user_top_num = 1);
//        // 1:N人脸识别(传图片二进制文件buffer和库里的比对)
//        /// <summary>
//        /// 人脸识别,提供1:N查找 (传入二进制图片buffer)
//        /// </summary>
//        /// <param name="buf">二进制图片信息,数据大小小于10M</param>
//        /// <param name="size">图片大小</param>
//        /// <param name="group_id_list">组id列表。默认至少填写一个group_id,从指定的group中进行查找。需要同时查询多个group,用逗号分隔,上限10个</param>
//        /// <param name="user_id">用户id,若指定了某个user,则只会与指定group下的这个user进行对比;若user_id传空字符串” ”,则会与此group下的所有user进行1:N识别</param>
//        /// <param name="user_top_num">识别后返回的用户top数,默认为1,最多返回50个结果</param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "identify_by_buf", CharSet = CharSet.Ansi
//           , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr identify_by_buf(byte[] buf, int size, string group_id_list,
//            string user_id, int user_top_num = 1);
//        // 1:N人脸识别(传人脸特征值和库里的比对)
//        /// <summary>
//        /// 1:N人脸识别(传人脸特征值和库里的比对)
//        /// </summary>
//        /// <param name="feature"></param>
//        /// <param name="fea_len"></param>
//        /// <param name="group_id_list">组id列表。默认至少填写一个group_id,从指定的group中进行查找。需要同时查询多个group,用逗号分隔,上限10个</param>
//        /// <param name="user_id">用户id,若指定了某个user,则只会与指定group下的这个user进行对比;若user_id传空字符串” ”,则会与此group下的所有user进行1:N识别</param>
//        /// <param name="user_top_num">识别后返回的用户top数,默认为1,最多返回50个结果</param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "identify_by_feature", CharSet = CharSet.Ansi
//          , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr identify_by_feature(byte[] feature, int fea_len, string group_id_list,
//            string user_id, int user_top_num = 1);
 
//        // 提前加载库里所有数据到内存中
//        /// <summary>
//        /// 提前加载库里所有数据到内存中
//        /// </summary>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "load_db_face", CharSet = CharSet.Ansi
//          , CallingConvention = CallingConvention.Cdecl)]
//        public static extern bool load_db_face();
 
//        // 1:N人脸识别(传人脸图片文件和内存已加载的整个库数据比对)
//        /// <summary>
//        /// 1:N人脸识别(传人脸图片文件和内存已加载的整个库数据比对)
//        /// </summary>
//        /// <param name="image"></param>
//        /// <param name="user_top_num"></param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "identify_with_all", CharSet = CharSet.Ansi
//          , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr identify_with_all(string image, int user_top_num = 1);
 
//        // 1:N人脸识别(传人脸图片文件和内存已加载的整个库数据比对)
//        /// <summary>
//        /// 
//        /// </summary>
//        /// <param name="image">图片的二进制文件</param>
//        /// <param name="size"></param>
//        /// <param name="user_top_num"></param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "identify_by_buf_with_all", CharSet = CharSet.Ansi
//          , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr identify_by_buf_with_all(byte[] image, int size, int user_top_num = 1);
 
//        // 1:N人脸识别(传人脸特征值和内存已加载的整个库数据比对)
//        /// <summary>
//        /// 1:N人脸识别(传人脸特征值和内存已加载的整个库数据比对)
//        /// </summary>
//        /// <param name="feature"></param>
//        /// <param name="fea_len"></param>
//        /// <param name="user_top_num"></param>
//        /// <returns></returns>
//        [DllImport("BaiduFaceApi.dll", EntryPoint = "identify_by_feature_with_all", CharSet = CharSet.Ansi
//          , CallingConvention = CallingConvention.Cdecl)]
//        public static extern IntPtr identify_by_feature_with_all(byte[] feature, int fea_len, int user_top_num = 1);
 
 
//        // 测试获取人脸特征值(2048个byte)
//        public void test_get_face_feature()
//        {
//            byte[] fea = new byte[2048];
//            string file_name = "G:\\Development\\Application\\testface\\img\\beckham\\2.jpg";
//            int len = 0;
//            IntPtr ptr = get_face_feature(file_name, ref len);
//            if (ptr == IntPtr.Zero)
//            {
//                Console.WriteLine("get face feature error");
//            }
//            else
//            {
//                if (len == 2048)
//                {
//                    Console.WriteLine("get face feature success");
//                    Marshal.Copy(ptr, fea, 0, 2048);
//                    // 可保存特征值2048个字节的fea到文件中
//                    // FileUtil.byte2file("G:\\Development\\Application\\testface\\img\\beckham\\fea1.txt",fea, 2048);
//                }
//                else
//                {
//                    Console.WriteLine("get face feature error");
//                }
//            }
//        }
//        /// <summary>
//        /// 获取人脸特征值(2048个byte)
//        /// </summary>
//        /// <param name="fileName"></param>
//        /// <returns></returns>
//        public string GetFaceFeature(string fileName)
//        {
//            try
//            {
//                byte[] fea = new byte[2048];
//                string file_name = fileName == null ? fileName : "G:\\Development\\Application\\testface\\img\\beckham\\2.jpg";
//                int len = 0;
//                IntPtr ptr = get_face_feature(file_name, ref len);
//                if (ptr == IntPtr.Zero)
//                {
//                    Console.WriteLine("get face feature error");
//                    return "error";
//                }
//                else
//                {
//                    if (len == 2048)
//                    {
//                        Console.WriteLine("get face feature success");
//                        Marshal.Copy(ptr, fea, 0, 2048);
//                        return fea.ToString();
//                        // 可保存特征值2048个字节的fea到文件中
//                        // FileUtil.byte2file("G:\\Development\\Application\\testface\\img\\beckham\\fea1.txt",fea, 2048);
//                    }
//                    else
//                    {
//                        Console.WriteLine("get face feature error");
//                        return "error";
//                    }
//                }
//            }
//            catch (Exception e)
//            {
//                throw e;
//            }
//        }
//        /// <summary>
//        /// 获取人脸特征值 2048Byte
//        /// </summary>
//        /// <param name="file_name">图片信息,数据大小小于10M,传入图片文件路径</param>
//        /// <param name="length">通过引用返回特征值的长度,若为2048表示提取正确,其他值表示提取了错误的特征值</param>
//        /// <returns></returns>
//        public string GetFaceFeature(string file_name, ref int length)
//        {
//            byte[] fea = new byte[2048];
//            int len = length == 0 ? 0 : length; //defalut=0
//            string result = "";
//            IntPtr ptr = get_face_feature(file_name, ref len);
//            if (ptr == IntPtr.Zero)
//            {
//                result = ("get face feature error");
//            }
//            else
//            {
//                if (len == 2048)
//                {
//                    result = ("get face feature success");
//                    Marshal.Copy(ptr, fea, 0, 2048);
//                    // 可保存特征值2048个字节的fea到文件中
//                    // FileUtil.byte2file("G:\\Development\\Application\\testface\\img\\beckham\\fea1.txt",fea, 2048);
//                }
//                else
//                {
//                    result = ("get face feature error");
//                }
//            }
//            return result;
//        }
 
 
//        //// 测试获取人脸特征值(2048个byte)
//        //public void test_get_face_feature_by_buf()
//        //{
//        //    byte[] fea = new byte[2048];
//        //    System.Drawing.Image img = System.Drawing.Image.FromFile("G:\\Development\\Application\\testface\\img\\beckham\\2.jpg");
//        //    byte[] img_bytes = ImageUtil.img2byte(img);
//        //    int len = 0;
//        //    IntPtr ptr = get_face_feature_by_buf(img_bytes, img_bytes.Length, ref len);
//        //    if (ptr == IntPtr.Zero)
//        //    {
//        //        Console.WriteLine("get face feature error");
//        //    }
//        //    else
//        //    {
//        //        if (len == 2048)
//        //        {
//        //            Console.WriteLine("get face feature success");
//        //            Marshal.Copy(ptr, fea, 0, 2048);
//        //            // 可保存特征值2048个字节的fea到文件中
//        //            //  FileUtil.byte2file("G:\\Development\\Application\\testface\\img\\beckham\\fea2.txt",fea, 2048);
//        //        }
//        //        else
//        //        {
//        //            Console.WriteLine("get face feature error");
//        //        }
//        //    }
//        //}
 
//        ///// <summary>
//        ///// 获取人脸特征值 2048byte
//        ///// </summary>
//        ///// <param name="filePath"></param>
//        ///// <returns></returns>
//        //public string GetFaceFeatureByBuffer(string filePath)
//        //{
//        //    byte[] fea = new byte[2048];
//        //    string result = "";
//        //    System.Drawing.Image img = System.Drawing.Image.FromFile(filePath);
//        //    byte[] img_bytes = ImageUtil.img2byte(img);
//        //    int len = 0;
//        //    IntPtr ptr = get_face_feature_by_buf(img_bytes, img_bytes.Length, ref len);
//        //    if (ptr == IntPtr.Zero)
//        //    {
//        //        result = ("get face feature error");
//        //    }
//        //    else
//        //    {
//        //        if (len == 2048)
//        //        {
//        //            result = ("get face feature success");
//        //            Marshal.Copy(ptr, fea, 0, 2048);
//        //            // 可保存特征值2048个字节的fea到文件中
//        //            //  FileUtil.byte2file("G:\\Development\\Application\\testface\\img\\beckham\\fea2.txt",fea, 2048);
//        //        }
//        //        else
//        //        {
//        //            result = ("get face feature error");
//        //        }
//        //    }
//        //    return result;
//        //}
 
 
//        // 测试1:1比较,传入图片文件路径
//        public void test_match()
//        {
//            string file1 = "G:\\Development\\Application\\testface\\img\\beckham\\1.jpg";
//            string file2 = "G:\\Development\\Application\\testface\\img\\beckham\\9.jpg";
//            IntPtr ptr = match(file1, file2);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("match res is:" + buf);
//        }
//        /// <summary>
//        /// 1:1比较 传入图片文件路径
//        /// </summary>
//        /// <param name="file1"></param>
//        /// <param name="file2"></param>
//        /// <returns></returns>
//        public string FaceMatch(string file1, string file2)
//        {
//            IntPtr ptr = match(file1, file2);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("match res is:" + buf);
//            return buf;
//        }
//        // 测试1:1比较,传入图片文件二进制buffer
//        //public void test_match_by_buf()
//        //{
//        //    System.Drawing.Image img1 = System.Drawing.Image.FromFile("d:\\444.bmp");
//        //    byte[] img_bytes1 = ImageUtil.img2byte(img1);
 
//        //    System.Drawing.Image img2 = System.Drawing.Image.FromFile("d:\\555.png");
//        //    byte[] img_bytes2 = ImageUtil.img2byte(img2);
//        //    Console.WriteLine("IntPtr ptr = match_by_buf");
//        //    IntPtr ptr = match_by_buf(img_bytes1, img_bytes1.Length, img_bytes2, img_bytes2.Length);
//        //    string buf = Marshal.PtrToStringAnsi(ptr);
//        //    Console.WriteLine("match_by_buf res is:" + buf);
//        //}
//        /// <summary>
//        /// 1:1比较 传图片二进制Buffer
//        /// </summary>
//        /// <param name="file1"></param>
//        /// <param name="file2"></param>
//        /// <returns></returns>
//        public string FaceMatchByBuffer(byte[] file1, byte[] file2)
//        {
//            // System.Drawing.Image img1 = System.Drawing.Image.FromFile(file1);
//            byte[] img_bytes1 = file1; // ImageUtil.img2byte(img1);
 
//            // System.Drawing.Image img2 = System.Drawing.Image.FromFile(file2);
//            byte[] img_bytes2 = file2; // ImageUtil.img2byte(img2);
//            Console.WriteLine("IntPtr ptr = match_by_buf");
//            IntPtr ptr = match_by_buf(img_bytes1, img_bytes1.Length, img_bytes2, img_bytes2.Length);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            return ("match_by_buf res is:" + buf);
//        }
//        // 测试1:1比较,传入opencv视频帧
//        public void test_match_by_mat()
//        {
//            Mat img1 = Cv2.ImRead("d:\\444.bmp");
//            Mat img2 = Cv2.ImRead("d:\\555.png");
//            IntPtr ptr = match_by_mat(img1.CvPtr, img2.CvPtr);// img_bytes1, img_bytes1.Length, img_bytes2, img_bytes2.Length);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("match_by_buf res is:" + buf);
//        }
//        /// <summary>
//        /// 1:1比较,传入opencv视频帧
//        /// </summary>
//        /// <param name="file1"></param>
//        /// <param name="file2"></param>
//        /// <returns></returns>
//        public string FaceMatchByMat(string file1, string file2)
//        {
//            Mat img1 = Cv2.ImRead(file1);
//            Mat img2 = Cv2.ImRead(file2);
//            IntPtr ptr = match_by_mat(img1.CvPtr, img2.CvPtr);// img_bytes1, img_bytes1.Length, img_bytes2, img_bytes2.Length);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            return ("match_by_buf res is:" + buf);
 
//        }
//        // 测试根据特征值和图片二进制buf比较
//        //public void test_match_by_feature()
//        //{
//        //    // 获取特征值2048个字节
//        //    byte[] fea = new byte[2048];
//        //    string file_name = "G:\\Development\\Application\\testface\\img\\beckham\\2.jpg";
//        //    int len = 0;
//        //    IntPtr ptr = get_face_feature(file_name, ref len);
//        //    if (len != 2048)
//        //    {
//        //        Console.WriteLine("get face feature error!");
//        //        return;
//        //    }
//        //    Marshal.Copy(ptr, fea, 0, 2048);
//        //    // 获取图片二进制buffer
//        //    System.Drawing.Image img2 = System.Drawing.Image.FromFile("G:\\Development\\Application\\testface\\img\\beckham\\8.jpg");
//        //    byte[] img_bytes2 = ImageUtil.img2byte(img2);
 
//        //    IntPtr ptr_res = match_by_feature(fea, fea.Length, img_bytes2, img_bytes2.Length);
//        //    string buf = Marshal.PtrToStringAnsi(ptr_res);
//        //    Console.WriteLine("match_by_feature res is:" + buf);
 
//        //}
//        /// <summary>
//        /// 根据特征值和图片二进制buf比较
//        /// </summary>
//        /// <param name="file_name">需要对比的特征值</param>
//        /// <param name="file_buffer">需要对比的第二张图片,小于10M</param>
//        /// <returns></returns>
//        public string FaceMatchByFeature(byte[] file_name, byte[] file_buffer)
//        {
//            // 获取特征值2048个字节
//            byte[] fea = file_name; // new byte[2048];
//            //int len = 0;
//            //IntPtr ptr = get_face_feature(file_name, ref len);
//            //if (len != 2048)
//            //{
//            //    return ("get face feature error!");
//            //}
//            //Marshal.Copy(ptr, fea, 0, 2048);
//            //// 获取图片二进制buffer
//            //System.Drawing.Image img2 = System.Drawing.Image.FromFile(file_buffer);
//            byte[] img_bytes2 = file_buffer; // ImageUtil.img2byte(img2);
 
//            IntPtr ptr_res = match_by_feature(fea, fea.Length, img_bytes2, img_bytes2.Length);
//            string buf = Marshal.PtrToStringAnsi(ptr_res);
//            Console.WriteLine("match_by_feature res is:" + buf);
//            return buf;
 
//        }
 
//        // 测试1:N比较,传入图片文件路径
//        public /*void*/string test_identify(string str, string usr_grp, string usr_id)
//        {
//            string file1 = str;//"G:\\Development\\Application\\testface\\img\\beckham\\6.jpg";
//            string user_group = usr_grp;//"test_group";
//            string user_id = usr_id;//"test_user";
//            IntPtr ptr = identify(file1, user_group, user_id);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("identify res is:" + buf);
//            return buf;
//        }
//        /// <summary>
//        /// 1:N比较,传入图片文件路径
//        /// </summary>
//        /// <param name="file">图片信息,数据大小小于10M,传入图片文件路径</param>
//        /// <param name="user_group">组id列表。默认至少填写一个group_id,从指定的group中进行查找。需要同时查询多个group,用逗号分隔,上限10个</param>
//        /// <param name="user_id">用户id,若指定了某个user,则只会与指定group下的这个user进行对比;若user_id传空字符串” ”,则会与此group下的所有user进行1:N识别</param>
//        /// <returns></returns>
//        public static string FaceIdentify(string file, string user_group, string user_id)
//        {
//            string file1 = file;
//            IntPtr ptr = identify(file1, user_group, user_id);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("identify res is:" + buf);
//            return buf;
//        }
 
//        // 测试1:N比较,传入图片文件二进制buffer
//        //public void test_identify_by_buf(string str, string usr_grp, string usr_id)
//        //{
//        //    System.Drawing.Image img = System.Drawing.Image.FromFile(str);//"G:\\Development\\Application\\testface\\img\\beckham\\2.jpg");
//        //    byte[] img_bytes = ImageUtil.img2byte(img);
 
//        //    string user_group = usr_grp;//"test_group";
//        //    string user_id = usr_id;// "test_user";
//        //    IntPtr ptr = identify_by_buf(img_bytes, img_bytes.Length, user_group, user_id);
//        //    string buf = Marshal.PtrToStringAnsi(ptr);
//        //    Console.WriteLine("identify_by_buf res is:" + buf);
//        //}
//        /// <summary>
//        /// 1:N比较,传入图片文件二进制buffer
//        /// </summary>
//        /// <param name="str">二进制图片信息,数据大小小于10M</param>
//        /// <param name="usr_grp">组id列表。默认至少填写一个group_id,从指定的group中进行查找。需要同时查询多个group,用逗号分隔,上限10个</param>
//        /// <param name="usr_id">用户id,若指定了某个user,则只会与指定group下的这个user进行对比;若user_id传空字符串” ”,则会与此group下的所有user进行1:N识别</param>
//        /// <returns></returns>
//        public string FaceIdentifyByBuffer(byte[] str, string usr_grp, string usr_id)
//        {
//            // System.Drawing.Image img = System.Drawing.Image.FromFile(str);
//            byte[] img_bytes = str; // ImageUtil.img2byte(img);
 
//            string user_group = usr_grp;//"test_group";
//            string user_id = usr_id;// "test_user";
//            IntPtr ptr = identify_by_buf(img_bytes, img_bytes.Length, user_group, user_id);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("identify_by_buf res is:" + buf);
//            return buf;
//        }
 
//        // 测试1:N比较,传入提取的人脸特征值
//        public void test_identify_by_feature()
//        {
//            // 获取特征值2048个字节
//            byte[] fea = new byte[2048];
//            string file_name = "G:\\Development\\Application\\testface\\img\\beckham\\2.jpg";
//            int len = 0;
//            IntPtr ptr = get_face_feature(file_name, ref len);
//            if (len != 2048)
//            {
//                Console.WriteLine("get face feature error!");
//                return;
//            }
//            Marshal.Copy(ptr, fea, 0, 2048);
 
//            string user_group = "test_group";
//            string user_id = "test_user";
//            IntPtr ptr_res = identify_by_feature(fea, fea.Length, user_group, user_id);
//            string buf = Marshal.PtrToStringAnsi(ptr_res);
//            Console.WriteLine("identify_by_feature res is:" + buf);
//        }
//        /// <summary>
//        /// 1:N比较,传入提取的人脸特征值
//        /// </summary>
//        /// <param name="file_name">传入图片特征</param>
//        /// <param name="userGroup">组id列表。默认至少填写一个group_id,从指定的group中进行查找。需要同时查询多个group,用逗号分隔,上限10个</param>
//        /// <param name="userId">用户id,若指定了某个user,则只会与指定group下的这个user进行对比;若user_id传空字符串” ”,则会与此group下的所有user进行1:N识别</param>
//        /// 
//        public static string FaceIdentifyByFeature(string file_name, string userGroup, string userId)
//        {
//            // 获取特征值2048个字节
//            byte[] fea = new byte[2048];
//            int len = 0;
//            IntPtr ptr = get_face_feature(file_name, ref len);
//            if (len != 2048)
//            {
//                return ("get face feature error!");
//            }
//            Marshal.Copy(ptr, fea, 0, 2048);
 
//            string user_group = userGroup == null ? "test_group" : userGroup;
//            string user_id = userId == null ? "test_user" : userId;
//            IntPtr ptr_res = identify_by_feature(fea, fea.Length, user_group, user_id);
//            string buf = Marshal.PtrToStringAnsi(ptr_res);
//            Console.WriteLine("identify_by_feature res is:" + buf);
//            return buf;
//        }
 
//        // 通过特征值比对(1:1)
//        public void test_compare_feature()
//        {
//            // 获取特征值1   共2048个字节
//            byte[] fea1 = new byte[2048];
//            string file_name1 = "G:\\Development\\Application\\testface\\img\\beckham\\2.jpg";
//            int len1 = 0;
//            IntPtr ptr1 = get_face_feature(file_name1, ref len1);
//            if (len1 != 2048)
//            {
//                Console.WriteLine("get face feature error!");
//                return;
//            }
//            Marshal.Copy(ptr1, fea1, 0, 2048);
 
//            // 获取特征值2   共2048个字节
//            byte[] fea2 = new byte[2048];
//            string file_name2 = "G:\\Development\\Application\\testface\\img\\beckham\\8.jpg";
//            int len2 = 0;
//            IntPtr ptr2 = get_face_feature(file_name2, ref len2);
//            if (len2 != 2048)
//            {
//                Console.WriteLine("get face feature error!");
//                return;
//            }
//            Marshal.Copy(ptr2, fea2, 0, 2048);
//            // 比对
//            float score = compare_feature(fea1, len1, fea2, len2);
//            Console.WriteLine("compare_feature score is:" + score);
//        }
//        /// <summary>
//        /// 通过特征值比对(1:1) 对人脸特征值进行比较,可返回人脸特征相似分值(百分制)
//        /// </summary>
//        /// <param name="file_name1">2048个byte数组的特征值(传图片路径)</param>
//        /// <param name="file_name2">2048个byte数组的特征值(传图片路径)</param>
//        /// <returns></returns>
//        public static string FaceCompareFeature(string file_name1, string file_name2)
//        {
//            string mes = "入:";
//            try
//            {
 
//                // 获取特征值1   共2048个字节
//                byte[] fea1 = new byte[2048];
//                int len1 = 0;
//                IntPtr ptr1 = get_face_feature(file_name1, ref len1);
//                if (len1 != 2048)
//                {
//                    return mes += "get face feature error!";
//                }
//                Marshal.Copy(ptr1, fea1, 0, 2048);
 
//                // 获取特征值2   共2048个字节
//                byte[] fea2 = new byte[2048];
//                int len2 = 0;
//                IntPtr ptr2 = get_face_feature(file_name2, ref len2);
//                if (len2 != 2048)
//                {
//                    return mes += "get face feature error!";
//                }
//                Marshal.Copy(ptr2, fea2, 0, 2048);
//                // 比对
//                // len1 特征值1的长度
//                float score = compare_feature(fea1, len1, fea2, len2);
//                Console.WriteLine("compare_feature score is:" + score);
//                return mes += score.ToString();
 
//            }
//            catch (Exception ex)
//            {
//                return mes += ex;
//            }
//        }
//        /// <summary>
//        /// 通过特征值比对(1:1) 对人脸特征值进行比较,可返回人脸特征相似分值(百分制)
//        /// </summary>
//        /// <param name="face1">2048个byte数组的特征值</param>
//        /// <param name="face2">2048个byte数组的特征值</param>
//        /// <returns></returns>
//        public string FaceCompareFeatureByBuffer(byte[] face1, byte[] face2)
//        {
//            if (face1.Length == 2048 && face2.Length == 2048)
//            {
//                // 获取特征值1   共2048个字节
//                byte[] fea1 = new byte[2048];
//                fea1 = face1;
//                int len1 = 0;
//                // 获取特征值1   共2048个字节
//                byte[] fea2 = new byte[2048];
//                fea2 = face2;
//                int len2 = 0;
//                // 比对
//                // len1 特征值1的长度
//                float score = compare_feature(fea1, len1, fea2, len2);
//                Console.WriteLine("compare_feature score is:" + score);
//                return score.ToString();
//            }
//            else
//            {
//                return "byte should be 2048";
//            }
//        }
 
//        // 测试1:N比较,传入提取的人脸特征值和已加载的内存中整个库比较
//        public void test_identify_by_feature_with_all()
//        {
//            // 加载整个数据库到内存中
//            load_db_face();
//            // 获取特征值2048个字节
//            byte[] fea = new byte[2048];
//            string file_name = "G:\\Development\\Application\\testface\\img\\beckham\\2.jpg";
//            int len = 0;
//            IntPtr ptr = get_face_feature(file_name, ref len);
//            if (len != 2048)
//            {
//                Console.WriteLine("get face feature error!");
//                return;
//            }
//            Marshal.Copy(ptr, fea, 0, 2048);
//            IntPtr ptr_res = identify_by_feature_with_all(fea, fea.Length);
//            string buf = Marshal.PtrToStringAnsi(ptr_res);
//            Console.WriteLine("identify_by_feature_with_all res is:" + buf);
//        }
//        /// <summary>
//        /// 1:N比较,传入提取的人脸特征值和已加载的内存中整个库比较
//        /// </summary>
//        /// <param name="file_name">传入人脸文件特征值</param>
//        /// <returns></returns>
//        public string FaceIdentifyByFeatureWithAll(byte[] file_name)
//        {
//            // 加载整个数据库到内存中
//            load_db_face();
//            // 获取特征值2048个字节
//            byte[] fea = new byte[2048];
//            fea = file_name;
//            int len = 0;
//            //IntPtr ptr = get_face_feature(file_name, ref len);
//            //if (len != 2048)
//            //{
//            //    Console.WriteLine("get face feature error!");
//            //    return "error";
//            //}
//            // Marshal.Copy(ptr, fea, 0, 2048);
//            IntPtr ptr_res = identify_by_feature_with_all(fea, fea.Length);
//            string buf = Marshal.PtrToStringAnsi(ptr_res);
//            Console.WriteLine("identify_by_feature_with_all res is:" + buf);
//            return buf;
//        }
 
//        // 测试1:N比较,传入图片文件路径和已加载的内存中整个库比较
//        public void test_identify_with_all()
//        {
//            // 加载整个数据库到内存中
//            load_db_face();
//            // 1:N
//            string file1 = "G:\\Development\\Application\\testface\\img\\beckham\\3.jpg";
//            IntPtr ptr = identify_with_all(file1);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("identify_with_all res is:" + buf);
//        }
//        /// <summary>
//        /// 1:N比较,传入图片文件路径和已加载的内存中整个库比较
//        /// </summary>
//        /// <param name="file1">传入图片路径</param>
//        /// <returns></returns>
//        public string FaceIndentifyWithAll(string file1)
//        {
//            // 加载整个数据库到内存中
//            load_db_face();
//            // 1:N
//            IntPtr ptr = identify_with_all(file1);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("identify_with_all res is:" + buf);
//            return buf;
//        }
       
 
//        /// <summary>
//        /// 1:N比较,传入图片文件二进制buffer和已加载的内存中整个库比较
//        /// </summary>
//        /// <param name="file_name"></param>
//        /// <returns></returns>
//        public string FaceIdentifyByBufferWithAll(byte[] file_name)
//        {
//            // 加载整个数据库到内存中
//            load_db_face();
//            // 1:N
//            // System.Drawing.Image img = System.Drawing.Image.FromFile(file_name);
//            byte[] img_bytes = file_name;// ImageUtil.img2byte(img);
 
//            IntPtr ptr = identify_by_buf_with_all(img_bytes, img_bytes.Length);
//            string buf = Marshal.PtrToStringAnsi(ptr);
//            Console.WriteLine("identify_by_buf_with_all res is:" + buf);
//            return buf;
//        }
 
//    }
//}