mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
C++ port: update test binary with more flags and add barcode format names next to the enum for printing (right know the only way to tell what result->getBarcodeFormat() is is by comparing one by one against the enum entries.)
git-svn-id: https://zxing.googlecode.com/svn/trunk@1499 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
7bba1c4680
commit
0cfc8f2ab5
|
@ -20,3 +20,19 @@
|
|||
|
||||
#include <zxing/BarcodeFormat.h>
|
||||
|
||||
namespace zxing {
|
||||
|
||||
const char *barcodeFormatNames[] = {
|
||||
"None",
|
||||
"QR_CODE",
|
||||
"DATA_MATRIX",
|
||||
"UPC_E",
|
||||
"UPC_A",
|
||||
"EAN_8",
|
||||
"EAN_13",
|
||||
"CODE_128",
|
||||
"CODE_39",
|
||||
"ITF"
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,9 @@ namespace zxing {
|
|||
BarcodeFormat_CODE_39,
|
||||
BarcodeFormat_ITF
|
||||
} BarcodeFormat;
|
||||
|
||||
|
||||
/* if you update the enum, please update the name in BarcodeFormat.cpp */
|
||||
extern const char *barcodeFormatNames[];
|
||||
}
|
||||
|
||||
#endif // __BARCODE_FORMAT_H__
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <zxing/Exception.h>
|
||||
#include <zxing/common/IllegalArgumentException.h>
|
||||
#include <zxing/BinaryBitmap.h>
|
||||
#include <zxing/DecodeHints.h>
|
||||
|
||||
//#include <zxing/qrcode/detector/Detector.h>
|
||||
//#include <zxing/qrcode/detector/QREdgeDetector.h>
|
||||
|
@ -45,12 +46,15 @@ using namespace zxing;
|
|||
//using namespace zxing::qrcode;
|
||||
|
||||
static bool raw_dump = false;
|
||||
static bool show_format = false;
|
||||
static bool tryHarder = false;
|
||||
static bool show_filename = false;
|
||||
|
||||
static const int MAX_EXPECTED = 1024;
|
||||
|
||||
Ref<Result> decode(Ref<BinaryBitmap> image) {
|
||||
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints) {
|
||||
Ref<Reader> reader(new MultiFormatReader);
|
||||
return Ref<Result> (new Result(*reader->decode(image)));
|
||||
return Ref<Result> (new Result(*reader->decode(image, hints)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,7 +65,7 @@ int test_image(Image& image, bool hybrid, string expected = "") {
|
|||
|
||||
Ref<BitMatrix> matrix(NULL);
|
||||
Ref<Binarizer> binarizer(NULL);
|
||||
|
||||
const char* result_format = "";
|
||||
|
||||
try {
|
||||
Ref<MagickBitmapSource> source(new MagickBitmapSource(image));
|
||||
|
@ -72,9 +76,12 @@ int test_image(Image& image, bool hybrid, string expected = "") {
|
|||
binarizer = new GlobalHistogramBinarizer(source);
|
||||
}
|
||||
|
||||
DecodeHints hints(hints.DEFAULT_HINTS);
|
||||
hints.setTryHarder(tryHarder);
|
||||
Ref<BinaryBitmap> binary(new BinaryBitmap(binarizer));
|
||||
Ref<Result> result(decode(binary));
|
||||
Ref<Result> result(decode(binary, hints));
|
||||
cell_result = result->getText()->getText();
|
||||
result_format = barcodeFormatNames[result->getBarcodeFormat()];
|
||||
res = 0;
|
||||
} catch (ReaderException e) {
|
||||
cell_result = "zxing::ReaderException: " + string(e.what());
|
||||
|
@ -102,9 +109,14 @@ int test_image(Image& image, bool hybrid, string expected = "") {
|
|||
}
|
||||
|
||||
|
||||
if (raw_dump && !hybrid) /* don't print twice, and global is a bit better */
|
||||
cout << cell_result << endl;
|
||||
if (raw_dump && !hybrid) {/* don't print twice, and global is a bit better */
|
||||
cout << cell_result;
|
||||
if (show_format) {
|
||||
cout << " " << result_format;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -149,7 +161,7 @@ string get_expected(string imagefilename) {
|
|||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc <= 1) {
|
||||
cout << "Usage: " << argv[0] << " [--dump-raw] <filename1> [<filename2> ...]" << endl;
|
||||
cout << "Usage: " << argv[0] << " [--dump-raw] [--show-format] [--try-harder] [--show-filename] <filename1> [<filename2> ...]" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -170,8 +182,22 @@ int main(int argc, char** argv) {
|
|||
raw_dump = true;
|
||||
continue;
|
||||
}
|
||||
if (infilename.compare("--show-format") == 0) {
|
||||
show_format = true;
|
||||
continue;
|
||||
}
|
||||
if (infilename.compare("--try-harder") == 0) {
|
||||
tryHarder = true;
|
||||
continue;
|
||||
}
|
||||
if (infilename.compare("--show-filename") == 0) {
|
||||
show_filename = true;
|
||||
continue;
|
||||
}
|
||||
if (!raw_dump)
|
||||
cerr << "Processing: " << infilename << endl;
|
||||
if (show_filename)
|
||||
cout << infilename << " ";
|
||||
Image image;
|
||||
try {
|
||||
image.read(infilename);
|
||||
|
|
Loading…
Reference in a new issue