-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathIndividualPixels.h
86 lines (71 loc) · 2.35 KB
/
IndividualPixels.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
/*
* Copyright 2009-2010, Andrew Barry
*
* This file is part of MakerScanner.
*
* MakerScanner is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (Version 2, June 1991) as published by
* the Free Software Foundation.
*
* MakerScanner is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INDIVIDUAL_PIXELS
#define INDIVIDUAL_PIXELS
#ifndef OPENCV_INCLUDES
#define OPENCV_INCLUDES
#include "cv.h"
#include "highgui.h"
#endif // OPENCV_INCLUDES
/*
* Standard code for getting individual pixel access -- RgbImage, BwImage, RgbImage Float, and BwImageFloat
* Nothing especailly novel here...
*/
template<class T> class Pixels
{
private:
IplImage* imgp;
public:
Pixels(IplImage* img=0) {imgp=img;}
~Pixels(){imgp=0;}
void operator=(IplImage* img) {imgp=img;}
inline T* operator[](const int rowIndx) {
return ((T *)(imgp->imageData + rowIndx*imgp->widthStep));}
};
typedef struct{
unsigned char b,g,r;
} RgbPixel;
typedef struct{
float b,g,r;
} RgbPixelFloat;
typedef Pixels<RgbPixel> RgbImage;
typedef Pixels<RgbPixelFloat> RgbImageFloat;
typedef Pixels<unsigned char> BwImage;
typedef Pixels<float> BwImageFloat;
#endif // INDIVIDUAL_PIXELS
/* How to use this class
// refer to individual pixels as shown below.
// when they are changed in the class's image, they change in the parameter image as well.
// http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00053000000000000000
# For a single-channel byte image:
IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
BwImage imgA(img);
imgA[i][j] = 111;
# For a multi-channel byte image:
IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3);
RgbImage imgA(img);
imgA[i][j].b = 111;
imgA[i][j].g = 111;
imgA[i][j].r = 111;
# For a multi-channel float image:
IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3);
RgbImageFloat imgA(img);
imgA[i][j].b = 111;
imgA[i][j].g = 111;
imgA[i][j].r = 111;
*/