RGB的HSV转换错误 [英] Wrong HSV conversion from RGB

查看:148
本文介绍了RGB的HSV转换错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些列表,其中包含RGB格式的蓝色值.

I have these lists containing blue values in RGB format.

low = [
    [0, 0, 128],
    [65, 105, 225],
    [70, 130, 180],
    [72, 61, 139],
    [83, 104, 120]
]

我想做的是:将所有值(例如,第一个列表从RGB转换为HSV).

What I want to make is this: convert all the values from, for example, first list from RGB to HSV.

我编写了以下代码:

import cv2
import numpy as np

for v in low:
    rgb = np.uint8([[v]])
    print("RGB: ", rgb)

    hsv = cv2.cvtColor(rgb, cv2.COLOR_RGB2HSV)
    print("HSV: ", hsv)
    print("\n")

问题是当我去检查颜色(RGB-HSV)是否相同时.在这里,我发现不是.

The problem is when I go to check if the colors (RGB-HSV) are the same. Here I discovered that it's not.

让我们从low列表中获取最后一个值.

Let's take the last value from low list.

RGB:  [[[ 83 104 120]]]
HSV:  [[[103  79 120]]]

RGB是RGB输入值,并且输出HSV.但这最后一个与RGB颜色不同.首先是蓝色阴影,最后是绿色.为什么?

RGB is RGB input value and HSV is output. But this last one it's not the same color as RGB. First is a shade of blue and last is green. Why?

我使用了此工具来检查值.它还表示该RGB的正确HSV应该为205, 30, 47.

I used this tool to check values. It also says that the right HSV for this RGB should be 205, 30, 47.

我的错误在哪里?

推荐答案

用于验证的工具的色相范围为[0,359],饱和度和值的范围为[0,100]. OpenCV的HSV范围对于色相为[0,179],对于饱和度"和值"为[0,255].

The tool you used for verification has range [0,359] for Hue, and range [0,100] for Saturation and Value. OpenCV's HSV ranges are [0,179] for Hue, [0,255] for Saturation and Value.

乘以2、1/2.55、1/2.55,将得到期望值,并减去较小的整数截断错误:[103 79 120] * [2 1/2.55 1/2.55] = [206 31 47]

Multiply by 2, 1/2.55, 1/2.55 and you will get the expected values, off by minor integer truncation errors: [103 79 120] * [2 1/2.55 1/2.55] = [206 31 47]

这篇关于RGB的HSV转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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