5 * Created by Ralf Kistner on 16/10/2009.
6 * Copyright 2008 ZXing authors All rights reserved.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include "MagickBitmapSource.h"
26 #include <zxing/qrcode/QRCodeReader.h>
27 #include <zxing/common/GlobalHistogramBinarizer.h>
28 #include <zxing/common/LocalBlockBinarizer.h>
29 #include <zxing/Exception.h>
31 using namespace Magick;
33 using namespace zxing;
34 using namespace zxing::qrcode;
37 void decode_image(Image& image, bool localized) {
39 Ref<MagickBitmapSource> source(new MagickBitmapSource(image));
41 Ref<Binarizer> binarizer(NULL);
43 binarizer = new LocalBlockBinarizer(source);
45 binarizer = new GlobalHistogramBinarizer(source);
49 Ref<BinaryBitmap> image(new BinaryBitmap(binarizer));
51 Ref<Result> result(reader.decode(image));
53 cout << result->getText()->getText() << endl;
54 } catch (zxing::Exception& e) {
55 cerr << "Error: " << e.what() << endl;
60 int main(int argc, char** argv) {
62 cout << "Usage: " << argv[0] << "<filename1> [<filename2> ...]" << endl;
65 for (int i = 1; i < argc; i++) {
66 string infilename = argv[i];
67 cout << "Processing: " << infilename << endl;
70 image.read(infilename);
72 cerr << "Unable to open image, ignoring" << endl;
76 bool local = true; // Use local thresholding
78 decode_image(image, local);