private Image <Bgr, byte> DetectEyes(Image <Bgr, byte> frame) { List <Rectangle> eyes = DetectEye.DetectEyes(frame, mainWindow); if (eyes.Count != 1) { return(null); } else { Rectangle rect = eyes[0]; if (eyes[0].Width == eyes[0].Height) { double cutYRate = 0.15; int newy = eyes[0].Y + Convert.ToInt32(eyes[0].Height * cutYRate); int newh = Convert.ToInt32(eyes[0].Height * (1 - cutYRate * 2)); int newx = eyes[0].X; int neww = eyes[0].Width - eyes[0].Width % 4; rect = new Rectangle(newx, newy, neww, newh); } Image <Bgr, byte> subImage = frame.GetSubRect(rect).Copy(); DrawEyes(frame, eyes); return(subImage); } }
private Image <Bgr, byte> DetectEyes(Image <Bgr, byte> frame_rgb) { List <Rectangle> eyes = new List <Rectangle>(); try { eyes = DetectEye.DetectEyes(frame_rgb, mainWindow); } catch (Exception ex) { mainWindow.ShowLable2("Detect eyes exception!!" + ex.Message, false); return(null); } if (eyes.Count != 1) { return(null); } else { //Rectangle rect = eyes[0]; //if (eyes[0].Width == eyes[0].Height) //{ // double cutXRate = 0.1; // int newy = eyes[0].Y ; // int newh =eyes[0].Height ; // int newx = Convert.ToInt32(eyes[0].Width*(1-cutXRate)); // if(newx<0) // newx=0; // int neww = Convert.ToInt32(eyes[0].Width * ((1 +2* cutXRate)) + eyes[0].Width % 4); // if (newx + neww > frame_rgb.Width) // neww = frame_rgb.Width - newx; // rect = new Rectangle(newx, newy, neww, newh); //} //Image<Bgr, byte> subImage = frame_rgb.GetSubRect(rect).Copy(); Image <Bgr, byte> subImage = frame_rgb.Resize(640, 480, Emgu.CV.CvEnum.INTER.CV_INTER_AREA).Copy(); DrawEyes(frame_rgb, eyes); return(subImage); } }