I have recently found this zbar software that has yielded promising results when reading barcodes. It has the ability to decode a barcode from the command line. Since this is not an SDK or API. So, I did a trick to read barcodes from an image using a java program.
import java.io.*; public class BarCodeReader { public static void main(String args[]) { try { Process p=Runtime.getRuntime().exec("C:/Program Files/ZBar/bin/zbarimg D:/jpeg/006.jpg"); p.waitFor(); BufferedReader reader=new BufferedReader( new InputStreamReader(p.getInputStream()) ); String line=reader.readLine(); while(line!=null) { System.out.println(line); line=reader.readLine(); } } catch(IOException e1) {} catch(InterruptedException e2) {} System.out.println("Done"); } }
Hope this can be useful for anyone trying to read the barcode from an image in JAVA.
Note: it also works for Linux. I tested it. For linux environment you only need to execute this command.
sudo apt-get install zbar-tools
and in a Java program, change your code as follows:
Process p=Runtime.getRuntime().exec("zbarimg /opt/images/006.jpg");
And it works very well.
If you guys come across any other barcode reading SDK or API or software that can run on the command line, please leave a response.
source share