using System;
|
using System.Configuration;
|
using System.Runtime.InteropServices;
|
using System.Text;
|
using FaceSdkX64Service;
|
|
namespace FaceSdkX64Register
|
{
|
public partial class FrmRegister : Form
|
{
|
Int32 VIDEO_WIDTH = 640, VIDEO_HEIGHT = 480; // Ïà»ú·Ö±æÂÊ
|
|
Int32 nRotate = 0; /* Ïà»ú°²×°½Ç¶È£º0-Õý³£°²×°£¬90-Ðýת90¶È°²×°£¬180-Ðýת180¶È°²×°£¬270-Ðýת270¶È°²×° */
|
|
Int32 nWidth = 0, nHeight = 0; // ÊÓÆµÖ¡Êý¾Ý·Ö±æÂÊ£¨Ïà»úÕýװʱΪÏà»ú·Ö±æÂÊ£¬Ïà»ú90¶È»ò270¶Èµ¹×°Ê±ÎªÏà»ú·Ö±æÂÊ¿í¶È¶Ôµ÷£©
|
|
// ½çÃæÏÔʾ¼°±£´æÍ¼ÏóµÄÈËÁ³´óСÏà¶ÔÔʼSDK¼ì²â³öµÄÈËÁ³´óСµÄ·Å´ó±¶Êý
|
float fExtendLeft = 0.15f, fExtendRight = 0.15f, fExtendTop = 0.15f, fExtendBottom = 0.20f; // Ϊ0±íʾ²»·Å´ó
|
|
// ²ÊÉ«¼°ºìÍâÏà»ú VID/PID ÅäÖã¨ÓÐÅäÖÃÔò¸ù¾ÝÖ¸¶¨µÄVID/PID´ò¿ªÏà»ú£¬ÎÞÅäÖÃÔò¸ù¾ÝÑ¡ÔñµÄÏà»ú±àºÅ´ò¿ªÏà»ú£©
|
int nVid1 = 0, nPid1 = 0, nVid2 = 0, nPid2 = 0;
|
|
IntPtr hCamColor = IntPtr.Zero, hCamGray = IntPtr.Zero; // Ïà»ú¶ÔÏó
|
IntPtr hPreviewColor = IntPtr.Zero, hPreviewGray = IntPtr.Zero; // ÊÓÆµÖ¡ÏÔʾ¶Ô½Ç
|
|
TH_Faces.FACE_DETECT_RESULT FaceColor, FaceColorExt; // SDK¼ì²âµ½µÄ²ÊɫͼÏóÔʼÈËÁ³×ø±ê£¬ÒÔ¼°½çÃæÏÔʾ¼°±£´æÍ¼ÏóµÄÈËÁ³×ø±ê£¨ÔÚÔÊ¼×ø±ê»ù´¡Éϸù¾ÝfExtend?±äÁ¿·Å´ó£©
|
TH_Faces.FACE_DETECT_RESULT FaceGray, FaceGrayExt; // SDK¼ì²âµ½µÄºìÍâͼÏóÔʼÈËÁ³×ø±ê£¬ÒÔ¼°½çÃæÏÔʾ¼°±£´æÍ¼ÏóµÄÈËÁ³×ø±ê£¨ÔÚÔÊ¼×ø±ê»ù´¡Éϸù¾ÝfExtend?±äÁ¿·Å´ó£©
|
|
Boolean bSdkInit = false, bCamColorReady = false, bCamGrayReady = false, bFramesReady = false; // ״̬±êʶ
|
|
IntPtr pFrameColor, pFrameGray; // ±£´æ²ÊÉ«Ïà»úºÍºìÍâÏà»úµÄͼÏóÖ¡Êý¾Ý
|
IntPtr pFrameTemp, pFrameTemp2; // ÁÙʱͼÏóÖ¡Êý¾Ý»º³åÇø
|
OpaqueCommand oc;
|
|
bool loading = false;
|
|
public FrmRegister()
|
{
|
InitializeComponent();
|
oc = new OpaqueCommand();
|
CheckForIllegalCrossThreadCalls = false; // ÔÊÐí¿çÏ̵߳÷Óÿؼþ¡¢
|
}
|
|
private void FrmRegister_Load(object sender, EventArgs e)
|
{
|
loading = true;
|
timer3.Enabled = true; // Æô¶¯¶¨Ê±Æ÷£¬¶¨Ê±ÏÔʾ°ë͸Ã÷Ãɰå²ã
|
Task.Run(() =>
|
{
|
try
|
{
|
int i, nCameraNum = CHS_Capture.SmCameraGetCount(); // ¼ì²âÁ¬½ÓµÄÏà»ú¸öÊý
|
|
// ¶ÁÏà»úÅäÖÃÎļþ camera.ini £¨ÊÇ·ñ´ò¿ªÖ¸¶¨ VID/PID µÄÏà»ú£©
|
string val;
|
|
StringBuilder sb = new StringBuilder(256);
|
ConfigHelper.GetPrivateProfileString("common", "vid1", "0", sb, 255, "./camera.ini"); // ¶Á²ÊÉ«Ïà»úµÄVID
|
try
|
{
|
val = sb.ToString();
|
nVid1 = Convert.ToInt32(val, 16);
|
}
|
catch
|
{
|
nVid1 = 0;
|
}
|
ConfigHelper.GetPrivateProfileString("common", "pid1", "0", sb, 255, "./camera.ini"); // ¶Á²ÊÉ«Ïà»úµÄPID
|
try
|
{
|
val = sb.ToString();
|
nPid1 = Convert.ToInt32(val, 16);
|
}
|
catch
|
{
|
nPid1 = 0;
|
}
|
ConfigHelper.GetPrivateProfileString("common", "vid2", "0", sb, 255, "./camera.ini"); // ¶ÁºìÍâÏà»úµÄVID
|
try
|
{
|
val = sb.ToString();
|
nVid2 = Convert.ToInt32(val, 16);
|
}
|
catch
|
{
|
nVid2 = 0;
|
}
|
ConfigHelper.GetPrivateProfileString("common", "pid2", "0", sb, 255, "./camera.ini"); // ¶ÁºìÍâÏà»úµÄPID
|
try
|
{
|
val = sb.ToString();
|
nPid2 = Convert.ToInt32(val, 16);
|
}
|
catch
|
{
|
nPid2 = 0;
|
}
|
|
if (nVid1 <= 0 || nPid1 <= 0) nVid1 = 0;
|
if (nVid2 <= 0 || nPid2 <= 0) nVid2 = 0;
|
|
if (nCameraNum == 0)
|
{
|
label1.Text = "ûÓмì²âµ½Ïà»ú£¬Çë¼ì²éÏà»úÁ¬½ÓÊÇ·ñÕý³££¡";
|
label1.ForeColor = Color.Red;
|
return;
|
}
|
|
// SDK³õʼ»¯
|
int ret = TH_Faces.IdFaceSdkInit();
|
if (ret < 0)
|
{
|
label1.Text = "Ëã·¨³õʼ»¯Ê§°Ü, Çë²åÈë¼ÓÃܹ· !";
|
label1.ForeColor = Color.Red;
|
|
IntPtr pRunCode = Marshal.AllocHGlobal(35 + 1);
|
TH_Faces.IdFaceSdkGetRunCode(pRunCode);
|
MessageBox.Show("SDK³õʼ»¯Ê§°Ü !\n\nÉ豸ÔËÐÐÂë: " + Marshal.PtrToStringAnsi(pRunCode));
|
Marshal.FreeHGlobal(pRunCode);
|
return;
|
}
|
|
// ÊÚȨÊÇ·ñÖ§³Ö»îÌå¼ì²â
|
ret = TH_Faces.IdFaceSdkGetLiveFaceStatus();
|
if (ret != 1)
|
{
|
TH_Faces.IdFaceSdkUninit();
|
label1.Text = "»îÌå¼ì²âÊÚȨδ¿ªÍ¨,ÇëÁªÏµ¹©Ó¦ÉÌ !";
|
label1.ForeColor = Color.Red;
|
return;
|
}
|
|
bSdkInit = true;
|
|
// ·ÖÅä²Êɫ֡»º³åÇø¡¢ºìÍâÖ¡»º³åÇø¼°ÁÙʱ֡Êý¾Ý»º³åÇø
|
pFrameColor = Marshal.AllocHGlobal(VIDEO_WIDTH * VIDEO_HEIGHT * 3);
|
pFrameGray = Marshal.AllocHGlobal(VIDEO_WIDTH * VIDEO_HEIGHT * 3);
|
pFrameTemp = Marshal.AllocHGlobal(VIDEO_WIDTH * VIDEO_HEIGHT * 3);
|
pFrameTemp2 = Marshal.AllocHGlobal(VIDEO_WIDTH * VIDEO_HEIGHT * 3);
|
|
// ·ÖÅä²ÊÉ«ÔʼÈËÁ³×ø±ê¿Õ¼ä¡¢²ÊÉ«·Å´óÈËÁ³×ø±ê¿Õ¼ä¡¢ºìÍâÔʼÈËÁ³×ø±ê¿Õ¼ä¡¢ºìÍâ·Å´óÈËÁ³×ø±ê¿Õ¼ä
|
FaceColor = new TH_Faces.FACE_DETECT_RESULT();
|
FaceColorExt = new TH_Faces.FACE_DETECT_RESULT();
|
FaceGray = new TH_Faces.FACE_DETECT_RESULT();
|
FaceGrayExt = new TH_Faces.FACE_DETECT_RESULT();
|
|
Start();
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show("³õʼ»¯Ïà»úʧ°Ü: " + ex.Message, "´íÎó", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
}
|
finally
|
{
|
loading = false;
|
}
|
});
|
}
|
|
private void Start()
|
{
|
if (nRotate == 90 || nRotate == 270)
|
{
|
nWidth = VIDEO_HEIGHT;
|
nHeight = VIDEO_WIDTH;
|
}
|
else
|
{
|
nWidth = VIDEO_WIDTH;
|
nHeight = VIDEO_HEIGHT;
|
}
|
|
// ´ò¿ª²ÊÉ«Ïà»ú
|
if (nVid1 > 0) hCamColor = CHS_Capture.SmCameraOpenEx(nVid1, nPid1, VIDEO_WIDTH, VIDEO_HEIGHT);
|
hCamColor = CHS_Capture.SmCameraOpen(0, VIDEO_WIDTH, VIDEO_HEIGHT);
|
|
// ´´½¨²Êɫ֡ÏÔʾ¶ÔÏó
|
hPreviewColor = CHS_Capture.SmCameraPreviewCreate(nWidth, nHeight, pictureBox1.Handle);
|
|
bCamColorReady = (hCamColor != IntPtr.Zero);
|
bCamGrayReady = (hCamGray != IntPtr.Zero);
|
bFramesReady = false;
|
|
|
// Æô¶¯¶¨Ê±Æ÷
|
//timer1.Interval = 40;
|
//timer2.Interval = 200;
|
//timer1.Enabled = true;
|
//timer2.Enabled = true;
|
}
|
|
private void timer1_Tick(object sender, EventArgs e)
|
{
|
int ret;
|
|
// Èç¹û²ÊÉ«Ïà»úÒÑ´ò¿ª£¬¶ÁÈ¡²ÊÉ«ÊÓÆµÖ¡
|
if (bCamColorReady)
|
{
|
if (nRotate == 90 || nRotate == 270)
|
{
|
// Ïà»úÐýת90¶È»ò270¶È£¬ÏȶÁµ½ÁÙʱ»º³åÇø
|
ret = CHS_Capture.SmCameraGetFrame(hCamColor, pFrameTemp, 1, 0);
|
|
// ½«ÁÙʱ»º³åÇøÖеÄͼÏóÊý¾ÝÐýתºó·ÅÈë pFrameColor »º³åÇø
|
if (ret == 0) TH_Faces.RotateRgb24Data(pFrameTemp, VIDEO_WIDTH, VIDEO_HEIGHT, nRotate, 0, pFrameColor);
|
}
|
// Ö±½Ó¶ÁÈ¡ÊÓÆµÖ¡Êý¾Ýµ½ pFrameColor »º³åÇø
|
else ret = CHS_Capture.SmCameraGetFrame(hCamColor, pFrameColor, 1, 0);
|
|
if (ret == 2) // Ïà»úÒѶϿªÁ¬½Ó£¬Ôò¹Ø±ÕÏà»ú
|
{
|
CHS_Capture.SmCameraClose(hCamColor);
|
hCamColor = IntPtr.Zero;
|
bCamColorReady = false;
|
label1.Text = "²ÊÉ«Ïà»úÒѶϿª";
|
label1.ForeColor = Color.Red;
|
}
|
}
|
|
// Èç¹ûºìÍâÏà»úÒÑ´ò¿ª£¬¶ÁÈ¡ºìÍâÊÓÆµÖ¡
|
if (bCamGrayReady)
|
{
|
if (nRotate == 90 || nRotate == 270)
|
{
|
// Ïà»úÐýת90¶È»ò270¶È£¬ÏȶÁµ½ÁÙʱ»º³åÇø
|
ret = CHS_Capture.SmCameraGetFrame(hCamGray, pFrameTemp, 1, 0);
|
|
// ½«ÁÙʱ»º³åÇøÖеÄͼÏóÊý¾ÝÐýתºó·ÅÈë pFrameGray »º³åÇø
|
if (ret == 0) TH_Faces.RotateRgb24Data(pFrameTemp, VIDEO_WIDTH, VIDEO_HEIGHT, nRotate, 0, pFrameGray);
|
}
|
// Ö±½Ó¶ÁÈ¡ÊÓÆµÖ¡Êý¾Ýµ½ pFrameGray »º³åÇø
|
else ret = CHS_Capture.SmCameraGetFrame(hCamGray, pFrameGray, 1, 0);
|
|
if (ret == 2) // Ïà»úÒѶϿªÁ¬½Ó£¬Ôò¹Ø±ÕÏà»ú
|
{
|
CHS_Capture.SmCameraClose(hCamGray);
|
hCamGray = IntPtr.Zero;
|
bCamGrayReady = false;
|
label1.Text = "ºìÍâÏà»úÒѶϿª";
|
label1.ForeColor = Color.Red;
|
}
|
}
|
|
bFramesReady = (bCamColorReady || bCamGrayReady);
|
|
// ÏÔʾ²Êɫ֡ͼÏó
|
if (bCamColorReady) CHS_Capture.SmCameraPreviewFace(hPreviewColor, pFrameColor, FaceColorExt.rcFace.left, FaceColorExt.rcFace.top, FaceColorExt.rcFace.right, FaceColorExt.rcFace.bottom, 3, Color.Green.ToArgb());
|
|
// ÏÔʾºìÍâ֡ͼÏó
|
if (bCamGrayReady) CHS_Capture.SmCameraPreviewFace(hPreviewGray, pFrameGray, FaceGrayExt.rcFace.left, FaceGrayExt.rcFace.top, FaceGrayExt.rcFace.right, FaceGrayExt.rcFace.bottom, 3, Color.Green.ToArgb());
|
}
|
|
private void timer2_Tick(object sender, EventArgs e)
|
{
|
if (bFramesReady)
|
{
|
// ¶Ô²ÊÉ«ºÍºìÍâ֡ͼÏó·Ö±ð¼ì²âÈËÁ³
|
int nNum1 = 0, nNum2 = 0;
|
if (bCamColorReady) nNum1 = TH_Faces.IdFaceSdkDetectFace(pFrameColor, nWidth, nHeight, ref FaceColor);
|
if (bCamGrayReady) nNum2 = TH_Faces.IdFaceSdkDetectFace(pFrameGray, nWidth, nHeight, ref FaceGray);
|
|
if (nNum1 < 1)
|
{ // ²ÊÉ«¾µÍ·Î´¼ì²âµ½ÈËÁ³£¬Çå³ý²ÊÉ«ÈËÁ³×ø±ê
|
FaceColor.rcFace.left = FaceColor.rcFace.right = 0;
|
FaceColor.rcFace.top = FaceColor.rcFace.bottom = 0;
|
FaceColorExt = FaceColor;
|
}
|
else
|
{ // ²ÊÉ«¾µÍ·¼ì²âµ½ÈËÁ³£¬¸üвÊÉ«ÈËÁ³·Å´ó×ø±ê
|
int w = FaceColor.rcFace.right - FaceColor.rcFace.left, h = FaceColor.rcFace.bottom - FaceColor.rcFace.top;
|
int left = FaceColor.rcFace.left - (int)(w * fExtendLeft), right = FaceColor.rcFace.right + (int)(w * fExtendRight), top = FaceColor.rcFace.top - (int)(h * fExtendTop), bottom = FaceColor.rcFace.bottom + (int)(h * fExtendBottom);
|
if (left < 0) left = 0;
|
if (right >= nWidth) right = nWidth - 1;
|
if (top < 0) top = 0;
|
if (bottom >= nHeight) bottom = nHeight - 1;
|
|
FaceColorExt.rcFace.left = left;
|
FaceColorExt.rcFace.top = top;
|
FaceColorExt.rcFace.right = right;
|
FaceColorExt.rcFace.bottom = bottom;
|
|
}
|
if (nNum2 < 1)
|
{ // ºìÍ⾵ͷδ¼ì²âµ½ÈËÁ³£¬Çå³ýºìÍâÈËÁ³×ø±ê
|
FaceGray.rcFace.left = FaceGray.rcFace.right = 0;
|
FaceGray.rcFace.top = FaceGray.rcFace.bottom = nHeight;
|
FaceGrayExt = FaceGray;
|
}
|
else
|
{ // ºìÍ⾵ͷ¼ì²âµ½ÈËÁ³£¬¸üкìÍâÈËÁ³·Å´ó×ø±ê
|
int w = FaceGray.rcFace.right - FaceGray.rcFace.left, h = FaceGray.rcFace.bottom - FaceGray.rcFace.top;
|
int left = FaceGray.rcFace.left - (int)(w * fExtendLeft), right = FaceGray.rcFace.right + (int)(w * fExtendRight), top = FaceGray.rcFace.top - (int)(h * fExtendTop), bottom = FaceGray.rcFace.bottom + (int)(h * fExtendBottom);
|
if (left < 0) left = 0;
|
if (right >= nWidth) right = nWidth - 1;
|
if (top < 0) top = 0;
|
if (bottom >= nHeight) bottom = nHeight - 1;
|
|
FaceGrayExt.rcFace.left = left;
|
FaceGrayExt.rcFace.top = top;
|
FaceGrayExt.rcFace.right = right;
|
FaceGrayExt.rcFace.bottom = bottom;
|
}
|
|
if (nNum1 > 0 || nNum2 > 0) // ÖÁÉÙÓÐÒ»¸öÏà»úÄܼì²âµ½ÈËÁ³Ê±£¬½øÐлîÌåÅбð
|
{
|
int nLiveFace = 0;
|
|
if ((bCamColorReady == true && nNum1 < 1) || (bCamGrayReady == true && nNum2 < 1))
|
{ // Á½¸öÏà»ú¶¼´ò¿ªÁË£¬µ«ÊÇÖ»ÓÐÒ»¸öÏà»úÄܼì²âµ½ÈËÁ³Ê±£¬×Ô¶¯ÅÐΪ·Ç»îÌå
|
label1.Text = "È·ÈÏΪ·Ç»îÌå !";
|
label1.ForeColor = Color.Red;
|
}
|
else
|
{
|
int nScore = 0;
|
|
if (nNum1 > 0 && nNum2 > 0) nLiveFace = TH_Faces.IdFaceSdkLiveFaceDetectEx(nWidth, nHeight, pFrameColor, ref FaceColor, (IntPtr)0, ref FaceGray, ref nScore);
|
else if (nNum1 > 0) nLiveFace = TH_Faces.IdFaceSdkLiveFaceDetectEx(nWidth, nHeight, pFrameColor, ref FaceColor, IntPtr.Zero, ref FaceGray, ref nScore);
|
else nLiveFace = TH_Faces.IdFaceSdkLiveFaceDetectEx(nWidth, nHeight, IntPtr.Zero, ref FaceColor, pFrameGray, ref FaceGray, ref nScore);
|
|
if (nLiveFace == 1)
|
{
|
label1.Text = "È·ÈÏΪ»îÌ壬·ÖÊý " + nScore.ToString();
|
label1.ForeColor = Color.Green;
|
|
if (nScore > 80)
|
{
|
string strTimeFlag = System.DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
string strFolder = Environment.CurrentDirectory + "\\Record";
|
if (System.IO.Directory.Exists(strFolder) == false)
|
System.IO.Directory.CreateDirectory(strFolder);
|
|
string strFileName = strFolder + "\\" + strTimeFlag + "_" + nLiveFace.ToString() + "_1.jpg";
|
if (nNum1 > 0)
|
{
|
IntPtr ptrFileName = Marshal.StringToHGlobalAnsi(strFileName);
|
TH_Faces.CropImage(pFrameColor, nWidth, nHeight, pFrameTemp2, FaceColorExt.rcFace.left, FaceColorExt.rcFace.top, FaceColorExt.rcFace.right - FaceColorExt.rcFace.left, FaceColorExt.rcFace.bottom - FaceColorExt.rcFace.top, 0);
|
TH_Faces.SaveJpegFile(ptrFileName, pFrameTemp2, FaceColorExt.rcFace.right - FaceColorExt.rcFace.left, FaceColorExt.rcFace.bottom - FaceColorExt.rcFace.top, 24, 90);
|
}
|
|
timer1.Enabled = false; // Í£Ö¹¶¨Ê±Æ÷£¬±ÜÃâÁ¬Ðø¼ì²â
|
timer2.Enabled = false;
|
|
//MessageBox.Show("»îÌå¼ì²â³É¹¦£¬·ÖÊý " + nScore.ToString() + "£¬ÈËÁ³Í¼Æ¬Òѱ£´æµ½ Record Ŀ¼Ï£¡", "Ìáʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
// ÊÍ·Å×ÊÔ´
|
Stop();
|
|
Release();
|
|
this.Hide(); // Òþ²Øµ±Ç°´°¿Ú
|
int port = 9298;
|
string? portStr = ConfigurationManager.AppSettings.Get("port");
|
if (!string.IsNullOrEmpty(portStr) && int.TryParse(portStr, out int tempPort))
|
{
|
port = tempPort; // ´ÓÅäÖÃÎļþ¶ÁÈ¡¶Ë¿ÚºÅ
|
}
|
|
DateTime startTime = DateTime.Now;
|
Task.Run(() =>
|
{
|
while (true) // µÈ´ý10ÃëÖÓ
|
{
|
if (DateTime.Now - startTime > TimeSpan.FromSeconds(60))
|
{
|
Environment.Exit(0); // Í˳öÓ¦ÓóÌÐò
|
}
|
|
}
|
});
|
|
HttpServer httpServer = new HttpServer(port, strFileName); // Æô¶¯HTTP·þÎñ£¬ÌṩÈËÁ³Í¼Æ¬·ÃÎÊ
|
|
foreach (var item in Directory.GetFiles(strFolder))
|
{
|
File.Delete(item);
|
}
|
|
Environment.Exit(0); // Í˳öÓ¦ÓóÌÐò
|
}
|
}
|
else if (nLiveFace == 0)
|
{
|
label1.Text = "δȷÈÏΪ»îÌ壬·ÖÊý " + nScore.ToString();
|
label1.ForeColor = Color.Magenta;
|
}
|
else
|
{
|
label1.Text = "»îÌå¼ì²âʧ°Ü£¬½Ó¿Ú·µ»Ø " + nLiveFace.ToString();
|
label1.ForeColor = Color.Red;
|
}
|
}
|
|
//if (bSaveFace) // ÊÇ·ñ±£´æÈËÁ³Í¼Æ¬£¬Ã¿Ö¡ÈËÁ³Í¼Æ¬¶¼±£´æ»áÕ¼Óýϴó´ÅÅ̿ռä
|
//{
|
// string strTimeFlag = System.DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
// string strFolder = Environment.CurrentDirectory + "\\Record";
|
// if (System.IO.Directory.Exists(strFolder) == false)
|
// System.IO.Directory.CreateDirectory(strFolder);
|
|
// // ±£´æ²ÊÉ«ÈËÁ³Í¼Æ¬
|
// if (nNum1 > 0)
|
// {
|
// string strFileName = strFolder + "\\" + strTimeFlag + "_" + nLiveFace.ToString() + "_1.jpg";
|
// IntPtr ptrFileName = Marshal.StringToHGlobalAnsi(strFileName);
|
// TH_Faces.CropImage(pFrameColor, nWidth, nHeight, pFrameTemp2, FaceColorExt.rcFace.left, FaceColorExt.rcFace.top, FaceColorExt.rcFace.right - FaceColorExt.rcFace.left, FaceColorExt.rcFace.bottom - FaceColorExt.rcFace.top, 0);
|
// TH_Faces.SaveJpegFile(ptrFileName, pFrameTemp2, FaceColorExt.rcFace.right - FaceColorExt.rcFace.left, FaceColorExt.rcFace.bottom - FaceColorExt.rcFace.top, 24, 90);
|
// }
|
// // ±£´æºìÍâÈËÁ³Í¼Æ¬
|
// if (nNum2 > 0)
|
// {
|
// string strFileName = strFolder + "\\" + strTimeFlag + "_" + nLiveFace.ToString() + "_2.jpg";
|
// IntPtr ptrFileName = Marshal.StringToHGlobalAnsi(strFileName);
|
// TH_Faces.CropImage(pFrameGray, nWidth, nHeight, pFrameTemp2, FaceGrayExt.rcFace.left, FaceGrayExt.rcFace.top, FaceGrayExt.rcFace.right - FaceGrayExt.rcFace.left, FaceGrayExt.rcFace.bottom - FaceGrayExt.rcFace.top, 0);
|
// TH_Faces.SaveJpegFile(ptrFileName, pFrameTemp2, FaceGrayExt.rcFace.right - FaceGrayExt.rcFace.left, FaceGrayExt.rcFace.bottom - FaceGrayExt.rcFace.top, 24, 90);
|
// }
|
//}
|
}
|
else
|
{ // Á½¸öÏà»ú¾ùδ¼ì²âµ½ÈËÁ³£¬ÔòÌáʾÓû§ÕýÊÓÏà»ú
|
label1.Text = "ÇëÕýÊÓÏà»ú !";
|
label1.ForeColor = Color.Red;
|
}
|
bFramesReady = false;
|
}
|
}
|
|
void Stop()
|
{
|
bCamColorReady = bCamGrayReady = false;
|
bFramesReady = false;
|
|
// ¹Ø±Õ²ÊÉ«Ïà»ú
|
if (hCamColor != IntPtr.Zero)
|
{
|
CHS_Capture.SmCameraClose(hCamColor);
|
hCamColor = IntPtr.Zero;
|
}
|
|
// ¹Ø±ÕºìÍâÏà»ú
|
if (hCamGray != IntPtr.Zero)
|
{
|
CHS_Capture.SmCameraClose(hCamGray);
|
hCamGray = IntPtr.Zero;
|
}
|
|
// Ïú»Ù²Êɫ֡ÏÔʾ¶ÔÏó
|
if (hPreviewColor != IntPtr.Zero)
|
{
|
CHS_Capture.SmCameraPreviewDestroy(hPreviewColor);
|
hPreviewColor = IntPtr.Zero;
|
}
|
|
// Ïú»ÙºìÍâÖ¡ÏÔʾ¶ÔÏó
|
if (hPreviewGray != IntPtr.Zero)
|
{
|
CHS_Capture.SmCameraPreviewDestroy(hPreviewGray);
|
hPreviewGray = IntPtr.Zero;
|
}
|
}
|
|
void Release()
|
{
|
Marshal.FreeHGlobal(pFrameColor);
|
Marshal.FreeHGlobal(pFrameGray);
|
Marshal.FreeHGlobal(pFrameTemp);
|
Marshal.FreeHGlobal(pFrameTemp2);
|
|
if (bSdkInit)
|
{
|
bSdkInit = false;
|
|
// SDK·´³õʼ»¯£¬ÊÍ·ÅSDK×ÊÔ´
|
TH_Faces.IdFaceSdkUninit();
|
}
|
}
|
|
private void timer3_Tick(object sender, EventArgs e)
|
{
|
if (!loading)
|
{
|
loading = false;
|
oc.HideOpaqueLayer(); // Òþ²Ø°ë͸Ã÷Ãɰå²ã
|
timer3.Enabled = false; // Í£Ö¹¶¨Ê±Æ÷
|
timer1.Interval = 40;
|
timer2.Interval = 200;
|
timer1.Enabled = true;
|
timer2.Enabled = true;
|
label1.Visible = true; // Òþ²ØÌáʾÐÅÏ¢
|
}
|
else
|
{
|
label1.Visible = false; // Òþ²ØÌáʾÐÅÏ¢
|
oc.ShowOpaqueLayer(this, 255, true);
|
}
|
|
}
|
}
|
}
|