简体   繁体   English

使用zxing.net扫描多个条形码

[英]Scan multiple barcodes with zxing.net

My aim is to detect multiple datamatrices on a larger image like this (the four big): 我的目标是在像这样的大图像上检测多个数据矩阵(四大):

完整的图像

Based on several code samples, I made a small test program: 基于几个代码示例,我做了一个小测试程序:

Bitmap image = getImage();

DataMatrixReader reader = new DataMatrixReader();
GenericMultipleBarcodeReader genericReader = new genericMultipleBarcodeReader(reader);
Dictionary<DecodeHintType, object> hints = new Dictionary<DecodeHintType,object>();
hints.Add(DecodeHintType.TRY_HARDER, true);

BitmapLuminanceSource source = new BitmapLuminanceSource(image);
HybridBinarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Result[] results = genericReader.decodeMultiple(binaryBitmap,hints);

show(results);

It could'nt detect any code on the large image. 它无法检测到大图像上的任何代码。

But it can detect the code, when its cropped like that: 但它可以检测到代码,当它被裁剪时:

裁剪

After that I merged two generated data matrices, and it failed too: 之后我合并了两个生成的数据矩阵,它也失败了:

在此输入图像描述

Last I ran two more test with slightly cropped images, both failed: 最后我用略微裁剪的图片再进行了两次测试,两次都失败了:

在此输入图像描述

在此输入图像描述

So it seems this library is not robust at all, or maybe I use it wrong. 所以看起来这个库根本不健壮,或者我使用它错了。

Any idea how to improve my results? 知道如何改善我的结果吗? (including other libraries and preprocessing) (包括其他库和预处理)

It can't be said that the library is not robust but there are two key factors affecting you here: 不能说图书馆不健壮,但这里有两个影响你的关键因素:

  • Zxing's data-matrix detection algorithm assumes that the barcode is centered. Zxing的数据矩阵检测算法假设条形码居中。 Or more precisely, that the center of the image is inside the data-matrix. 或者更确切地说,图像的中心在数据矩阵内。
  • Zxing's multiple reader specially fails when barcodes are grid-aligned. 当条形码与网格对齐时,Zxing的多个阅读器特别失败。

My recommendation is to implement your own MultipleBarcodeReader taking into account what I've mentioned. 我的建议是考虑到我提到的内容,实现你自己的MultipleBarcodeReader

A naive approach could be to take sample images centered over a grid of points spaced so every data-matrix (no matter its position within the image) contain at least one of the points inside. 一种天真的方法可以是将样本图像置于以间隔的网格为中心,使得每个数据矩阵(无论其在图像内的位置)包含内部的至少一个点。 You just have to make sure to exclude duplicated codes. 您只需确保排除重复的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM