CX中的ZXing(“Zebra Crossing”)

我正在寻找一个好的开源库,可以从图像中找到并读取条形码(与使用条形码扫描仪相比)。 从Stack Overflow的其他问题来看,我发现ZXing (“Zebra Crossing”)非常好。 虽然它是为Java制作的,但是有一个C#端口 – 但是,我相信它可能不完整。 你认为它是否足够可靠来解析这种情况下的条形码,还是其他一些库更好?

编辑:正如Ed在评论中指出的那样,我应该先尝试一下。 哇,我没想到。 :)但我想我的问题是部分端口是否足够可靠 – 如果你以前有人使用它,它能否熟练扫描?

当然,这取决于你使用它的是什么。 即使Java版本的zxing也有一些重要的局限性和性能问题。 例如,它只能在页面上找到一个条形码。 此外,它用于在页面上定位1-D条形码的算法效率不高(不知道2-D条形码的算法 – 这不是我正在研究的项目要求的一部分)。 这是可以解决的所有问题 – 几个月前我开始进行了一项改进,并且能够显着提高一维位置性能和可靠性,但是我们的开发优先级已经发生了变化,所以我从那时起就没有开始工作。

至于C#的部分端口是否良好,如果你想回复差异,我很乐意发表评论。

编辑 – 这是我做的一些重构:

首先,将RowNumberStrategy分解如下:

public interface RowNumberStrategy { public int getNextRowNumber(); public class OriginalRowStrategy implements RowNumberStrategy{ int middle; boolean tryHarder = false; int rowStep; int maxLines; int maxRows; int x; public OriginalRowStrategy(int maxRows, boolean tryHarder) { this.x = 0; this.maxRows = maxRows; this.middle = maxRows >> 1; // divide by 2 this.tryHarder = tryHarder; rowStep = Math.max(1, maxRows >> (tryHarder ? 7 : 4)); if (tryHarder) { maxLines = maxRows; // Look at the whole image, not just the center } else { maxLines = 9; // Nine rows spaced 1/16 apart is roughly the middle half of the image } } public int getNextRowNumber() { if (x > maxLines) return -1; int rowStepsAboveOrBelow = (x + 1) >> 1; boolean isAbove = (x & 0x01) == 0; // ie is x even? int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow); if (rowNumber < 0 || rowNumber >= maxRows) { // Oops, if we run off the top or bottom, stop return -1; } x = x + 1; return rowNumber; } } public class LinearScanRowStrategy implements RowNumberStrategy{ private final int maxRows; private int currentRow; public LinearScanRowStrategy(int totalRows) { maxRows = totalRows; currentRow = 0; } public int getNextRowNumber() { if (currentRow > maxRows) return -1; return maxRows - 1 - currentRow++; } } public class ProgressiveScanRowStrategy implements RowNumberStrategy{ private final int maxRows; private int currentStepSize; private int currentStep; public ProgressiveScanRowStrategy(int totalRows) { maxRows = totalRows; currentStep = 0; currentStepSize = maxRows; } public int getNextRowNumber() { int nextRow = (currentStep++) * currentStepSize; if (nextRow < maxRows) return nextRow; currentStepSize = currentStepSize >> 1; if (currentStepSize <= 0) return -1; currentStep = 1; nextRow = currentStep * currentStepSize; return nextRow; } } } 

那么doDecode的顶部变成如下:

 private Result doDecode(MonochromeBitmapSource image, Hashtable hints) throws ReaderException { int width = image.getWidth(); int height = image.getHeight(); BitArray row = new BitArray(width); boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); RowNumberStrategy rowProvider = new RowNumberStrategy.ProgressiveScanRowStrategy(height); int rowNumber; while ((rowNumber = rowProvider.getNextRowNumber()) != -1){ ... } 

最终,这应该是可以通过DecodeHintType设置的东西,但是我们发现渐进式策略比我们可以抛出它的每种情况都要快(而且不仅仅是更快 - 更快)。

我已经使用java版本超过一年,每天扫描大约100,它的效果很好。 我认为没有理由认为c#版本会更糟。

尝试使用ikvmc编译java版本,然后从C#代码访问它。