Browse Source

人脸比对

master
胡超1 1 year ago
parent
commit
a67ebe302d
  1. 3
      CPF_Cef/Common/Log.cs
  2. 20
      CPF_Cef/Devices/IDCard.cs
  3. 73
      CPF_Cef/Devices/LhtCF.cs
  4. 53
      CPF_Cef/MainModel.cs

3
CPF_Cef/Common/Log.cs

@ -68,14 +68,11 @@ namespace AKSWebBrowser.Commen
{ {
try { streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); } catch { } finally { } try { streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath); } catch { } finally { }
} }
else
{
streamWriter.WriteLine("***********************************************************************"); streamWriter.WriteLine("***********************************************************************");
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss")); streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
streamWriter.WriteLine("输出信息:信息"); streamWriter.WriteLine("输出信息:信息");
streamWriter.WriteLine("信息:\r\n" + message); streamWriter.WriteLine("信息:\r\n" + message);
} }
}
catch { } catch { }
finally finally
{ {

20
CPF_Cef/Devices/IDCard.cs

@ -59,7 +59,10 @@ namespace AksWebBrowser.Devices
{ {
string txt = Encoding.UTF8.GetString(FileName); string txt = Encoding.UTF8.GetString(FileName);
iDCardModel.ImageBase64 = "data:image/jpg;base64," + txt.Substring(0, (txt.IndexOf("=") + 1)); iDCardModel.ImageBase64 = "data:image/jpg;base64," + txt.Substring(0, (txt.IndexOf("=") + 1));
} //开启人脸比对
string stat = LhtCF.LhtCFFace(code, txt);
if (stat == "0")
{
byte[] sCHMsg = new byte[520]; byte[] sCHMsg = new byte[520];
int itype = 0; int itype = 0;
status = LibClass.ParseIDCardInfo(CHMsg, cLen, ref itype, sCHMsg); status = LibClass.ParseIDCardInfo(CHMsg, cLen, ref itype, sCHMsg);
@ -85,6 +88,21 @@ namespace AksWebBrowser.Devices
return "{\"keycode\":\"" + code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + JsonConvert.SerializeObject(OBJ) + "}"; return "{\"keycode\":\"" + code + "\",\"message\":\"seccse\",\"code\":\"200\",\"status\":true,\"data\":" + JsonConvert.SerializeObject(OBJ) + "}";
} }
else else
{
//关闭
LibClass.ICReaderClose(icdev);
return "{\"keycode\":\"" + code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "身份证不是同一人" + "\"}";
}
}
else
{
//关闭
LibClass.ICReaderClose(icdev);
return "{\"keycode\":\"" + code + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "读取身份证失败" + "\"}";
}
}
else
{ {
//关闭 //关闭
LibClass.ICReaderClose(icdev); LibClass.ICReaderClose(icdev);

73
CPF_Cef/Devices/LhtCF.cs

@ -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)]

53
CPF_Cef/MainModel.cs

@ -137,7 +137,8 @@ namespace AKS.EnterpriseLibrary.WebBrowser
break; break;
} }
} }
else { else
{
result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}"; result = "{\"keycode\":\"" + "hert" + "\",\"message\":\"seccse\",\"code\":\"400\",\"status\":true,\"data\":\"参数解析错误\"}";
} }
} }
@ -664,6 +665,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string time = DateTime.Now.ToString( string time = DateTime.Now.ToString(
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
string dirpath = System.IO.Directory.GetCurrentDirectory(); 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/PrintFile"; dirpath = dirpath + @"/wwwroot/PrintFile";
if (!Directory.Exists(dirpath)) if (!Directory.Exists(dirpath))
{ {
@ -724,6 +735,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string time = DateTime.Now.ToString( string time = DateTime.Now.ToString(
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
string dirpath = System.IO.Directory.GetCurrentDirectory(); 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/PrintFile"; dirpath = dirpath + @"/wwwroot/PrintFile";
if (!Directory.Exists(dirpath)) if (!Directory.Exists(dirpath))
{ {
@ -812,6 +833,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string time = DateTime.Now.ToString( string time = DateTime.Now.ToString(
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
string dirpath = System.IO.Directory.GetCurrentDirectory(); 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/WaveOutFile"; dirpath = dirpath + @"/wwwroot/WaveOutFile";
if (!Directory.Exists(dirpath)) if (!Directory.Exists(dirpath))
{ {
@ -1258,6 +1289,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string time = DateTime.Now.ToString( string time = DateTime.Now.ToString(
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
string dirpath = System.IO.Directory.GetCurrentDirectory(); 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/Record"; dirpath = dirpath + @"/wwwroot/Record";
if (!Directory.Exists(dirpath)) if (!Directory.Exists(dirpath))
{ {
@ -1354,6 +1395,16 @@ namespace AKS.EnterpriseLibrary.WebBrowser
string time = DateTime.Now.ToString( string time = DateTime.Now.ToString(
"yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo); "yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
string dirpath = System.IO.Directory.GetCurrentDirectory(); 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/WavFile"; dirpath = dirpath + @"/wwwroot/WavFile";
// Log.Info(dirpath); // Log.Info(dirpath);
if (!Directory.Exists(dirpath)) if (!Directory.Exists(dirpath))

Loading…
Cancel
Save