VideoCaptureElement NewVideoSample event never fired

430 views Asked by At

I'm trying to use WPF-MediaKit VideoCaptureElement to preview a web cam video, and to decode QR code if one is in a frame, therefore I need to get access to each frame recorded by web cam and according to documentation it requires EnableSampleGrabbing option on and NewVideoSample event handler. As for now my code looks something like this.

public partial class QrScannerControl : UserControl
{
    public delegate void QrResultDelegate(string qr);

    public QrResultDelegate OnQrDeoded { get; set; }
    private QRCodeReader _qrCodeReader = new QRCodeReader();
    public QrScannerControl()
    {
        InitializeComponent();
        VideoCapElement.EnableSampleGrabbing = true;
        VideoCapElement.UseYuv = false;
        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();

            var retStr = detectorResult.Points.Aggregate("Found at points ", (current, point) => current + (point.ToString() + ", "));

            Console.WriteLine(retStr);
            DebugLabel.Content = retStr;
            var result = _qrCodeReader.decode(binBitmap);
            if (result == null) return;
            OnQrDeoded?.Invoke(result.Text);
        }; 
    }
}

But the event never fires.

0

There are 0 answers