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 { }
}
else
{
streamWriter.WriteLine("***********************************************************************");
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
streamWriter.WriteLine("输出信息:信息");
streamWriter.WriteLine("信息:\r\n" + message);
}
}
catch { }
finally
{

20
CPF_Cef/Devices/IDCard.cs

@ -59,7 +59,10 @@ namespace AksWebBrowser.Devices
{
string txt = Encoding.UTF8.GetString(FileName);
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];
int itype = 0;
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) + "}";
}
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);

73
CPF_Cef/Devices/LhtCF.cs

@ -1,8 +1,11 @@
using AKSWebBrowser.Commen;
using CPF.Linux;
using CPF.Mac.CoreGraphics;
using CPF.Windows;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
@ -12,6 +15,7 @@ namespace AksWebBrowser.Devices
{
public class LhtCF
{
public static string face = string.Empty;
public LhtCF() { }
/// <summary>
@ -19,40 +23,49 @@ namespace AksWebBrowser.Devices
/// </summary>
/// <param name="code"></param>
/// <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
{
int status = libLhtCFs.CF_Init();
// Log.Info("初始化函数" + status);
if (status == 0)
{
status = libLhtCFs.CF_GetCameraStatus(0);
// Log.Info("获取摄像头状态" + status);
face = _face;
status = libLhtCFs.CF_Init();
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);
//status = libLhtCFs.SetCamADataCallbackEx(GetMjpegStream);
//Log.Info("设置回调:" + status);
//停止活体检测
Task.Run(() => { libLhtCFs.CF_StopLiveDetect(); });
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
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); });
@ -62,13 +75,15 @@ namespace AksWebBrowser.Devices
}
}
}
}
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数据回调函数定义
[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数据回调函数定义
[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)]
@ -143,12 +158,12 @@ namespace AksWebBrowser.Devices
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", CallingConvention = CallingConvention.Cdecl)]
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)]
public static extern int CF_FaceCompare(byte[] picPathA, byte[] picPathB, int score);
[DllImport("LhtCF.dll", CallingConvention = CallingConvention.Cdecl)]
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)]

53
CPF_Cef/MainModel.cs

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

Loading…
Cancel
Save