private static void ShowWindow(Mat img, Mat patternImage, PatternDetector patternDetector, CameraCalibrationInfo calibration, Capture capture = null)
        {
            double fps = capture != null?capture.GetCaptureProperty(CapProp.Fps) : 30;

            using (var window = new GameWindow(calibration, img))
            {
                window.PatternDetector = patternDetector;
                window.Pattern         = patternImage;
                window.Capture         = capture;
                window.Run(fps);
            }
        }
Example #2
0
        private ProcessedFrame ProcessFrame(Mat frame)
        {
            var img = frame.Clone();

            PatternDetector.FindPattern(img);
            PatternDetector.PatternTrackingInfo.ComputePose(PatternDetector.Pattern, _calibration);

            var isPatternPresent = true;
            var patternPose      = PatternDetector.PatternTrackingInfo.Pose3d;

            return(new ProcessedFrame {
                IsPatternPresent = isPatternPresent, PatternPose = patternPose, Image = img
            });
        }
        public static void Run(string path, string patternPath, SourceType type)
        {
            FeaturesUtils.Init();

            var calibration = new CameraCalibrationInfo(560.764656335266f, 562.763179958161f, 295.849138757436f, 255.022208986073f);

            var patternImage    = CvInvoke.Imread(patternPath, Emgu.CV.CvEnum.LoadImageType.Unchanged);
            var patternDetector = new PatternDetector(patternImage);

            if (type == SourceType.Image)
            {
                var image = CvInvoke.Imread(path, Emgu.CV.CvEnum.LoadImageType.Unchanged);
                ShowWindow(image, patternImage, patternDetector, calibration);
            }
            else if (type == SourceType.Video)
            {
                var capture = new Capture(path);
                var image   = capture.QueryFrame();
                ShowWindow(image, patternImage, patternDetector, calibration, capture);
            }
        }