如何在python open上读取图像的rgb或hsv值

2024-04-25 23:54:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想读一些图像的rgb或hsv值。 我查了一下怎么读,找到了答案。在

import cv2
image = cv2.imread("sample.jpg")
color = int(image[300, 300])
# if image type is b g r, then b g r value will be displayed.
# if image is gray then color intensity will be displayed.
print color

链接:Get RGB value opencv python

但这段代码给了我这样一个错误: TypeError:只有size-1数组可以转换为Python标量

如何修复此错误? 谢谢您。在


Tags: 答案图像imageifisvalue错误rgb
1条回答
网友
1楼 · 发布于 2024-04-25 23:54:17

你写的代码除了第三行外几乎是正确的 修复删除int函数将导致您要查找的结果。在

代码示例

import cv2
image = cv2.imread("sample.jpg")
color = image[300,300]
print(color)

结果:

^{pr2}$

这里我有3个代表RGB空间的数字。在

相关问题 更多 >

    热门问题