opencv 访问像素不正确的坑

用opencv中三种访问像素的方法要,使用at<uchar>访问单通道的图像,注意其顺序

img.at<uchar>(x,y),访问的其实是图像中(y,x)点;

img.at<uchar>(Point(x,y)),访问的才是我们希望的(x,y)点像素;

原因的oencv Mat中存储的像素点下标(0,1)分别是指的(y,x);

使用时一定要注意,按照常理就使用mg.at<uchar>(Point(x,y))吧,用错了会出现像素点xy反掉了,浪费了一天时间,才从官网上查到这个,大家引以为鉴。

opencv官网原文(https://docs.opencv.org/2.4.13/doc/user_guide/ug_mat.html):

In order to get pixel intensity value, you have to know the type of an image and the number of channels. Here is an example for a single channel grey scale image (type 8UC1) and pixel coordinates x and y:

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

intensity.val[0] contains a value from 0 to 255. Note the ordering of x and y. Since in OpenCV images are represented by the same structure as matrices, we use the same convention for both cases - the 0-based row index (or y-coordinate) goes first and the 0-based column index (or x-coordinate) follows it. Alternatively, you can use the following notation:

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值