X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=cpp%2Fmagick%2Fsrc%2Fmain.cpp;fp=cpp%2Fmagick%2Fsrc%2Fmain.cpp;h=292984d3248e45de6c4731e79f622cc4daed54f9;hb=305aa7b260184b41bc3a43d101fcd1835335e825;hp=65be40cecea76509e5b111e9a9e536d2eefefa0b;hpb=3e495a1b7f96cb3994694b49f255c8d67cbe2f20;p=zxing.git diff --git a/cpp/magick/src/main.cpp b/cpp/magick/src/main.cpp index 65be40ce..292984d3 100644 --- a/cpp/magick/src/main.cpp +++ b/cpp/magick/src/main.cpp @@ -4,6 +4,7 @@ * * Created by Ralf Kistner on 16/10/2009. * Copyright 2008 ZXing authors All rights reserved. + * Modified by Yakov Okshtein (flyashi@gmail.com) to add 1D barcode support. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,10 +26,12 @@ #include "MagickBitmapSource.h" #include #include +#include +#include #include #include #include -#include +//#include #include #include #include @@ -106,28 +109,14 @@ void save_grid(Ref matrix, string filename, Ref image.write(filename); } -Ref decode(string out_prefix, Ref image, string& cell_grid, string& cell_transformed) { +Ref decode2D(string out_prefix, Ref image, string& cell_grid, string& cell_transformed) { + Decoder decoder; QREdgeDetector detector = QREdgeDetector(image->getBlackMatrix()); Ref detectorResult(detector.detect()); - if (out_prefix.size()) { - // Grid image - string gridfile = out_prefix + ".grid.gif"; - Ref transform = detectorResult->getTransform(); - int dimension = detectorResult->getBits()->getDimension(); - save_grid(image->getBlackMatrix(), gridfile, transform, dimension); - cell_grid = ""; - - // Transformed image - string tfile = out_prefix + ".transformed.png"; - save_matrix(detectorResult->getBits(), tfile, 5); - cell_transformed = ""; - } - - vector > points(detectorResult->getPoints()); Ref decoderResult(decoder.decode(detectorResult->getBits())); @@ -136,11 +125,26 @@ Ref decode(string out_prefix, Ref image, string& cell_grid decoderResult->getRawBytes(), points, BarcodeFormat_QR_CODE)); - return result; + } +Ref decode1D(string out_prefix, Ref image, string& cell_grid, string& cell_transformed) { + + + Ref reader(new oned::MultiFormatUPCEANReader); + Ref result(new Result(*reader->decode(image))); + return result; +} +//TODO(flyashi): Call MultiFormatReader directly +Ref decode(string out_prefix, Ref image, string& cell_grid, string& cell_transformed) { + try { + return decode1D(out_prefix,image,cell_grid,cell_transformed); + } catch (ReaderException re) { + return decode2D(out_prefix,image,cell_grid,cell_transformed); + } +} int test_image(Image& image, string out_prefix, bool localized) { @@ -159,7 +163,7 @@ int test_image(Image& image, string out_prefix, bool localized) { Ref source(new MagickBitmapSource(image)); if (localized) { - binarizer = new LocalBlockBinarizer(source); + //binarizer = new LocalBlockBinarizer(source); } else { binarizer = new GlobalHistogramBinarizer(source); } @@ -167,7 +171,7 @@ int test_image(Image& image, string out_prefix, bool localized) { if (out_prefix.size()) { string monofile = out_prefix + ".mono.png"; matrix = binarizer->getBlackMatrix(); - save_matrix(matrix, monofile); + //save_matrix(matrix, monofile); cell_mono = ""; } @@ -190,10 +194,8 @@ int test_image(Image& image, string out_prefix, bool localized) { res = -5; } - cout << "" << cell_mono << "" << endl; - cout << "" << cell_grid << "" << endl; - cout << "" << cell_transformed << "" << endl; - cout << "" << cell_result << "" << endl; + cout << cell_result; + return res; } @@ -213,16 +215,15 @@ int main(int argc, char** argv) { } string outfolder = argv[1]; - int total = argc - 2; + // int total = argc - 2; int gonly = 0; int lonly = 0; int both = 0; int neither = 0; - cout << "" << endl; for (int i = 2; i < argc; i++) { string infilename = argv[i]; - cerr << "Processing: " << infilename << endl; +// cerr << "Processing: " << infilename << endl; Image image; try { image.read(infilename); @@ -230,10 +231,6 @@ int main(int argc, char** argv) { cerr << "Unable to open image, ignoring" << endl; continue; } - cout << "" << endl; - cout << "" << endl; - - cout << "" << endl; int gresult = 1; @@ -241,36 +238,23 @@ int main(int argc, char** argv) { if (outfolder == string("-")) { gresult = test_image_global(image, ""); - lresult = test_image_local(image, ""); +// lresult = test_image_local(image, ""); } else { replace(infilename.begin(), infilename.end(), '/', '_'); string prefix = string(outfolder) + string("/") + infilename; gresult = test_image_global(image, prefix + ".g"); - lresult = test_image_local(image, prefix + ".l"); + // lresult = test_image_local(image, prefix + ".l"); } gresult = gresult == 0; - lresult = lresult == 0; + // lresult = lresult == 0; gonly += gresult && !lresult; lonly += lresult && !gresult; both += gresult && lresult; neither += !gresult && !lresult; - cout << "" << endl; } - cout << "
" << infilename << "
" << endl; - - cout << "" << endl; - cout << "" << endl; - cout << "" << endl; - cout << "" << endl; - cout << "" << endl; - cout << "" << endl; - - cout << "
Total" << total << "
Both correct" << both << "
Neither correct" << neither << "
Global only" << gonly << "
Local only" << lonly << "
" << endl; - cout << "" << endl; - return 0; }