如何从一个图像使用zxing库读取多个QR codeS [英] How to read multiple qr codes from one image using zxing library
问题描述
我目前正在开发一个扫描器读取多个QR codeS在一个图像中。 我设法读取QR codeS中的形象,但它给我不一致的结果。假设有4 QR codeS的形象,有时我能读2,有时3或者只是1.不像原来的扫描器(ZXing扫描仪),它去codeS快。虽然在我的情况,我必须确保有足够的光线和图像不模糊脱code吧。
我现在用的是 QR codeMultiReader
脱$ C C图像$。目前,使用 ZXing
库创建应用程序。
下面是我的code中的片段:
公共无效onPictureTaken(byte []的数据,摄像头摄像头){
BitmapFactory.Options选择=新BitmapFactory.Options();
opt.inMutable = TRUE;
点阵位图= BitmapFactory
.DE codeByteArray(数据,0,data.length,OPT);
哈希表<德codeHintType,对象>提示=新的Hashtable<德codeHintType,对象>();
hints.put(德codeHintType.TRY_HARDER,Boolean.TRUE);
LuminanceSource源=新RGBLuminanceSource(位);
QR codeMultiReader多读取=新的QR codeMultiReader();
结果[]结果= multiReader.de codeMultiple(新BinaryBitmap(
新HybridBinarizer(源)),提示);
}
我已创建了一个应用程序的相机,我已经使用意图
作为默认的摄像头应用程序是有每的Andriod操作系统,一般他们更好地为该设备优化的比写一个通用的相机应用这将只有你的手机进行优化......这样的相机更好的使用意图
。
有关从单一图像中提取多个QR我想下面的code。
但结果并不一致一段时间,我得到1或2或3出4一段时间没有....它不是完美的解决方案。
如果(照片== NULL)
返回;
位图ScaledQr = NULL;
ScaledQr = Bitmap.createScaledBitmap(照片,640,480,假);
BinaryBitmap Qr的= BitMap2BinayBitmap(ScaledQr);
结果[]ķpresultMulti = NULL;
结果ķpresultSingle = NULL;
哈希表<德codeHintType,对象>提示=新的Hashtable<德codeHintType,对象>();
hints.put(德codeHintType.TRY_HARDER,真正的);
//hints.put(De$c$cHintType.PURE_BAR$c$c,真正的);
尝试 {
ķpresultMulti = K preaderArr.de codeMultiple(QR,提示);
}赶上(NotFoundException E){
// TODO自动生成的catch块
msbox(异常,NotFoundException);
e.printStackTrace();
}
如果(K presultMulti!= NULL){
msbox(总结果,K presultMulti.length +); // + photo.getWidth()+高度=+ photo.getHeight());
对于(结果KP:K presultMulti)
{
msbox(结果,kp.getText());
}
}
I am currently developing a scanner that reads multiple QR codes found in one image. I manage to read the QR codes in the image but it's giving me inconsistent results. Assuming there are 4 QR codes in the image, sometimes I can read 2 and sometimes 3 or just 1. Unlike in the original scanner (ZXing Scanner) it decodes fast. While in my case, I have to make sure there is enough light and the image is not blurred to decode it.
I am using the QRCodeMultiReader
to decode the image. Currently using ZXing
Library to create the application.
Below is the snippet of my code:
public void onPictureTaken(byte[] data, Camera camera) {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inMutable = true;
Bitmap bitmap = BitmapFactory
.decodeByteArray(data, 0, data.length, opt);
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
LuminanceSource source = new RGBLuminanceSource(bitmap);
QRCodeMultiReader multiReader = new QRCodeMultiReader();
Result[] results = multiReader.decodeMultiple(new BinaryBitmap(
new HybridBinarizer(source)), hints);
}
i have created one app for camera i have used intent
as the default Camera app is there with every Andriod OS and generally they are better optimized for that device than writing a generic Camera app which would be optimized for your phone only...so for camera better use intent
.
For Extracting multiple QR from a Single image i tried the code below.
But results are not consistent some time I get 1 or 2 or 3 out of 4 some time none....its not perfect solution
if(photo == null)
return;
Bitmap ScaledQr = null;
ScaledQr = Bitmap.createScaledBitmap(photo, 640,480, false);
BinaryBitmap Qr = BitMap2BinayBitmap(ScaledQr);
Result [] kpResultMulti = null;
Result kpResultSingle = null;
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, true);
//hints.put(DecodeHintType.PURE_BARCODE, true);
try {
kpResultMulti = kpReaderArr.decodeMultiple(Qr,hints);
} catch (NotFoundException e) {
// TODO Auto-generated catch block
msbox("Exception","NotFoundException");
e.printStackTrace();
}
if(kpResultMulti != null){
msbox("Total Result" ,kpResultMulti.length +"");// + photo.getWidth() + "Height=" + photo.getHeight());
for(Result kp : kpResultMulti)
{
msbox("Results",kp.getText());
}
}
这篇关于如何从一个图像使用zxing库读取多个QR codeS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!