Example #1
0
        unsafe void visualise_tracking(Mat captured_image, ref CLNF face_model, ref FaceModelParameters det_parameters, int frame_count, double fx, double fy, double cx, double cy)
        {
            //Drawing the facial landmarks on the face and the bounding box around it if tracking is successful and initialised
            double detection_certainty = face_model.detection_certainty;
            bool   detection_success   = face_model.detection_success;

            double visualisation_boundary = 0.2;

            // Only draw if the reliability is reasonable, the value is slightly ad-hoc
            if (detection_certainty < visualisation_boundary)
            {
                LandmarkDetector.Draw(new SWIGTYPE_p_cv__Mat(captured_image.CvPtr), face_model);

                double vis_certainty = detection_certainty;
                if (vis_certainty > 1)
                {
                    vis_certainty = 1;
                }
                if (vis_certainty < -1)
                {
                    vis_certainty = -1;
                }

                vis_certainty = (vis_certainty + 1) / (visualisation_boundary + 1);

                //A rough heuristic for box around the face width

                int thickness = (int)Math.Ceiling(2.0 * ((double)captured_image.Cols) / 640.0);

                Vec6d pose_estimate_to_draw = *((Vec6d *)LandmarkDetector.GetCorrectedPoseWorld(new SWIGTYPE_p_CLNF(CLNF.getCPtr(face_model)), fx, fy, cx, cy).Pointer);

                //Draw it in reddish if uncertain, blueish if certain
                var color = new Scalar((1 - vis_certainty) * 255.0, 0, vis_certainty * 255);
                LandmarkDetector.DrawBox(new SWIGTYPE_p_cv__Mat(captured_image.CvPtr), new SWIGTYPE_p_cv__Vec6d(new IntPtr(&pose_estimate_to_draw)), new SWIGTYPE_p_cv__Scalar(new IntPtr(&(color))), thickness, (float)fx, (float)fy, (float)cx, (float)cy);
            }

            //Work out the framerate
            if (frame_count % 10 == 0)
            {
                double t1 = Cv2.GetTickCount();
                fps_tracker = 10.0 / ((double)(t1 - t0) / Cv2.GetTickFrequency());
                t0          = (long)t1;
            }

            using (Mat resize = captured_image.Resize(new Size(Size.Width * SizeFactor, Size.Height * SizeFactor)))
            {
                string fpsSt = "FPS: " + Math.Round(fps_tracker).ToString("0.0");
                Cv2.PutText(resize, fpsSt, new Point(10, 20), HersheyFonts.HersheyPlain, 1, new Scalar(0, 255, 0), 1, LineTypes.AntiAlias);
                Cv2.ImShow("tracking_result", resize);
            }
        }
Example #2
0
 public static extern ExceptionStatus core_FileStorage_shift_Vec6d(IntPtr fs, Vec6d val);
 public static extern ExceptionStatus core_Mat_push_back_Vec6d(IntPtr self, Vec6d v);
Example #4
0
 public unsafe static SWIGTYPE_p_cv__Vec6d ToSwig(this Vec6d vec)
 {
     return(new SWIGTYPE_p_cv__Vec6d((IntPtr)(void *)&vec));
 }
Example #5
0
 public static extern ExceptionStatus core_FileNode_read_Vec6d(IntPtr node, out Vec6d returnValue);
 public static extern void core_Mat_push_back_Vec6d(IntPtr self, Vec6d v);