[SCM] Multi-format 1D/2D barcode image processing library branch, upstream, updated. 24d4480bc48cf9eabf7b2bd2f528248b0e458809
flyashi
flyashi at 59b500cc-1b3d-0410-9834-0bbf25fbcc57
Wed Aug 4 01:32:39 UTC 2010
The following commit has been merged in the upstream branch:
commit cc0ae3ad51897f0ec4c52762c52bea3fe3acb8b5
Author: flyashi <flyashi at 59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Date: Thu Jul 29 19:41:52 2010 +0000
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: http://zxing.googlecode.com/svn/trunk@1499 59b500cc-1b3d-0410-9834-0bbf25fbcc57
diff --git a/cpp/core/src/zxing/BarcodeFormat.cpp b/cpp/core/src/zxing/BarcodeFormat.cpp
index b31afcc..7badb2a 100755
--- a/cpp/core/src/zxing/BarcodeFormat.cpp
+++ b/cpp/core/src/zxing/BarcodeFormat.cpp
@@ -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"
+};
+
+}
diff --git a/cpp/core/src/zxing/BarcodeFormat.h b/cpp/core/src/zxing/BarcodeFormat.h
index 943831d..1be5c02 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 2773c33..ceb9cfc 100644
--- a/cpp/magick/src/main.cpp
+++ b/cpp/magick/src/main.cpp
@@ -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);
--
Multi-format 1D/2D barcode image processing library
More information about the Pkg-google-commits
mailing list