比较两种HSB颜色

时间:2017-01-21 13:41:27

标签: java c# colors hsb

我有一个项目捕获一个区域并在HSB中找到它的主导颜色,我使用this article来找到主色。

在我的代码中,我在项目启动时获得主色,每一秒我都会拍摄该区域的照片并将其与第一种颜色与此代码进行比较:

private bool IsColorChanged(Structures.HSB hsb)
    {
        //hsb is the newest dominant color of that area
        //m_refcolor is the main color of that area which I got at startup
        Structures.HSB localhsb;
            localhsb.Hue = Math.Abs(hsb.Hue - m_refcolor.Hue);
            localhsb.Saturation = Math.Abs(hsb.Saturation - m_refcolor.Saturation);
            localhsb.Brightness = Math.Abs(hsb.Brightness - m_refcolor.Brightness);
            if ((localhsb.Hue >= m_hsbtr.Htreshold) || (localhsb.Saturation >= m_hsbtr.Streshold) || (localhsb.Brightness >= m_hsbtr.Btreshold))
                return true;
        return false;
    }

如果颜色变为任何颜色,我会向用户发射一个事件。

我的最终目标是找出颜色是否更改为特定颜色?但我不知道该怎么办。我的意思是我不知道如何与HSB相互比较,我使用的代码只有在我想知道颜色是否变为任何颜色时才有效。

我使用了c#,但我没有遇到其他语言的问题。任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

使用ColorMine项目解决了我的问题,无需再编码。

这个项目使用Delta-E比较颜色并支持许多色彩空间。

相关问题