|
|
@ -1,8 +1,11 @@ |
|
|
|
using AKSWebBrowser.Commen; |
|
|
|
using AKSWebBrowser.Commen; |
|
|
|
|
|
|
|
using CPF.Linux; |
|
|
|
|
|
|
|
using CPF.Mac.CoreGraphics; |
|
|
|
using CPF.Windows; |
|
|
|
using CPF.Windows; |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Globalization; |
|
|
|
using System.Globalization; |
|
|
|
|
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
@ -12,6 +15,7 @@ namespace AksWebBrowser.Devices |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class LhtCF |
|
|
|
public class LhtCF |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
public static string face = string.Empty; |
|
|
|
public LhtCF() { } |
|
|
|
public LhtCF() { } |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -19,40 +23,49 @@ namespace AksWebBrowser.Devices |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="code"></param> |
|
|
|
/// <param name="code"></param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
public static string LhtCFFace(string code,string face) |
|
|
|
public static string LhtCFFace(string code, string _face) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string result = string.Empty; |
|
|
|
int status = -1; |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
int status = libLhtCFs.CF_Init(); |
|
|
|
face = _face; |
|
|
|
// Log.Info("初始化函数" + status); |
|
|
|
status = libLhtCFs.CF_Init(); |
|
|
|
if (status == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
status = libLhtCFs.CF_GetCameraStatus(0); |
|
|
|
|
|
|
|
// Log.Info("获取摄像头状态" + status); |
|
|
|
|
|
|
|
if (status == 0) |
|
|
|
if (status == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
status = libLhtCFs.CF_OpenCamera(); |
|
|
|
status = libLhtCFs.CF_OpenCamera(); |
|
|
|
// Log.Info("打开摄像头" + status); |
|
|
|
|
|
|
|
if (status == 0) |
|
|
|
if (status == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
status = libLhtCFs.CF_CreatWindow(0, 0, 300, 800, 600, 500); |
|
|
|
status = libLhtCFs.CF_CreatWindow(0, 0, 300, 800, 600, 500); |
|
|
|
// Log.Info("创建视频预览窗口" + status); |
|
|
|
|
|
|
|
if (status == 0) |
|
|
|
if (status == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
status = libLhtCFs.CF_StartLiveDetectEx(10000); |
|
|
|
status = libLhtCFs.CF_StartLiveDetectEx(10000); |
|
|
|
// Log.Info("活体检测超时时间:" + status); |
|
|
|
|
|
|
|
if (status == 0) |
|
|
|
if (status == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
|
|
//status = libLhtCFs.SetCamADataCallbackEx(GetMjpegStream); |
|
|
|
var tmpFile = "/tmp/" + time + ".jpg"; |
|
|
|
//Log.Info("设置回调:" + status); |
|
|
|
byte[] faceA = Convert.FromBase64String(face); |
|
|
|
|
|
|
|
byte[] faceB = Encoding.UTF8.GetBytes(tmpFile); |
|
|
|
|
|
|
|
status = libLhtCFs.CF_FaceCompare(faceA, faceB, 60); |
|
|
|
|
|
|
|
// Log.Info("人脸比对:" + status); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//停止活体检测 |
|
|
|
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
|
|
Task.Run(() => { libLhtCFs.CF_StopLiveDetect(); }); |
|
|
|
string dirpath = System.IO.Directory.GetCurrentDirectory(); |
|
|
|
|
|
|
|
string[] array = dirpath.Split("/"); |
|
|
|
|
|
|
|
var groupCount = array.GroupBy(x => x).Select(group => new { Element = group.Key, Count = group.Count() }).Where(x => x.Count > 0); |
|
|
|
|
|
|
|
if (groupCount.Count() == 1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
dirpath = dirpath + "/aks"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (groupCount.Count() == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
dirpath = dirpath + "/aks/aks"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dirpath = dirpath + @"/wwwroot/Face"; |
|
|
|
|
|
|
|
if (!Directory.Exists(dirpath)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Directory.CreateDirectory(dirpath); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Log.Info(dirpath); |
|
|
|
|
|
|
|
var tempFile = dirpath + "/" + time + ".jpg"; |
|
|
|
|
|
|
|
Log.Info("人脸路径:" + tempFile); |
|
|
|
|
|
|
|
status = libLhtCFs.CF_GetImage(0, Encoding.Default.GetBytes(tempFile)); |
|
|
|
|
|
|
|
Log.Info("获取人脸:" + status); |
|
|
|
} |
|
|
|
} |
|
|
|
//关闭视频预览窗口 |
|
|
|
//关闭视频预览窗口 |
|
|
|
Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); |
|
|
|
Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); |
|
|
@ -62,13 +75,15 @@ namespace AksWebBrowser.Devices |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception ex) |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//Log.Error("双目摄像头采集人脸异常:" + ex.Message); |
|
|
|
//关闭视频预览窗口 |
|
|
|
|
|
|
|
Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); |
|
|
|
|
|
|
|
//关闭摄像头 |
|
|
|
|
|
|
|
Task.Run(() => { libLhtCFs.CF_CloseCamera(); }); |
|
|
|
|
|
|
|
Log.Info("双目摄像头采集人脸异常:" + ex.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
return ""; |
|
|
|
return status.ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -80,11 +95,11 @@ namespace AksWebBrowser.Devices |
|
|
|
|
|
|
|
|
|
|
|
//RGB数据回调函数定义 |
|
|
|
//RGB数据回调函数定义 |
|
|
|
[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] |
|
|
|
[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] |
|
|
|
public delegate void GetVideoStream([MarshalAs(UnmanagedType.LPArray)] byte[] rgbData, int width, int height); |
|
|
|
public delegate void GetVideoStream(byte[] rgbData, int width, int height); |
|
|
|
|
|
|
|
|
|
|
|
//mjpeg数据回调函数定义 |
|
|
|
//mjpeg数据回调函数定义 |
|
|
|
[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] |
|
|
|
[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] |
|
|
|
public delegate void GetMjpegStream([MarshalAs(UnmanagedType.LPArray)] byte[] mjpegData, int dataLen); |
|
|
|
public delegate void GetMjpegStream(byte[] mjpegData, int dataLen); |
|
|
|
|
|
|
|
|
|
|
|
//初始化 |
|
|
|
//初始化 |
|
|
|
[DllImport("libLhtCF", EntryPoint = "CF_Init", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
|
|
[DllImport("libLhtCF", EntryPoint = "CF_Init", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
|
@ -143,12 +158,12 @@ namespace AksWebBrowser.Devices |
|
|
|
public static extern int CF_StopLiveDetect(); |
|
|
|
public static extern int CF_StopLiveDetect(); |
|
|
|
|
|
|
|
|
|
|
|
//获取采集图像 |
|
|
|
//获取采集图像 |
|
|
|
[DllImport("libLhtCF", EntryPoint = "CF_GetImage", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
|
|
[DllImport("libLhtCF", CallingConvention = CallingConvention.Cdecl)] |
|
|
|
public static extern int CF_GetImage(int nImageType, [MarshalAs(UnmanagedType.LPArray)] byte[] FilePath); |
|
|
|
public extern static int CF_GetImage(int nImageType, byte[] FilePath); |
|
|
|
|
|
|
|
|
|
|
|
//人脸比对 |
|
|
|
//人脸比对 |
|
|
|
[DllImport("libLhtCF", EntryPoint = "CF_GetImage", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
|
|
[DllImport("LhtCF.dll", CallingConvention = CallingConvention.Cdecl)] |
|
|
|
public static extern int CF_FaceCompare(byte[] picPathA, byte[] picPathB, int score); |
|
|
|
public extern static int CF_FaceCompare(byte[] picPathA, byte[] picPathB, ref int score); |
|
|
|
|
|
|
|
|
|
|
|
//创建视频预览窗口 |
|
|
|
//创建视频预览窗口 |
|
|
|
[DllImport("libLhtCF", EntryPoint = "CF_CreatWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
|
|
[DllImport("libLhtCF", EntryPoint = "CF_CreatWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
|
|