/// <summary>
/// 播放摄像头线程
/// </summary>
private void Play_Camera()
{
while (bPlayflag)
{
//Thread.Sleep(40);
Mat cFrame = new Mat();
m_vCapture.Read(cFrame);
int sleepTime = (int)Math.Round(1000 / m_vCapture.Fps);
Cv2.WaitKey(sleepTime);
if (cFrame.Empty())
{
continue;
}
Cv2.Flip(cFrame, cFrame, OpenCvSharp.FlipMode.Y);
Rect cMaxrect = new Rect(170, 90, 150, 150);
if (bTakePicture)//拍照,截取指定区域
{
Mat cHead = new Mat(cFrame, cMaxrect);
Cv2.ImWrite(PicSavePath, cHead);
SetPictureBoxImage(pic_head, cHead.ToBitmap());
cHead.Release();
bTakePicture = false;
}
//绘制指定区域(人脸框)
Scalar color = new Scalar(0, 100, 0);
Cv2.Rectangle(cFrame, cMaxrect, color, 2);
SetPictureBoxImage(pic_cam, cFrame.ToBitmap());
cFrame.Release();//释放
}
}