1 template<class T> class Image 2 { 3 private: 4 IlpImage *imgp; 5 public: 6 Image(IplImage* img = 0) 7 { 8 imgp = img; 9 } 10 inline T* operator[](const int rowIndx) 11 { 12 return( (T*)(imgp ->imageData + rowIndx * imgp ->widthStep)); 13 } 14 }; 15 16 typedef struct { 17 unsigned char b, g, r; 18 }RgbPixel; 19 20 typedef struct { 21 float b, g, r; 22 }RgbPixelFloat; 23 24 typedef Image<RgbPixel> RgbImage; 25 typedef Imgae<RgbPixelFloat> RgbImageFloat; 26 typedef Image<unsigned char> BwImage; 27 typedef Image<float> BwImageFloat;
例:对3通道的字节型图像访问如下:
1 IplImage* img = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 3); 2 RgbImage imgA(img); 3 //假设访问第K通道、第i行、第j列的像素 4 imgA[i][j].b = 111; 5 imgA[i][j].g = 111; 6 imgA[i][j].r = 111;
|
请发表评论