X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=javase%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fclient%2Fj2se%2FCommandLineRunner.java;h=8ac1de4d91e22bb5a7ebb59d5bb47df3157a0d04;hb=9aeefe94e7fe5485a83f16f4aa1997c610e5804f;hp=03ba804814e83282bfe50940e8b3c3bf6b9a2d98;hpb=25825519b9adc0034bcb2a4cce789550fc0600a7;p=zxing.git diff --git a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java index 03ba8048..8ac1de4d 100644 --- a/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java +++ b/javase/src/com/google/zxing/client/j2se/CommandLineRunner.java @@ -70,6 +70,7 @@ public final class CommandLineRunner { boolean productsOnly = false; boolean dumpResults = false; boolean dumpBlackPoint = false; + int[] crop = null; for (String arg : args) { if ("--try_harder".equals(arg)) { tryHarder = true; @@ -81,6 +82,12 @@ public final class CommandLineRunner { dumpResults = true; } else if ("--dump_black_point".equals(arg)) { dumpBlackPoint = true; + } else if (arg.startsWith("--crop")) { + crop = new int[4]; + String[] tokens = arg.substring(7).split(","); + for (int i = 0; i < crop.length; i++) { + crop[i] = Integer.parseInt(tokens[i]); + } } else if (arg.startsWith("-")) { System.err.println("Unknown command line option " + arg); printUsage(); @@ -91,7 +98,7 @@ public final class CommandLineRunner { Hashtable hints = buildHints(tryHarder, pureBarcode, productsOnly); for (String arg : args) { if (!arg.startsWith("--")) { - decodeOneArgument(arg, hints, dumpResults, dumpBlackPoint); + decodeOneArgument(arg, hints, dumpResults, dumpBlackPoint, crop); } } } @@ -106,6 +113,7 @@ public final class CommandLineRunner { vector.addElement(BarcodeFormat.UPC_E); vector.addElement(BarcodeFormat.EAN_13); vector.addElement(BarcodeFormat.EAN_8); + vector.addElement(BarcodeFormat.RSS14); if (!productsOnly) { vector.addElement(BarcodeFormat.CODE_39); vector.addElement(BarcodeFormat.CODE_128); @@ -128,13 +136,18 @@ public final class CommandLineRunner { System.err.println("Decode barcode images using the ZXing library\n"); System.err.println("usage: CommandLineRunner { file | dir | url } [ options ]"); System.err.println(" --try_harder: Use the TRY_HARDER hint, default is normal (mobile) mode"); + System.err.println(" --pure_barcode: Input image is a pure monochrome barcode image, not a photo"); System.err.println(" --products_only: Only decode the UPC and EAN families of barcodes"); System.err.println(" --dump_results: Write the decoded contents to input.txt"); System.err.println(" --dump_black_point: Compare black point algorithms as input.mono.png"); + System.err.println(" --crop=left,top,width,height: Only examine cropped region of input image(s)"); } - private static void decodeOneArgument(String argument, Hashtable hints, - boolean dumpResults, boolean dumpBlackPoint) throws IOException, + private static void decodeOneArgument(String argument, + Hashtable hints, + boolean dumpResults, + boolean dumpBlackPoint, + int[] crop) throws IOException, URISyntaxException { File inputFile = new File(argument); @@ -152,7 +165,7 @@ public final class CommandLineRunner { if (filename.contains(".mono.png")) { continue; } - Result result = decode(input.toURI(), hints, dumpBlackPoint); + Result result = decode(input.toURI(), hints, dumpBlackPoint, crop); if (result != null) { successful++; if (dumpResults) { @@ -164,13 +177,13 @@ public final class CommandLineRunner { System.out.println("\nDecoded " + successful + " files out of " + total + " successfully (" + (successful * 100 / total) + "%)\n"); } else { - Result result = decode(inputFile.toURI(), hints, dumpBlackPoint); + Result result = decode(inputFile.toURI(), hints, dumpBlackPoint, crop); if (dumpResults) { dumpResult(inputFile, result); } } } else { - decode(new URI(argument), hints, dumpBlackPoint); + decode(new URI(argument), hints, dumpBlackPoint, crop); } } @@ -193,8 +206,10 @@ public final class CommandLineRunner { } } - private static Result decode(URI uri, Hashtable hints, - boolean dumpBlackPoint) throws IOException { + private static Result decode(URI uri, + Hashtable hints, + boolean dumpBlackPoint, + int[] crop) throws IOException { BufferedImage image; try { image = ImageIO.read(uri.toURL()); @@ -206,7 +221,12 @@ public final class CommandLineRunner { return null; } try { - LuminanceSource source = new BufferedImageLuminanceSource(image); + LuminanceSource source; + if (crop == null) { + source = new BufferedImageLuminanceSource(image); + } else { + source = new BufferedImageLuminanceSource(image, crop[0], crop[1], crop[2], crop[3]); + } BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); if (dumpBlackPoint) { dumpBlackPoint(uri, image, bitmap);