下面的数据矩阵正在使用条形码扫描仪很好地读取,移动应用程序。但是,zxing库并不读取相同的内容。
我有一些图像转换代码注释了。甚至转换图像,旋转或缩放也没有帮助。
理想情况下,我想执行所有可能的图像预处理程序,直到解码.
移动应用程序使用的逻辑是什么,因为我从计算机屏幕上扫描相同的图像,而且它正在工作。
请找到下面的代码是用来解码的。
public class BarcodeReader {
private static Map<DecodeHintType,Object> hintsMap;
public static void main(String...args){
BufferedImage before = null;
hintsMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);
hintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
hintsMap.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class));
//hintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);
try
{
before = ImageIO.read(new File("C:/ocr.jpg"));
decode(before);
/* for(int i=1; i < 1000;i++){
AffineTransform transform = new AffineTransform();
double rad = (double)i/100;
double scale = (double)i/100;
System.out.println("rad "+scale);
//transform.rotate(rad, before.getWidth()/2, before.getHeight()/2);
transform.scale(scale, scale);
BufferedImage after = new BufferedImage(before.getWidth(), before.getHeight(), BufferedImage.TYPE_INT_ARGB);
AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
after = op.filter(before, after);
decode(after);
}*/
//tmpBfrImage = tmpBfrImage.getSubimage(200, 100, 800, 800);
}
catch (IOException tmpIoe)
{
tmpIoe.printStackTrace();
}
}
public static void decode(BufferedImage tmpBfrImage){
if (tmpBfrImage == null)
throw new IllegalArgumentException("Could not decode image.");
LuminanceSource tmpSource = new BufferedImageLuminanceSource(tmpBfrImage);
BinaryBitmap tmpBitmap = new BinaryBitmap(new HybridBinarizer(tmpSource));
MultiFormatReader tmpBarcodeReader = new MultiFormatReader();
Result tmpResult;
String tmpFinalResult;
try
{
if (hintsMap != null && ! hintsMap.isEmpty())
tmpResult = tmpBarcodeReader.decode(tmpBitmap, hintsMap);
else
tmpResult = tmpBarcodeReader.decode(tmpBitmap);
// setting results.
tmpFinalResult = String.valueOf(tmpResult.getText());
System.out.println(tmpFinalResult);
System.exit(0);;
}
catch (Exception tmpExcpt)
{
tmpExcpt.printStackTrace();
}
}
}

发布于 2016-07-20 09:48:51
我有多个层次的问题。我从github下载了zxing源代码并对其进行了调试。
hintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);出错。
在查看他们的DataMatrixReader源代码时,有一行代码这样做。
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE))
因此,不管将PURE_BARCODE设置为true还是false,它都认为它是真。理想情况下,提示不应包含密钥。
检测器通过观察每个顶点的黑白跃迁数来识别“L”。理想情况下,从左上角到左下角和左下角到右下角的转换应该有0转换.
然而,由于这条线被画得更靠近盒子的外部边缘,所以过渡没有变成0。我做了一些改变,把它移到左下角黑线的中心。这意味着向右移动垂直红线,并将红色底线向上移动。我增加了一个新的方法修正点,做了必要的修正。这种修正对我来说是有效的,理想情况下,应该让修正更聪明一些。
ResultPoint pointA = correctPoints(cornerPoints,Vertices.TOPLEFT);ResultPoint pointB = correctPoints(cornerPoints1,Vertices.BOTTOMLEFT);ResultPoint pointC = correctPoints(cornerPoints2,Vertices.TOPRIGHT);ResultPoint pointD =Vertices.TOPRIGHT(Vertices.TOPRIGHT,en19#);-私人(点,顶点){如果(())返回新(()+10,()+5);如果(vertice.equals(Vertices.BOTTOMLEFT)){返回新的ResultPoint(point.getX()+10,point.getY()-5);} if(vertice.equals(Vertices.TOPRIGHT)){返回新的ResultPoint(point.getX(),point.getY()+10);} else {返回新的ResultPoint(point.getX()-10,point.getY()-5);}}
在进行了这些更改之后,数据矩阵检测对像这些图像一样糟糕甚至更差的图像进行了检测。
发布于 2021-06-22 08:35:07
我在使用ZXing解码DataMatrix条形码时遇到了类似的问题。据我所见,ZXing并不遍历您发送的整个图像,而是从中间开始扩展,直到找到条形码。因此,如果DataMatrix条形码不在图像中心,ZXing将无法可靠地找到它。我通过创建不同的图像裁剪版本(相当慢)解决了这个问题:
我的核心解码方法类似于最初的文章。我的图像遍历逻辑如下:
// Read the original image
final BufferedImage image = ImageIO.read(...);
final int width = image.getWidth();
final int height = image.getHeight();
// Try detect codes using different sections of the image.
//
// +------+------+
// | ##|## |
// | ##|## |
// | ##|## |
// +------+------+
// | | |
// | | |
// | | |
// +------+------+
//
// We create 9 cropped versions of the image, with each cropped
// version being 1/4 of the original image. We traverse the
// original image from left-to-right, top-to-bottom, and create
// 9 sub-images that we try to decode in turn.
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
final int x = i * width / 4;
final int y = j * height / 4;
final BufferedImage crop = image.getSubimage(x, y, width / 2, height / 2);
decoded(crop);
}
}https://stackoverflow.com/questions/38437315
复制相似问题