[英]How can i change a pixel value from a grayscaled image using Opencv 2.3?
When i read a grayscaled image using for example in Opencv 2.3: 当我使用Opencv 2.3中的示例读取灰度图像时:
Mat src = imread("44.png" ,0);
How can i access the pixel value of it? 如何获取像素值?
I know if its RGB i can use: 我知道它是否可以使用RGB:
std::cout << src.at<cv::Vec3b>(i,j)[0].
Thanks in advance. 提前致谢。
Since a grayscale image contains only one component instead of 3, the resulting matrix/image is of type CV_8UC1
instead of CV_8UC3
. 由于灰度图像仅包含一个分量而不是3,因此生成的矩阵/图像的类型为
CV_8UC1
而不是CV_8UC3
。 And this in turn means, that individual pixels are not 3-vectors of bytes ( cv::Vec3b
) but just single bytes ( unsigned char
or OpenCV's uchar
). 这又意味着,单个像素不是字节的3个向量(
cv::Vec3b
),而是单个字节( unsigned char
或OpenCV的uchar
)。 So you can just use: 因此,您可以使用:
src.at<unsigned char>(i, j)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.