QR码网络摄像头扫描仪C# [英] QR code webcam scanner c#
问题描述
我尝试了各种 QR代码库和网络摄像头捕获技术.在特定时间间隔内捕获照片,然后将其发送到 QR code 库似乎是一个好主意,但是检测 QR code 的成功率却非常低.谁能推荐一种更好的方法来通过网络摄像头检测
I Have tried various QR code libraries and webcam capturing techniques. Capturing photos within a specific time interval and then sending it to the QR code library seemed as a good idea but the success ratio for detecting the QR code is extremely low. Could anyone recommend a better approach for detecting the QR code through webcam? Thanks a lot :)
代码:
void FinalVideo_NewFrame(对象发送者,NewFrameEventArgs eventArgs) {
void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) {
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = video;
try
{
com.google.zxing.qrcode.decoder.Decoder objDecoder = new com.google.zxing.qrcode.decoder.Decoder();
Bitmap bitmap = new Bitmap(pictureBox1.Image);
com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width,bitmap.Height);
var binarizer = new HybridBinarizer(source);
var binBitmap = new BinaryBitmap(binarizer);
QRCodeReader qrCodeReader = new QRCodeReader();
string str = new MultiFormatReader().decode(binBitmap).Text;
MessageBox.Show(str);
}
catch
{
}
}
我还使用了messages.toolkit.qrcode.dll. 代码如下:
I also used messaging.toolkit.qrcode.dll. The code follows:
private void mainWinForm_Load(对象发送者,EventArgs e)
private void mainWinForm_Load(object sender, EventArgs e)
{
webcam = new WebCam();
webcam.InitializeWebCam(ref imgVideo);
QRCodeDecoder decoder = new QRCodeDecoder();
try
{
MessageBox.Show(decoder.decode(new QRCodeBitmapImage(imgCapture.Image as Bitmap)));
}
catch
{
//Do nothing
}
}
推荐答案
尝试使用AForge.NET库从网络摄像头捕获视频,然后使用ZXing.Net库读取QR码.
Try using AForge.NET library for capturing the video from your webcam, and then ZXing.Net library for reading the QR codes.
您可以按照以下类似的Youtube教程进行操作,这些教程将展示如何使用AForge.Net从网络摄像头获取视频. https://www.youtube.com/watch?v=osAOpsRYqVs&t= 311s
You can follow some Youtube tutorials like these that will show how to get video from the webcam using AForge.Net . https://www.youtube.com/watch?v=osAOpsRYqVs&t=311s
对于QRs解码,我使用以下代码,每1秒执行一次:
As for the QRs decoding I used the following code which I execute every 1 second:
`
private void decode_QRtag()
{
try
{
//pictureBox1 shows the web cam video
Bitmap bitmap = new Bitmap(pictureBox1.Image);
BarcodeReader reader = new BarcodeReader { AutoRotate = true, TryHarder = true };
Result result = reader.Decode(bitmap);
string decoded = result.ToString().Trim();
//capture a snapshot if there is a match
PictureBox2.Image = bitmap;
textBox1.Text = decoded;
}
catch
{
}
}`
这篇关于QR码网络摄像头扫描仪C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!