Sascha-L / WPF-MediaKit

Microsoft Public License
363 stars 115 forks source link

How an I setup New Frame listener for VideoCaptureElement #68

Closed bbetter closed 6 years ago

bbetter commented 6 years ago

I need to detect whether qr code is present in each frame of web cam output, How can i get this callback?

xmedeko commented 6 years ago

Check the NewVideoSample event.

bbetter commented 6 years ago

Sorry for not responding for a long time, the problem is that i'm out of ideas , it never enters this callback

   public QrScannerControl()
        {
            InitializeComponent();
            VideoCapElement.EnableSampleGrabbing = true;
            VideoCapElement.NewVideoSample += (sender, args) =>
            {
                var binBitmap = new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(args.VideoFrame)));

                BitMatrix bm = binBitmap.BlackMatrix;
                Detector detector = new Detector(bm);
                DetectorResult detectorResult = detector.detect();

                string retStr = "Found at points ";
                foreach (ResultPoint point in detectorResult.Points)
                {
                    retStr += point.ToString() + ", ";
                }

                Console.WriteLine(retStr);
                var result = _qrCodeReader.decode(binBitmap);
                if (result == null) return;
                OnQrDeoded?.Invoke(result.Text);
            };
//how should i make it start entering this callback? the play method way is not working
            VideoCapElement.Play();
        }
xmedeko commented 6 years ago

Duplicate of #6 ?