#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>
//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)));
}
Ref<BitMatrix> matrix(NULL);
Ref<Binarizer> binarizer(NULL);
-
+ const char* result_format = "";
try {
Ref<MagickBitmapSource> source(new MagickBitmapSource(image));
binarizer = new GlobalHistogramBinarizer(source);
}
+ DecodeHints hints(DecodeHints::DEFAULT_HINT);
+ 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());
}
- 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;
}
textfilename.replace(dotpos+1, textfilename.length() - dotpos - 1, "txt");
char data[MAX_EXPECTED];
FILE *fp = fopen(textfilename.data(), "rb");
-
+
+ if (!fp) {
+ // could not open file
+ return "";
+ }
// get file size
fseek(fp, 0, SEEK_END);
int toread = ftell(fp);
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;
}
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);