VideoCaptureElement从未触发过NewVideoSample事件

时间:2017-12-03 23:05:29

标签: c# wpf directshow wpf-mediakit

我正在尝试使用WPF-MediaKit VideoCaptureElement来预览网络摄像头视频,如果一个人在一个帧中,则解码二维码,因此我需要访问由网络摄像头录制的每个帧。根据文档,它需要EnableSampleGrabbing选项和NewVideoSample事件处理程序。 至于现在我的代码看起来像这样。

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);
        }; 
    }
}

但事件永远不会发生。

0 个答案:

没有答案