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

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


Input/Output

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-AMYKhWDy-1603195519724)(C:\Users\lenovo\AppData\Roaming\Typora\typora-user-images\image-20201020144208703.png)]

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值