当然,这取决于您使用它的目的。即使是 Java 版本的 zxing 也存在一些重要的限制和性能问题。例如,它只能在一页上找到一个条形码。此外,它用于在页面上定位一维条形码的算法并不是特别有效(不知道二维条形码的算法 - 这不是我正在从事的项目的要求的一部分)。这些都是可以解决的问题 - 我在几个月前开始了增强,并且能够显着提高一维定位性能和可靠性,但我们的开发优先级已经发生了变化,所以从那以后我就没有再处理它。
至于部分移植到 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; // i.e. 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
那么 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){
...
}
Run Code Online (Sandbox Code Playgroud)
最终,这应该是可以通过 DecodeHintType 设置的东西,但我们发现,在我们可以使用的每种情况下,渐进策略都比旧策略更快(而且不仅仅是快一点 -快得多)。
| 归档时间: |
|
| 查看次数: |
4868 次 |
| 最近记录: |