Событие VideoCaptureElement NewVideoSample никогда не запускалось
Я пытаюсь использовать WPF-MediaKit VideoCaptureElement
для предварительного просмотра видео с веб-камеры и декодирования QR-кода, если он есть в кадре, поэтому мне нужно получить доступ к каждому кадру, записанному веб-камерой, и в соответствии с документацией это требует 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);
};
}
}
Но событие никогда не срабатывает.