[英]How to control exposure or brightness of webcam in UWP using MediaCapture.VideoDeviceController for QR-Code scanning
[英]QR code scanning does not work in UWP
我正在使用ZXing.Net.Mobile,并具有以下代码来扫描QR码。
await scanner.Scan().ContinueWith(t =>
{
if (t.Result != null)
HandleScanResult(t.Result);
});
scanner.UseCustomOverlay = false;
scanner.ScanContinuously(async (res) =>
{
var msg = "Found Barcode: " + res.Text;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
ViewHelper.showMessage(msg, "");
});
});
我已经尝试了ContinueWith和ScanContinuosly,但是它们都不起作用。 我有一条带红线的相机视图,但它不扫描QR码。
我要去哪里错了。
我想您正在使用ZXing.NET包?
Mike Taulty在Windows 8.1上的“扫描”应用程序上撰写了整个博客文章系列,然后将其移植到Windows 10甚至在HoloLens上运行。 最后的帖子中还有一个小型配套应用程序,可在UWP上运行以进行简单扫描(语音命令该应用程序进行扫描)。
在该示例中,他正在使用以下方法:
ZXingQrCodeScanner.ScanFirstCameraForQrCode(
result =>
{
this.txtResult.Text = result?.Text ?? "none";
},
TimeSpan.FromSeconds(30));
假设系统上找到的第一个摄像头应用于QR码扫描,但是支持此操作的类将允许采用更灵活的方法,并且ScanFirstCameraForQrCode函数扩展为以下以下步骤
public static class ZXingQrCodeScanner
{
public static async void ScanFirstCameraForQrCode(
Action<Result> resultCallback,
TimeSpan timeout)
{
Result result = null;
var mediaFrameSourceFinder = new MediaFrameSourceFinder();
// We want a source of media frame groups which contains a color video
// preview (and we'll take the first one).
var populated = await mediaFrameSourceFinder.PopulateAsync(
MediaFrameSourceFinder.ColorVideoPreviewFilter,
MediaFrameSourceFinder.FirstOrDefault);
if (populated)
{
// We'll take the first video capture device.
var videoCaptureDevice =
await VideoCaptureDeviceFinder.FindFirstOrDefaultAsync();
if (videoCaptureDevice != null)
{
// Make a processor which will pull frames from the camera and run
// ZXing over them to look for QR codes.
var frameProcessor = new QrCaptureFrameProcessor(
mediaFrameSourceFinder,
videoCaptureDevice,
MediaEncodingSubtypes.Bgra8);
// Remember to ask for auto-focus on the video capture device.
frameProcessor.SetVideoDeviceControllerInitialiser(
vd => vd.Focus.TrySetAuto(true));
// Process frames for up to 30 seconds to see if we get any QR codes...
await frameProcessor.ProcessFramesAsync(timeout);
// See what result we got.
result = frameProcessor.QrZxingResult;
}
}
// Call back with whatever result we got.
resultCallback(result);
}
}
资源:
我希望这种方法可以帮助您前进。
您可以尝试我现成的解决方案: GitHub上的Barcode_Scanner_UWP
我试图通过VideoScanZXingWinRT存储库
他们俩都使用ZXing.Net,但是与旧的Mike Taulty 样本相比,它可以“即时”捕获QR。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.