-
Notifications
You must be signed in to change notification settings - Fork 4
/
cvxImage_300.h
executable file
·184 lines (159 loc) · 3.95 KB
/
cvxImage_300.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#ifndef CVX_IMAGE_300_H
#define CVX_IMAGE_300_H 1
#include "opencv2/core/core.hpp"
#include "opencv2/core/core_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"
#include <iostream>
using std::ostream;
using std::endl;
using std::cout;
using cv::Mat;
namespace cvx
{
template<class T> class Image
{
inline friend ostream& operator<<(ostream& os, Image<T>& image)
{
if(image.m_imgp->nChannels != 1)
{
return os;
}
int height = image.m_imgp->height;
int width = image.m_imgp->width;
int x, y;
if(image.m_imgp->nChannels == 1)
{
for(y=0; y<height; ++y)
{
for(x=0; x<width; ++x)
{
os<<(T)image[y][x]<<" ";
}
os<<endl;
}
}
return os;
}
private:
const IplImage* m_imgp;
char ** m_row;
public:
Image(const IplImage* img = 0)
{
m_imgp = img;
m_row = new char *[m_imgp->height];
for (int i = 0; i<m_imgp->height; ++i) {
m_row[i] = m_imgp->imageData + i * m_imgp->widthStep;
}
}
~Image(){m_imgp = 0; delete []m_row;}
inline T* operator[](const int rowIndex)
{
return ((T*)(m_row[rowIndex]));
}
};
template<class T> class MatImage
{
private:
const Mat* m_matp;
unsigned char ** m_row;
public:
MatImage(const Mat* mat = 0)
{
assert(mat);
assert(!(mat->empty()));
assert(mat->dims == 2);
m_matp = mat;
m_row = new unsigned char *[m_matp->rows];
for (int i = 0; i<m_matp->rows; ++i) {
m_row[i] = m_matp->data + i * (m_matp->step.p[0]);
}
}
~MatImage(){m_matp = 0; delete []m_row;}
inline T* operator[](const int rowIndex)
{
return ((T*)(m_row[rowIndex]));
}
};
typedef struct{
unsigned char b,g,r;
}RgbPixel;
typedef struct{
unsigned char a,b,g,r;
}RgbaPixel;
typedef struct{
unsigned char b,g,r,a;
}ArgbPixel;
typedef struct{
short int b,g,r;
}RgbPixelShortInt;
typedef struct{
unsigned short int b,g,r;
}RgbPixelUShortInt;
typedef struct{
int b,g,r;
}RgbPixelInt;
typedef struct{
float b,g,r;
}RgbPixelFloat;
typedef struct {
unsigned char h,s,v;
}HsvPixel;
typedef struct {
unsigned char y, u, v;
}YuvPixel;
typedef struct{
float b,g,r,a;
}RgbaPixelFloat;
typedef struct{
unsigned char l,a,b;
}LabPixel;
/*color image*/
typedef Image<RgbPixel> RgbImage;
typedef Image<HsvPixel> HsvImage;
typedef Image<YuvPixel> YuvImage;
typedef Image<RgbPixelShortInt> RgbImageShortInt;
typedef Image<RgbPixelInt> RgbImageInt;
typedef Image<RgbPixelFloat> RgbImageFloat;
typedef Image<RgbaPixelFloat> RgbaImageFloat;
typedef Image<LabPixel> LabImage;
/*gray image*/
typedef Image<unsigned char> BwImage;
typedef Image<short int> BwImageShortInt;
typedef Image<float> BwImageFloat;
typedef Image<int> BwImageInt;
/*color mat image*/
typedef MatImage<RgbPixelUShortInt> Rgb16UImage;
typedef MatImage<unsigned short int> Bw16UImage;
typedef MatImage<short int> Bw16SImage;
typedef MatImage<RgbPixel> Rgb8UImage;
typedef MatImage<ArgbPixel> Argb8UImage;
typedef MatImage<unsigned char> Bw8UImage;
typedef MatImage<RgbPixelFloat> Rgb32FImage;
typedef MatImage<float> Bw32FImage;
typedef MatImage<double> Bw64FImage;
typedef MatImage<int> Bw32SImage;
typedef MatImage<HsvPixel> Hsv8UImage;
// typedef MatImage<RgbaPixel> Rgba8UImage;
/*6 3 7
2 x 0
5 1 4*/
typedef struct{
int d[8];
}ENeighborInt;
typedef struct{
int left;
int down;
int leftDown;
int rightDown;
}LrtdPixel;
/*eight neighborhood */
typedef Image<ENeighborInt> ENImageInt;
typedef Image<LrtdPixel> FNImageInt;
}
#endif