Home > Net >  About the ThreadPool. QueueUserWorkItem (new WaitCallback executed only once in a for loop
About the ThreadPool. QueueUserWorkItem (new WaitCallback executed only once in a for loop

Time:09-19


For (I=0; I & lt; MultiFaceInfo. FaceNum; I++)///////////////the for loop
{
ImageInfo ImageInfo=ImageUtil. ReadBMP (bitmap);
//get a facial
ASF_SingleFaceInfo eachFace=FaceUtil. GetMaxFace (multiFaceInfo, I);
//get the Rect
MRECT the rect=eachFace. FaceRect;
//testing RGB camera under the largest face
Graphics g=um participant raphics;
Float offsetX=PIC. Width * 1 f/bitmap. The Width;
Float offsetY=PIC. Height * 1 f/bitmap. The Height;
Float x=the rect. Left * offsetX;
Float width=the rect. Right * offsetX - x;
Float y=the rect. Top * offsetY;
Float height=the rect. Bottom * offsetY - y;
//frame according to the Rect
G.D rawRectangle (Pens. The Red, x, y, width, height);
If (trackRGBUnit message!="" & amp; & X & gt; 0 & amp; & Y & gt; 0)
{
//to a frame detection results show page
G.D rawString (trackRGBUnit. The message, the font, trackRGBUnit. Message. The Contains (" live ")? BlueBrush: yellowBrush, x, y - 15);
}
//the Console. WriteLine (" {0} time execution ", I);
//that detect only one frame, to prevent the occurrence of other memory page caton and occupied is

//asynchronous processing to extract the characteristic value and compare, otherwise the page will compare card (////////////////////////////////this is the thread pool)
ThreadPool. QueueUserWorkItem (new WaitCallback delegate (
{
Console. WriteLine (" {0} time execution process of living ", I);
If (the rect left!=0 & amp; & The rect. Right!=0 & amp; & The rect. Top!=0 & amp; & The rect bottom!=0)
{
Try
{
The lock (rectLock)
{
AllRect. Left=(int) (the rect. Left * offsetX);
AllRect. Top=(int) (the rect. Top * offsetY);
AllRect. Right=(int) (the rect. Right * offsetX);
AllRect. Bottom=(int) (the rect. Bottom * offsetY);
}






If (imageInfo==null)
{
return;
}


//RGB live test
ASF_LivenessInfo liveInfo=FaceUtil. LivenessInfo_RGB (pVideoRGBImageEngine imageInfo, multiFaceInfo, out retCode_Liveness);

//judgment test resultIf (retCode_Liveness==0 & amp; & LiveInfo. Num & gt; 0)
{

If (liveInfo. Num & gt; 1)
{isLive=MemoryUtil. PtrToStructure (liveInfo. IsLive + MemoryUtil. SizeOf (a) * (I)); Console. WriteLine (" {1} {0} face result ", I, isLive); }
The else {isLive=MemoryUtil. PtrToStructure (liveInfo isLive); }
IsLiveness=(isLive==1)? True, false;

Console. WriteLine (" live test result sets {0} ", liveInfo. Num);

}

//if (imageInfo!=null)
//{
//MemoryUtil. Free (imageInfo. ImgData);
//}
If (isLive==1)
{
Int result=2;

//to extract face feature
//IntPtr feature=FaceUtil. ExtractFeature (pVideoRGBImageEngine, bitmap, eachFace);
//catch Exception (ex) {MessageBox. Show (ex. Message); }
//IntPtr feature=FaceUtil. ExtractFeature (pVideoRGBImageEngine, bitmap, eachFace);
//float similarity=0 f;
////get the comparison the results
//result=compareFeature (feature, out similarity);

//MemoryUtil. Free (feature);
If (result & gt; 1)
{
//will compare results on the display messages, used in the latest show
//trackRGBUnit. Message=the string. Format (" {0} {1}, {2} ", result, similarity, and the string. Format (" isLiveness, RGB {0} "? "Living" : "implant"));
}
The else
{
//display messages
TrackRGBUnit. Message=the string. Format (" isLiveness, RGB {0} "? "Living" : "implant");
}
}
The else
{
//display messages
TrackRGBUnit. Message=the string. Format (" isLiveness, RGB {0} "? "Living" : "implant");
}
}
The catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
The finally
{


//ispicLock=true;
}
}
The else
{
The lock (rectLock)
{
AllRect. Left=0;
AllRect. Top=0;
AllRect. Right=0;
AllRect. Bottom=0;
}
}
//ispicLock=true;

Thread.sleep (1);
}));
Thread.sleep (1);
}//frame

CodePudding user response:

Well, what's the matter?
  •  Tags:  
  • C #
  • Related