Hi i have tried to read a barcode from image using below code but i am unable to read the file as it contains multiple barcodes. Is there any work around for this?
@GetMapping(value = "OCR/Apachecamel")
@ApiOperation(value = "Get result from Barcode Apachecamel library")
public BarcodeInfo GetApachecamelResult() throws Exception {
try {
InputStream barCodeInputStream = new FileInputStream("images/multiple.png");
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
new BufferedImageLuminanceSource(ImageIO.read(barCodeInputStream))));
if (bitmap.getWidth() < bitmap.getHeight()) {
if (bitmap.isRotateSupported()) {
bitmap = bitmap.rotateCounterClockwise();
}
}
return decode(bitmap);
} catch (IOException e) {
throw new BarcodeDecodingException(e);
}
}
private BarcodeInfo decode(BinaryBitmap bitmap) throws BarcodeDecodingException {
Reader reader = new MultiFormatReader();
try {
Result result = reader.decode(bitmap);
return new BarcodeInfo(result.getText(), result.getBarcodeFormat().toString());
} catch (Exception e) {
throw new BarcodeDecodingException(e);
}
}
public static class BarcodeInfo {
private final String text;
private final String format;
public String getText() {
return text;
}
public String getFormat() {
return format;
}
BarcodeInfo(String text, String format) {
this.text = text;
this.format = format;
}
}
public static class BarcodeDecodingException extends Exception {
BarcodeDecodingException(Throwable cause) {
super(cause);
}
}
pom.xml
<!-- https://mvnrepository.com/artifact/org.apache.camel/camel-barcode -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-barcode</artifactId>
<version>2.21.1</version>
</dependency>
Error
Image enclosed
Could some one let me know is there any workaround for this? Thanks in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…