So I’ve successfully access pixel data in a frame using the c++ frame access wrapper on the opencv webpage
template<class Frame>
class Frame_Data {
IplImage *imgp;
public:
Frame_Data (IplImage *img=0) {imgp = img;}
~Frame_Data () {imgp = 0;}
void operator=(IplImage *img) {imgp=img;}
inline Frame* operator[] (int rowIndex) {
return ((Frame*)(imgp->imageData + rowIndex*imgp->widthStep));
}
};
typedef struct {
unsigned char b,g,r;
} RgbPixel;
typedef struct {
float b,g,r;
} RgbPixelFloat;
typedef Frame_Data<RgbPixel> RgbImage;
Im then using 2 for loops to go through the frame pixel array such as:
for (int i = ymin; i < ymax; i++)
{
for (int j = xmin; j < xmax; j++)
{
int r = image[i][j].r;
int g = image[i][j].g;
int b = image[i][j].b;
So lets say I want to throw in an IF statement to check pixel data colors. I’ve seen some websites list them as stuff like
image[i][j].r=0xFF;
or if g < 0x20
Im not used to the hex looking values, i tried to look them up but can’t find any refernece, im used to cvscalars, so what do these mean? Like what does 0x20 stand for? or what about 0xFF?
thanks
The range from
0x00 ... 0xFFthat you are seeing is onebytewhich can hold a value between0 and 255which is how pixel color data is stored, generally in 3 or 4 bytes consisting of Red, Blue, Green and optionally Alpha.The
CvScalaris just a convenience container of 1, 2, 3 or 4 doubles which can be used to hold these values in a slightly different form.For example:
cv.RGB(1.0, 0.5, 0.3)sets the red component of the color to1.0 or 100%, the green component to0.5 or 50%and the blue component to0.3 or 30%. When the actual color structure is created each of these components will be made up of exactly onebyteso this is analagous to setting theR (red component) to
1.0 * 0xFF = 0xFFG (green component) to
0.5 * 0xFF = 0x7FB (blue component) to
0.3 * 0xFF = 0x26The alpha is automatically set to
1.0 or 0xFF