我尝试了各种QR 码库和网络摄像头捕获技术。在特定时间间隔内拍摄照片,然后将其发送到二维码库似乎是一个好主意,但检测到二维码的成功率极低。谁能推荐一种更好的方法来通过网络摄像头检测二维码?非常感谢 :)
代码:
void FinalVideo_NewFrame(对象发送者,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
{
}
}
我还使用了messaging.toolkit.qrcode.dll。代码如下:
private void mainWinForm_Load(对象发送者,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
}
}