使用openCV识别HSV中的颜色范围 [英] Identifying the range of a color in HSV using openCV

查看:704
本文介绍了使用openCV识别HSV中的颜色范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python中的openCV识别黄色.我已经到了这一步,必须在HSV中定义黄色的上下限.

I am working on identifying the color yellow using openCV in python. I have come to this step where I have to define the lower and upper range of the color yellow in HSV.

用于定义蓝色范围的示例:

Example for defining the range of Blue:

lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])

HSV通常以百分比定义,我想知道如何像示例一样定义黄色的范围.

The HSV is usually defined in percentage, I want to know how to define the range for yellow like the example.

这是我所学习的色彩空间教程正在关注.

上面提到的博客中有一些建议,但是并没有给我想要的输出.

There are some suggestions in the blog mentioned above, but it does not give me the desired output.

推荐答案

它是简单.您可以使用功能cv2.cvtColor().

It's Simple. You can use the function, cv2.cvtColor().

您无需传递图像,只需传递要转换为hsv的BGR值即可.

Instead of passing an image, you just pass the BGR values which you want to convert to hsv.

例如,要查找绿色的HSV值,请键入以下命令

For Example, to find the HSV value of Green, type the following command

import numpy as np
import cv2

green = np.uint8([[[0, 255, 0]]]) #here insert the bgr values which you want to convert to hsv
hsvGreen = cv2.cvtColor(green, cv2.COLOR_BGR2HSV)
print(hsvGreen)

lowerLimit = hsvGreen[0][0][0] - 10, 100, 100
upperLimit = hsvGreen[0][0][0] + 10, 255, 255

print(upperLimit)
print(lowerLimit)

现在,上限将为[H+10, 100,100]

,下限将为[H-10, 255, 255]

正式文档(请参阅以下网页的最后部分) https://docs.opencv.org/3.1.0/df/d9d/tutorial_py_colorspaces.html

这篇关于使用openCV识别HSV中的颜色范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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