You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
8.6 KiB
161 lines
8.6 KiB
using AKSWebBrowser.Commen; |
|
using CPF.Windows; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Globalization; |
|
using System.Linq; |
|
using System.Runtime.InteropServices; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
|
|
namespace AksWebBrowser.Devices |
|
{ |
|
public class LhtCF |
|
{ |
|
public LhtCF() { } |
|
|
|
/// <summary> |
|
/// 人脸比对 |
|
/// </summary> |
|
/// <param name="code"></param> |
|
/// <returns></returns> |
|
public static string LhtCFFace(string code,string face) |
|
{ |
|
string result = string.Empty; |
|
try |
|
{ |
|
int status = libLhtCFs.CF_Init(); |
|
Log.Info("初始化函数" + status); |
|
if (status == 0) |
|
{ |
|
status = libLhtCFs.CF_GetCameraStatus(0); |
|
Log.Info("获取摄像头状态" + status); |
|
if (status == 0) |
|
{ |
|
status = libLhtCFs.CF_OpenCamera(); |
|
Log.Info("打开摄像头" + status); |
|
if (status == 0) |
|
{ |
|
status = libLhtCFs.CF_CreatWindow(0, 0, 300, 800, 600, 500); |
|
Log.Info("创建视频预览窗口" + status); |
|
if (status == 0) |
|
{ |
|
status = libLhtCFs.CF_StartLiveDetectEx(10000); |
|
Log.Info("活体检测超时时间:" + status); |
|
if (status == 0) |
|
{ |
|
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); |
|
var tmpFile = "/tmp/" + time + ".jpg"; |
|
byte[] faceA = Convert.FromBase64String(face); |
|
byte[] faceB = Encoding.UTF8.GetBytes(tmpFile); |
|
status = libLhtCFs.CF_FaceCompare(faceA, faceB, 60); |
|
Log.Info("人脸比对:" + status); |
|
|
|
//停止活体检测 |
|
Task.Run(() => { libLhtCFs.CF_StopLiveDetect(); }); |
|
} |
|
//关闭视频预览窗口 |
|
Task.Run(() => { libLhtCFs.CF_CloseWindow(0); }); |
|
} |
|
//关闭摄像头 |
|
Task.Run(() => { libLhtCFs.CF_CloseCamera(); }); |
|
} |
|
} |
|
} |
|
|
|
} |
|
catch (Exception ex) |
|
{ |
|
Log.Error("双目摄像头采集人脸异常:" + ex.Message); |
|
} |
|
return ""; |
|
} |
|
} |
|
|
|
class libLhtCFs |
|
{ |
|
// 检测回调函数定义 |
|
[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] |
|
public delegate void DetectCallBack(int nEventId, IntPtr lpContext); |
|
|
|
//RGB数据回调函数定义 |
|
[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] |
|
public delegate void GetVideoStream([MarshalAs(UnmanagedType.LPArray)] byte[] rgbData, int width, int height); |
|
|
|
//mjpeg数据回调函数定义 |
|
[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)] |
|
public delegate void GetMjpegStream([MarshalAs(UnmanagedType.LPArray)] byte[] mjpegData, int dataLen); |
|
|
|
//初始化 |
|
[DllImport("libLhtCF", EntryPoint = "CF_Init", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_Init(); |
|
|
|
//反初始化函数 |
|
[DllImport("libLhtCF", EntryPoint = "CF_Uninit", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_Uninit(); |
|
|
|
//反初始化函数 |
|
[DllImport("libLhtCF", EntryPoint = "CF_GetCameraStatus", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_GetCameraStatus(int status); |
|
|
|
//设置检测回调函数 |
|
[DllImport("libLhtCF", EntryPoint = "CF_GetCameraStatus", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_SetDetectCallBack(DetectCallBack pCB, IntPtr lpContext); |
|
|
|
//设置彩色摄像头视频流回调 |
|
[DllImport("libLhtCF", EntryPoint = "SetCamADataCallback", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int SetCamADataCallback(GetVideoStream cb); |
|
|
|
//设置红外摄像头视频流回调 |
|
[DllImport("libLhtCF", EntryPoint = "SetCamBDataCallback", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int SetCamBDataCallback(GetVideoStream cb); |
|
|
|
//设置彩色摄像头mjpeg数据流回调 |
|
[DllImport("libLhtCF", EntryPoint = "SetCamADataCallbackEx", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int SetCamADataCallbackEx(GetMjpegStream cb); |
|
|
|
//设置红外摄像头mjpeg数据流回调 |
|
[DllImport("libLhtCF", EntryPoint = "SetCamBDataCallbackEx", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int SetCamBDataCallbackEx(GetMjpegStream cb); |
|
|
|
//设置分辨率 |
|
[DllImport("libLhtCF", EntryPoint = "CF_SetResolution", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_SetResolution(int width, int height); |
|
|
|
//打开摄像头 |
|
[DllImport("libLhtCF", EntryPoint = "CF_OpenCamera", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_OpenCamera(); |
|
|
|
//关闭摄像头 |
|
[DllImport("libLhtCF", EntryPoint = "CF_CloseCamera", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_CloseCamera(); |
|
|
|
//开始活体检测 |
|
[DllImport("libLhtCF", EntryPoint = "CF_StartLiveDetect", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_StartLiveDetect(); |
|
|
|
//活体检测超时时间 |
|
[DllImport("libLhtCF", EntryPoint = "CF_StartLiveDetectEx", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_StartLiveDetectEx(int timeout); |
|
|
|
//停止活体检测 |
|
[DllImport("libLhtCF", EntryPoint = "CF_StopLiveDetect", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_StopLiveDetect(); |
|
|
|
//获取采集图像 |
|
[DllImport("libLhtCF", EntryPoint = "CF_GetImage", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_GetImage(int nImageType, [MarshalAs(UnmanagedType.LPArray)] byte[] FilePath); |
|
|
|
//人脸比对 |
|
[DllImport("libLhtCF", EntryPoint = "CF_GetImage", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_FaceCompare(byte[] picPathA, byte[] picPathB, int score); |
|
|
|
//创建视频预览窗口 |
|
[DllImport("libLhtCF", EntryPoint = "CF_CreatWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_CreatWindow(int nWndType, long hWnd, int iX, int iY, int iWidth, int iHeight); |
|
|
|
//关闭视频预览窗口 |
|
[DllImport("libLhtCF", EntryPoint = "CF_CloseWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)] |
|
public static extern int CF_CloseWindow(int nWndType); |
|
} |
|
}
|
|
|