From 0cfc8f2ab55e80a7df47b5e9bade183bcae72159 Mon Sep 17 00:00:00 2001 From: flyashi Date: Thu, 29 Jul 2010 19:41:52 +0000 Subject: [PATCH] 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 --- cpp/core/src/zxing/BarcodeFormat.cpp | 16 +++++++++++ cpp/core/src/zxing/BarcodeFormat.h | 4 ++- cpp/magick/src/main.cpp | 40 +++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/cpp/core/src/zxing/BarcodeFormat.cpp b/cpp/core/src/zxing/BarcodeFormat.cpp index b31afccf1..7badb2abf 100755 --- a/cpp/core/src/zxing/BarcodeFormat.cpp +++ b/cpp/core/src/zxing/BarcodeFormat.cpp @@ -20,3 +20,19 @@ #include +namespace zxing { + +const char *barcodeFormatNames[] = { + "None", + "QR_CODE", + "DATA_MATRIX", + "UPC_E", + "UPC_A", + "EAN_8", + "EAN_13", + "CODE_128", + "CODE_39", + "ITF" +}; + +} diff --git a/cpp/core/src/zxing/BarcodeFormat.h b/cpp/core/src/zxing/BarcodeFormat.h index 943831dad..1be5c02dd 100644 --- a/cpp/core/src/zxing/BarcodeFormat.h +++ b/cpp/core/src/zxing/BarcodeFormat.h @@ -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__ diff --git a/cpp/magick/src/main.cpp b/cpp/magick/src/main.cpp index 2773c3351..ceb9cfcad 100644 --- a/cpp/magick/src/main.cpp +++ b/cpp/magick/src/main.cpp @@ -34,6 +34,7 @@ #include #include #include +#include //#include //#include @@ -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 decode(Ref image) { +Ref decode(Ref image, DecodeHints hints) { Ref reader(new MultiFormatReader); - return Ref (new Result(*reader->decode(image))); + return Ref (new Result(*reader->decode(image, hints))); } @@ -61,7 +65,7 @@ int test_image(Image& image, bool hybrid, string expected = "") { Ref matrix(NULL); Ref binarizer(NULL); - + const char* result_format = ""; try { Ref 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 binary(new BinaryBitmap(binarizer)); - Ref result(decode(binary)); + Ref 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] [ ...]" << endl; + cout << "Usage: " << argv[0] << " [--dump-raw] [--show-format] [--try-harder] [--show-filename] [ ...]" << 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);