python中cv2提取图像rgb值,获取RGB值opencv python

I am loading an image into python e.g.

image = cv2.imread("new_image.jpg")

How can i acccess the RGB values of image?

解决方案

You can do

image[y, x, c]

or equivalently image[y][x][c].

and it will return the value of the pixel in the x,y,c coordinates. Notice that indexing begins at 0. So, if you want to access the third BGR (note: not RGB) component, you must do image[y, x, 2] where y and x are the line and column desired.

Also, you can get the methods available in Python for a given object by typing dir(). For example, after loading image, run dir(image) and you will get some usefull commands:

'cumprod', 'cumsum', 'data', 'diagonal', 'dot', 'dtype', 'dump', 'dumps', 'fill',

'flags', 'flat', 'flatten', 'getfield', 'imag', 'item', 'itemset', 'itemsize',

'max', 'mean', 'min', ...

Usage: image.mean()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值