Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法识别彩色二维码,本地相册彩色二维码扫描不出来???提高扫描效率... #578

Open
deanhaiwei opened this issue Apr 26, 2023 · 7 comments

Comments

@deanhaiwei
Copy link

No description provided.

@wscjy
Copy link

wscjy commented Apr 26, 2023 via email

@deanhaiwei
Copy link
Author

ZXingView 可更新下

@deanhaiwei
Copy link
Author

rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new GlobalHistogramBinarizer(source)));
if (rawResult == null) {
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
if (rawResult != null) {
BGAQRCodeUtil.d("GlobalHistogramBinarizer 没识别到,HybridBinarizer 能识别到");
}
}

改成
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new GlobalHistogramBinarizer(source)));
if (rawResult == null) {
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
if (rawResult != null) {
BGAQRCodeUtil.d("GlobalHistogramBinarizer 没识别到,HybridBinarizer 能识别到");
}else{
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source.invert())));
}
}

rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source.invert())));加上这个可以识别彩色二维码

@deanhaiwei
Copy link
Author

识别的那段代码有问题!作者有空改下吧!
private Result getRawResult(Binarizer binarizer){
Result rawResult;
try {
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(binarizer));
}catch (Exception e){
rawResult = null;
}
return rawResult;
}

rawResult = getRawResult(new GlobalHistogramBinarizer(source));
if (rawResult == null) {
rawResult = getRawResult(new HybridBinarizer(source));
if (rawResult != null) {
BGAQRCodeUtil.d("GlobalHistogramBinarizer 没识别到,HybridBinarizer 能识别到");
}else {
rawResult = getRawResult(new HybridBinarizer(source.invert()));
}
}


rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new GlobalHistogramBinarizer(source)));
这段代码会报NotFoundException 异常
rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
这段就不生效了改完识别率会提高,还能识别彩色的二维码!

@dingliufan
Copy link

是的,下载源码 按照您这样改就可以,效率还变高了

@wscjy
Copy link

wscjy commented Dec 26, 2023 via email

@deanhaiwei deanhaiwei changed the title 无法识别彩色二维码 无法识别彩色二维码,效率不高... Oct 29, 2024
@deanhaiwei deanhaiwei changed the title 无法识别彩色二维码,效率不高... 无法识别彩色二维码,本地相册彩色二维码扫描不出来???提高扫描效率... Oct 29, 2024
@deanhaiwei
Copy link
Author

QRCodeDecoder 类中的这个方法

/**
* 同步解析bitmap二维码。该方法是耗时操作,请在子线程中调用。
*
* @param bitmap 要解析的二维码图片
* @return 返回二维码图片里的内容 或 null
*/
public static String syncDecodeQRCode(Bitmap bitmap) {
Result result;
RGBLuminanceSource source = null;
try {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
source = new RGBLuminanceSource(width, height, pixels);
result = new MultiFormatReader().decode(new BinaryBitmap(new GlobalHistogramBinarizer(source)), ALL_HINT_MAP);
return result.getText();
} catch (Exception e) {
e.printStackTrace();
if (source != null) {
try {
result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), ALL_HINT_MAP);
return result.getText();
} catch (Throwable e2) {
e2.printStackTrace();
try {
result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source.invert())), ALL_HINT_MAP);
return result.getText();
}catch (Exception e3){
e2.printStackTrace();
}
}
}
return null;
}
}

重点是和扫描的一样
result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source.invert()))
这样就能扫描到彩色的二维码不会返回null
source.invert() 这个是将 source 转换成了 InvertedLuminanceSource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants