-
Notifications
You must be signed in to change notification settings - Fork 3
/
zxingwrapper.h
101 lines (83 loc) · 2.48 KB
/
zxingwrapper.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
--------------------------------------------------------------------------------
- Module : zxingwrapper.h
- Description : Provides ability for easy use of OpenCV with Zxing-C++
- Author : G. Bradski, 2013
- Tim Zaman, 18-FEB-2016
--------------------------------------------------------------------------------
*/
/*
Copyright (c) 2013 G. Bradski
Copyright (c) 2016 Tim Zaman
Permission to use, copy, modify, distribute, and sell this software
for any purpose is hereby granted without fee, provided
that (i) the above copyright notices and this permission notice appear in
all copies of the software and related documentation.
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef ZXINGWRAPPER_H
#define ZXINGWRAPPER_H
#pragma once
#include <opencv2/opencv.hpp>
#include <zxing/LuminanceSource.h>
#include <zxing/MultiFormatReader.h>
#include <zxing/oned/OneDReader.h>
#include <zxing/oned/EAN8Reader.h>
#include <zxing/oned/EAN13Reader.h>
#include <zxing/oned/Code39Reader.h>
#include <zxing/oned/Code128Reader.h>
#include <zxing/datamatrix/DataMatrixReader.h>
#include <zxing/qrcode/QRCodeReader.h>
#include <zxing/aztec/AztecReader.h>
#include <zxing/common/GlobalHistogramBinarizer.h>
#include <zxing/Exception.h>
#include <zxing/common/GreyscaleLuminanceSource.h>
using namespace zxing;
using namespace oned;
using namespace datamatrix;
using namespace qrcode;
using namespace aztec;
class zxingwrapper : public LuminanceSource
{
private:
cv::Mat m_pImage;
public:
zxingwrapper(const cv::Mat &image) : LuminanceSource(image.cols, image.rows) {
m_pImage = image.clone();
}
~zxingwrapper(){
}
int getWidth() const {
return m_pImage.cols;
}
int getHeight() const {
return m_pImage.rows;
}
ArrayRef<char> getRow(int y, ArrayRef<char> row) const {
int width_ = getWidth();
if (!row){
row = ArrayRef<char>(width_);
}
const char *p = m_pImage.ptr<char>(y);
for(int x = 0; x<width_; ++x, ++p){
row[x] = *p;
}
return row;
}
ArrayRef<char> getMatrix() const {
int width_ = getWidth();
int height_ = getHeight();
ArrayRef<char> matrix = ArrayRef<char>(width_*height_);
for (int y = 0; y < height_; ++y){
const char *p = m_pImage.ptr<char>(y);
for(int x = 0; x < width_; ++x, ++p){
matrix[y*width_ + x] = *p;
}
}
return matrix;
}
};
//ZXINGWRAPPER_H
#endif