opencv像素操作

1–bit_depth—比特数—代表8bite,16bites,32bites,64bites—举个例子吧–比如说,如
如果你现在创建了一个存储–灰度图片的Mat对象,这个图像的大小为宽100,高100,那么,现在这张
灰度图片中有10000个像素点,它每一个像素点在内存空间所占的空间大小是8bite,8位–所以它对
应的就是CV_8
2–S|U|F–S–代表—signed int—有符号整形
U–代表–unsigned int–无符号整形
F–代表–float———单精度浮点型
3–C—-代表—一张图片的通道数,比如:
1–灰度图片–grayImg—是–单通道图像
2–RGB彩色图像———是–3通道图像
3–带Alph通道的RGB图像–是–4通道图像

如果使用的是uchar则使用Vec3b
如果使用的是float则使用Vec3f

float d = matDepthImage.at(row, col);

p.r = matRGBImage.ptr(row)[col * 3];
p.g = matRGBImage.ptr(row)[col * 3 + 1];
p.b = matRGBImage.ptr(row)[col * 3 + 2];

cv::Mat image = cv::imread(“Q:\test.jpg”, CV_LOAD_IMAGE_COLOR);
for(int k = 0; k < 1000; k++)
{
int i = rand() % image.cols;
int j = rand() % image.rows;
image.at(i, j)[0] = 255;
image.at(i, j)[1] = 255;
image.at(i, j)[2] = 255;
}

cv::Mat_ ima = image;
cv::namedWindow(“Origin image”, cv::WINDOW_NORMAL);
cv::imshow(“Origin image”, image);

for(int k = 0; k < 1000; k++)
{
int i = rand() % ima.cols;
int j = rand() % ima.rows;
ima(i, j)[0] = 255;
ima(i, j)[1] = 255;
ima(i, j)[2] = 255;
}

http://blog.csdn.net/liyuanbhu/article/details/48894973

你可能感兴趣的:(opencv)