public Mat RoiCropByPercent(Mat frame, double percentOfFace = 0.33) { double size = Math.Max(Parent.Width, Parent.Height) * percentOfFace; return(MatTool.New(frame, new Vision.Rect(Parent.X + Center.X - size * 0.5, Parent.Y + Center.Y - size * 0.5, size, size), true)); }
public Mat Plot(ScreenProperties screen) { var errorList = new List <double>(); var errorMM = new List <double>(); var ptList = new List <Point>(); var ptDistList = new List <Point>(); var frameMargin = new Point(12, 12); var frameSize = new Size(480, 480); var frameBackSize = frameSize.Clone(); frameBackSize.Width += frameMargin.Y * 2; frameBackSize.Height += frameMargin.Y * 2; var frame = MatTool.New(frameBackSize, MatType.CV_8UC3); using (Mat m = MatTool.New(frameSize, MatType.CV_8UC3)) { m.DrawRectangle(new Rect(0, 0, m.Width, m.Height), Scalar.BgrWhite, -1); foreach (var item in Data) { var pt = frameSize.Center; var ptDist = pt.Clone(); var key3d = item.Key * (-1 / item.Key.Z); var key = new Point(key3d.X, key3d.Y); pt.X *= key.X; pt.Y *= key.Y; var gazeVec = item.Value.Face.GazeInfo.Vector; ptDist.X *= gazeVec.X; ptDist.Y *= gazeVec.Y; pt += frameSize.Center; ptDist += frameSize.Center; ptList.Add(pt); ptDistList.Add(ptDist); var errorDiff = key - new Point(gazeVec.X, gazeVec.Y); var error = Math.Sqrt(Math.Pow(errorDiff.X, 2) + Math.Pow(errorDiff.Y, 2)); errorList.Add(error); var mmDist = item.Value.Face.LandmarkTransform.Z / item.Value.Face.UnitPerMM; errorMM.Add(Math.Abs(screen.Origin.Z - mmDist) * error / 10); } var errorMax = errorList.Max(); var errorMin = errorList.Min(); var errorAvg = errorList.Average(); var errorMMAvg = errorMM.Average(); for (int i = 0; i < ptList.Count; i++) { var pt = ptList[i]; var ptDist = ptDistList[i]; var error = errorList[i]; var alpha = (error - errorMin) / (errorMax - errorMin); var color = Scalar.Blend(Scalar.BgrBlue, 1 - alpha, Scalar.BgrRed, alpha); m.DrawArrow(pt, ptDist, color, 1, LineTypes.AntiAlias, 0.15); } Core.Cv.DrawText(m, $"Mean error: {errorAvg.ToString("0.000")}\n" + $"Mean error(cm): {errorMMAvg.ToString("0.00")}\n" + $"Mean error(degree): {(Math.Atan(errorAvg) / Math.PI * 180).ToString("0.00")}\n" + $"Samples: {errorList.Count}", new Point(10, 25), HersheyFonts.HersheyComplexSmall, 0.5, Scalar.BgrBlack, 1); frame.DrawRectangle(new Rect(0, 0, frame.Width, frame.Height), new Scalar(64, 64, 64), -1); Core.Cv.DrawMatAlpha(frame, m, frameMargin); } return(frame); }
public Mat ROI(Mat frame) { return(MatTool.New(frame, new Rect(Parent.X + X, Parent.Y + Y, Width, Height), true)); }