for ( i = 0; i < multiFaceInfo.faceNum; i++)///////////////這個for回圈
{
ImageInfo imageInfo = ImageUtil.ReadBMP(bitmap);
//得到一個人臉
ASF_SingleFaceInfo eachFace = FaceUtil.GetMaxFace(multiFaceInfo,i);
//得到Rect
MRECT rect = eachFace.faceRect;
//檢測RGB攝像頭下最大人臉
Graphics g = e.Graphics;
float offsetX = pic.Width * 1f / bitmap.Width;
float offsetY = pic.Height * 1f / bitmap.Height;
float x = rect.left * offsetX;
float width = rect.right * offsetX - x;
float y = rect.top * offsetY;
float height = rect.bottom * offsetY - y;
//根據Rect進行畫框
g.DrawRectangle(Pens.Red, x, y, width, height);
if (trackRGBUnit.message != "" && x > 0 && y > 0)
{
//將上一幀檢測結果顯示到頁面上
g.DrawString(trackRGBUnit.message, font, trackRGBUnit.message.Contains("活體") ? blueBrush : yellowBrush, x, y - 15);
}
// Console.WriteLine("第{0}次執行", i);
//保證只檢測一幀,防止頁面卡頓以及出現其他記憶體被占用情況
//異步處理提取特征值和比對,不然頁面會比較卡( ////////////////////////////////就是這個執行緒池)
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
{
Console.WriteLine("第{0}次執行活體行程",i);
if (rect.left != 0 && rect.right != 0 && rect.top != 0 && rect.bottom != 0)
{
try
{
lock (rectLock)
{
allRect.left = (int)(rect.left * offsetX);
allRect.top = (int)(rect.top * offsetY);
allRect.right = (int)(rect.right * offsetX);
allRect.bottom = (int)(rect.bottom * offsetY);
}
if (imageInfo == null)
{
return;
}
//RGB活體檢測
ASF_LivenessInfo liveInfo = FaceUtil.LivenessInfo_RGB(pVideoRGBImageEngine, imageInfo, multiFaceInfo, out retCode_Liveness);
//判斷檢測結果
if (retCode_Liveness == 0 && liveInfo.num > 0)
{
if (liveInfo.num > 1)
{ isLive = MemoryUtil.PtrToStructure<int>(liveInfo.isLive + MemoryUtil.SizeOf<int>() * (i)); Console.WriteLine("{0}人臉結果{1}",i, isLive); }
else {isLive = MemoryUtil.PtrToStructure<int>(liveInfo.isLive); }
isLiveness = (isLive == 1) ? true : false;
Console.WriteLine("活體檢測結果集為{0}", liveInfo.num);
}
//if (imageInfo != null)
//{
// MemoryUtil.Free(imageInfo.imgData);
//}
if (isLive == 1)
{
int result = 2;
//提取人臉特征
//IntPtr feature = FaceUtil.ExtractFeature(pVideoRGBImageEngine, bitmap, eachFace);
//catch (Exception ex) { MessageBox.Show(ex.Message); }
//IntPtr feature = FaceUtil.ExtractFeature(pVideoRGBImageEngine, bitmap, eachFace);
// float similarity = 0f;
////得到比對結果
//result = compareFeature(feature, out similarity);
//MemoryUtil.Free(feature);
if (result > -1)
{
//將比對結果放到顯示訊息中,用于最新顯示
// trackRGBUnit.message = string.Format(" {0}號 {1},{2}", result, similarity, string.Format("RGB{0}", isLiveness ? "活體" : "假體"));
}
else
{
//顯示訊息
trackRGBUnit.message = string.Format("RGB{0}", isLiveness ? "活體" : "假體");
}
}
else
{
//顯示訊息
trackRGBUnit.message = string.Format("RGB{0}", isLiveness ? "活體" : "假體");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
// ispicLock = true;
}
}
else
{
lock (rectLock)
{
allRect.left = 0;
allRect.top = 0;
allRect.right = 0;
allRect.bottom = 0;
}
}
// ispicLock = true;
Thread.Sleep(1);
}));
Thread.Sleep(1);
}//畫框判斷
uj5u.com熱心網友回復:
嗯,怎么了?轉載請註明出處,本文鏈接:https://www.uj5u.com/net/58411.html
標籤:C#
下一篇:學編程
