我想检测人脸检测的持续时间。过程的顺序是这样的:
然而,我的问题是我设法完成前两个过程但是当秒表恢复时,时间不会在上一个暂停时间开始。例如:
再次检测到脸部,但秒表将在11秒而不是6秒时恢复
for (int i = 0; i < faces.Length; i++)
{
var face = faces[i];
videoFrame.Draw(face, new Bgr(255, 255, 255), 2);
Image<Bgr, Byte> grayFrameTemp = videoFrame.GetSubRect(faces[i]);
//resize image
Image<Gray, Byte> graySubFace = grayFrame.GetSubRect(faces[i]);
Image<Gray, Byte> graySubFaceCrop = graySubFace.Resize(100, 100, Inter.Cubic);
Image<Bgr, Byte> frame_resize = videoFrame.Resize(100, 100, Inter.Cubic);
//Start the stopwatch whenever the face is detected
SW_Start();
}
public static void SW_Start()
{
Stopwatch sW = new Stopwatch();
sW.Start();
//Thread.Sleep(1000); //1 second
//sW.Stop();
TimeSpan ts = sW.Elapsed;
elapsedTime = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
}
注意*:使用Thread.Sleep(1000)和sw.Stop()可以解决我的问题,但它会导致我的程序出现大量延迟。 请帮忙