获取RGB值opencv python [英] Get RGB value opencv python

查看:519
本文介绍了获取RGB值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],其中yx是所需的行和列.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆