1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| #include <iostream>
#include <stdlib.h>
#include <stdint.h>
#include <fstream>
#include <string>
#include <zxing/qrcode/QRCodeReader.h>
#include <zxing/Exception.h>
#include <zxing/common/GlobalHistogramBinarizer.h>
#include <zxing/DecodeHints.h>
#include "BufferBitmapSource.h"
using namespace std;
using namespace zxing;
using namespace zxing::qrcode;
using namespace qrviddec;
int main(int argc, char ** argv)
{
try
{
// A buffer containing an image. In your code, this would be an image from your camera. In this
// example, it's just an array containing the code for "Hello!".
uint8_t buffer[] =
{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255, 0 , 0 , 0 , 0 , 0 , 255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255,
255, 0 , 255, 255, 255, 255, 255, 0 , 255, 255, 0 , 255, 0 , 255, 255, 0 , 255, 255, 255, 255, 255, 0 , 255,
255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255, 255, 0 , 0 , 255, 255, 255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255,
255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255, 255, 0 , 0 , 0 , 255, 255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255,
255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255, 255, 255, 0 , 255, 0 , 255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255,
255, 0 , 255, 255, 255, 255, 255, 0 , 255, 255, 255, 255, 0 , 0 , 255, 0 , 255, 255, 255, 255, 255, 0 , 255,
255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255, 0 , 255, 0 , 255, 0 , 255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 0 , 0 , 0 , 0 , 0 , 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 0 , 0 , 255, 0 , 0 , 255, 0 , 255, 255, 0 , 0 , 255, 0 , 255, 0 , 255, 255, 255, 255, 255, 0 , 255,
255, 0 , 0 , 0 , 0 , 0 , 255, 255, 0 , 255, 255, 0 , 255, 0 , 255, 0 , 255, 0 , 0 , 0 , 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 0 , 255, 0 , 0 , 0 , 255, 255, 0 , 0 , 255, 0 , 255, 0 , 0 , 0 , 255,
255, 255, 255, 0 , 0 , 255, 255, 255, 0 , 0 , 0 , 255, 0 , 255, 255, 255, 255, 255, 255, 0 , 255, 255, 255,
255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255, 255, 0 , 255, 255, 255, 255, 0 , 255, 255, 0 , 255, 0 , 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 0 , 0 , 255, 0 , 0 , 255, 255, 255, 255, 0 , 255, 0 , 0 , 255,
255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255, 255, 255, 0 , 255, 0 , 0 , 0 , 0 , 0 , 255, 0 , 255, 255, 255,
255, 0 , 255, 255, 255, 255, 255, 0 , 255, 255, 0 , 0 , 0 , 0 , 0 , 255, 0 , 0 , 0 , 0 , 255, 255, 255,
255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255, 0 , 255, 255, 0 , 0 , 255, 0 , 0 , 255, 0 , 255, 0 , 0 , 255,
255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255, 0 , 255, 0 , 0 , 0 , 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 0 , 255, 0 , 0 , 0 , 255, 0 , 255, 255, 0 , 0 , 255, 255, 255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255,
255, 0 , 255, 255, 255, 255, 255, 0 , 255, 0 , 255, 0 , 255, 255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255,
255, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255, 0 , 255, 0 , 0 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
};
int width = 23;
int height = 23;
// Convert the buffer to something that the library understands.
Ref<LuminanceSource> source (new BufferBitmapSource(width, height, buffer));
// Turn it into a binary image.
Ref<Binarizer> binarizer (new GlobalHistogramBinarizer(source));
Ref<BinaryBitmap> image(new BinaryBitmap(binarizer));
// Tell the decoder to try as hard as possible.
DecodeHints hints(DecodeHints::DEFAULT_HINT);
hints.setTryHarder(true);
// Perform the decoding.
QRCodeReader reader;
Ref<Result> result(reader.decode(image, hints));
// Output the result.
cout << result->getText()->getText() << endl;
}
catch (zxing::Exception& e)
{
cerr << "Error: " << e.what() << endl;
}
return 0;
} |
Partager