private void run()
{
Image<Bgr, Byte> image = new Image<Bgr, byte>("lena.jpg"); //Read the files as an 8-bit Bgr image
Capture vid = new Capture("kw.avi");
vid.FlipVertical = true;
int x = 0;
TimeSpan time = TimeSpan.Zero;
MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0);
using (VideoWriter vw = new VideoWriter("out3.avi", 15, 640, 480, true))
{
while (vid.Grab())
{
//if (++x % 1 != 0) continue;
image = vid.RetrieveBgrFrame();
long detectionTime;
List<Rectangle> faces = new List<Rectangle>();
List<Rectangle> eyes = new List<Rectangle>();
DetectFace.Detect(image, "haarcascade_frontalface_default.xml", "supersmile.xml", faces, eyes, out detectionTime);
foreach (Rectangle face in faces)
image.Draw(face, new Bgr(Color.Red), 2);
foreach (Rectangle eye in eyes)
image.Draw(eye, new Bgr(Color.Blue), 2);
if (eyes.Count > 0) time = time.Add(new TimeSpan(0, 0, 0, 0, 66));
//display the image
image.Draw(String.Format("{0}:{1}", time.Seconds, time.Milliseconds), ref font, new Point(50, 50), new Bgr(0, 0, 255));
setimage(image);
vw.WriteFrame<Bgr, Byte>(image);
}
}
}