OpenCV中获取图像某一像素值
2011-07-13 15:03
281 查看
This is a basic example for the OpenCV.
First we must know the structure of IplImage:
IPL image:
IplImage
|-- int nChannels; // Number of color channels (1,2,3,4)
|-- int depth; // Pixel depth in bits:
| // IPL_DEPTH_8U, IPL_DEPTH_8S,
| // IPL_DEPTH_16U,IPL_DEPTH_16S,
| // IPL_DEPTH_32S,IPL_DEPTH_32F,
| // IPL_DEPTH_64F
|-- int width; // image width in pixels
|-- int height; // image height in pixels
|-- char* imageData; // pointer to aligned image data
| // Note that color images are stored in BGR order
|-- int dataOrder; // 0 - interleaved color channels,
| // 1 - separate color channels
| // cvCreateImage can only create interleaved images
|-- int origin; // 0 - top-left origin,
| // 1 - bottom-left origin (Windows bitmaps style)
|-- int widthStep; // size of aligned image row in bytes
|-- int imageSize; // image data size in bytes = height*widthStep
|-- struct _IplROI *roi;// image ROI. when not NULL specifies image
| // region to be processed.
|-- char *imageDataOrigin; // pointer to the unaligned origin of image data
| // (needed for correct image deallocation)
|
|-- int align; // Alignment of image rows: 4 or 8 byte alignment
| // OpenCV ignores this and uses widthStep instead
|-- char colorModel[4]; // Color model - ignored by OpenCV
//------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
IplImage *img=cvLoadImage("c://fruitfs.bmp",1);
CvScalar s;
for(int i=0;i<img->height;i++){
for(int j=0;j<img->width;j++){
s=cvGet2D(img,i,j); // get the (i,j) pixel value
printf("B=%f, G=%f, R=%f ",s.val[0],s.val[1],s.val[2]);
s.val[0]=111;
s.val[1]=111;
s.val[2]=111;
cvSet2D(img,i,j,s);//set the (i,j) pixel value
}
}
cvNamedWindow("Image",1);
cvShowImage("Image",img);
cvWaitKey(0); //等待按键
cvDestroyWindow( "Image" );//销毁窗口
cvReleaseImage( &img ); //释放图像
return 0;
}
First we must know the structure of IplImage:
IPL image:
IplImage
|-- int nChannels; // Number of color channels (1,2,3,4)
|-- int depth; // Pixel depth in bits:
| // IPL_DEPTH_8U, IPL_DEPTH_8S,
| // IPL_DEPTH_16U,IPL_DEPTH_16S,
| // IPL_DEPTH_32S,IPL_DEPTH_32F,
| // IPL_DEPTH_64F
|-- int width; // image width in pixels
|-- int height; // image height in pixels
|-- char* imageData; // pointer to aligned image data
| // Note that color images are stored in BGR order
|-- int dataOrder; // 0 - interleaved color channels,
| // 1 - separate color channels
| // cvCreateImage can only create interleaved images
|-- int origin; // 0 - top-left origin,
| // 1 - bottom-left origin (Windows bitmaps style)
|-- int widthStep; // size of aligned image row in bytes
|-- int imageSize; // image data size in bytes = height*widthStep
|-- struct _IplROI *roi;// image ROI. when not NULL specifies image
| // region to be processed.
|-- char *imageDataOrigin; // pointer to the unaligned origin of image data
| // (needed for correct image deallocation)
|
|-- int align; // Alignment of image rows: 4 or 8 byte alignment
| // OpenCV ignores this and uses widthStep instead
|-- char colorModel[4]; // Color model - ignored by OpenCV
//------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
IplImage *img=cvLoadImage("c://fruitfs.bmp",1);
CvScalar s;
for(int i=0;i<img->height;i++){
for(int j=0;j<img->width;j++){
s=cvGet2D(img,i,j); // get the (i,j) pixel value
printf("B=%f, G=%f, R=%f ",s.val[0],s.val[1],s.val[2]);
s.val[0]=111;
s.val[1]=111;
s.val[2]=111;
cvSet2D(img,i,j,s);//set the (i,j) pixel value
}
}
cvNamedWindow("Image",1);
cvShowImage("Image",img);
cvWaitKey(0); //等待按键
cvDestroyWindow( "Image" );//销毁窗口
cvReleaseImage( &img ); //释放图像
return 0;
}
相关文章推荐
- OpenCV中获取图像某一像素值
- OpenCV中获取图像某一像素值
- OpenCV中获取图像某一像素值
- opencv中获取和编辑图像像素值
- 使用OpenCV获取图像中某一点的像素值和修改某一点的像素值
- OpenCV对图像获取像素值方法总结
- opencv获取图像的像素值
- opencv利用鼠标获取图像的像素值
- 使用OpenCV获取图像中某一点的像素值和修改某一点的像素值
- Opencv获取图像上的像素值(Ubuntu版)
- opencv利用鼠标获取图像的像素值
- 用opencv读取图像的每个像素值,鼠标点击获取每一个点,并显示像素
- Opencv获取并改变图像的像素值
- OpenCV获取彩色图像某一通道的最大连通域
- Opencv获取图像上的像素值(win10系统)
- 利用opencv获取鼠标左键点击位置图像的像素值
- Opencv获取并改变图像的像素值
- opencv 图像像素点的值获取与显示
- 【OpenCV】OpenCV中获取图像的像素点并处理
- opencv获取图像像素值的两种方法