从头开始opencv(五)——core:operations with images

it2023-09-06  78

从头开始opencv(五)——core:operations with images

Input/OutputBasic operations with imagesAccessing pixel intensity valuesPrimitive operations


Input/Output

Basic operations with images

Accessing pixel intensity values

Scalar intensity = img.at<uchar>(y, x);

注意x,y的顺序问题。

上面这个公式等价于下面这个公式:

Scalar intensity = img.at<uchar>(Point(x, y));

下面考虑三通道的情况

Vec3b intensity = img.at<Vec3b>(y, x); uchar blue = intensity.val[0]; uchar green = intensity.val[1]; uchar red = intensity.val[2]; Vec3f intensity = img.at<Vec3f>(y, x); float blue = intensity.val[0]; float green = intensity.val[1]; float red = intensity.val[2];

Primitive operations

从原有的灰度图img中得到黑色图像。

img = Scalar(0);

从原有图像中选出一块区域来

Rect r(10, 10, 100, 100); Mat smallImg = img(r);

从Mat到C API接口的转换

Mat img = imread("image.jpg"); IplImage img1 = img; CvMat m = img;

从彩图到灰度图的转换

Mat img = imread("image.jpg"); // loading a 8UC3 image Mat grey; cvtColor(img, grey, COLOR_BGR2GRAY);
最新回复(0)