获取RGB值opencv python [英] Get RGB value opencv python
问题描述
我正在将图像加载到python中
I am loading an image into python e.g.
image = cv2.imread("new_image.jpg")
如何获取image
的RGB值?
推荐答案
您可以
image[y, x, c]
或等效的image[y][x][c]
.
,它将返回x,y,c
坐标中的像素值.请注意,索引从0
开始.因此,如果要访问第三个BGR(注意:不是RGB)组件,则必须执行image[y, x, 2]
,其中y
和x
是所需的行和列.
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.
此外,您可以通过输入dir(<variable>)
在Python中为给定对象提供可用的方法.例如,加载image
后,运行dir(image)
,您将获得一些有用的命令:
Also, you can get the methods available in Python for a given object by typing dir(<variable>)
. 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', ...
用法:image.mean()
这篇关于获取RGB值opencv python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!