mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Improved the command line test app to accept multiple arguments, a --try_harder flag, and to skip hidden files and text files.
git-svn-id: https://zxing.googlecode.com/svn/trunk@371 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
a69a87e98d
commit
5079f361ac
|
@ -29,35 +29,61 @@ import java.net.URI;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Simply attempts to decode the barcode in the image indicated by the single argument
|
* <p>This simple command line utility decodes files, directories of files, or URIs which are passed
|
||||||
* to this program, which may be file or a URI. The raw text is printed.</p>
|
* as arguments. By default it uses the normal decoding algorithms, but you can pass --try_harder to
|
||||||
|
* request that hint. The raw text of each barcode is printed, and when running against directories,
|
||||||
|
* summary statistics are also displayed.</p>
|
||||||
*
|
*
|
||||||
* @author srowen@google.com (Sean Owen), dswitkin@google.com (Daniel Switkin)
|
* @author srowen@google.com (Sean Owen), dswitkin@google.com (Daniel Switkin)
|
||||||
*/
|
*/
|
||||||
public final class CommandLineRunner {
|
public final class CommandLineRunner {
|
||||||
|
|
||||||
|
private static Hashtable<DecodeHintType, Object> hints = null;
|
||||||
|
|
||||||
private CommandLineRunner() {
|
private CommandLineRunner() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
File inputFile = new File(args[0]);
|
for (int x = 0; x < args.length; x++) {
|
||||||
|
if (args[x].equals("--try_harder")) {
|
||||||
|
hints = new Hashtable<DecodeHintType, Object>(3);
|
||||||
|
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
||||||
|
} else if (args[x].startsWith("--")) {
|
||||||
|
System.out.println("Unknown command line option " + args[x]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int x = 0; x < args.length; x++) {
|
||||||
|
if (!args[x].startsWith("--")) {
|
||||||
|
decodeOneArgument(args[x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void decodeOneArgument(String argument) throws Exception {
|
||||||
|
File inputFile = new File(argument);
|
||||||
if (inputFile.exists()) {
|
if (inputFile.exists()) {
|
||||||
if (inputFile.isDirectory()) {
|
if (inputFile.isDirectory()) {
|
||||||
int successful = 0;
|
int successful = 0;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (File input : inputFile.listFiles()) {
|
for (File input : inputFile.listFiles()) {
|
||||||
|
String filename = input.getName().toLowerCase();
|
||||||
|
// Skip hidden files and text files (the latter is found in the blackbox tests).
|
||||||
|
if (filename.startsWith(".") || filename.endsWith(".txt")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (decode(input.toURI())) {
|
if (decode(input.toURI())) {
|
||||||
successful++;
|
successful++;
|
||||||
}
|
}
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
System.out.println("\nDecoded " + successful + " files out of " + total +
|
System.out.println("\nDecoded " + successful + " files out of " + total +
|
||||||
" successfully (" + (successful * 100 / total) + "%)");
|
" successfully (" + (successful * 100 / total) + "%)\n");
|
||||||
} else {
|
} else {
|
||||||
decode(inputFile.toURI());
|
decode(inputFile.toURI());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
decode(new URI(args[0]));
|
decode(new URI(argument));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +94,6 @@ public final class CommandLineRunner {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(3);
|
|
||||||
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
|
|
||||||
MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(image);
|
MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(image);
|
||||||
String result = new MultiFormatReader().decode(source, hints).getText();
|
String result = new MultiFormatReader().decode(source, hints).getText();
|
||||||
System.out.println(uri.toString() + ": " + result);
|
System.out.println(uri.toString() + ": " + result);
|
||||||
|
|
Loading…
Reference in a new issue