English 中文(简体)
Java: 检测颜色( 例如, 我的颜色是蓝色吗? )
原标题:Java: detecting a color (e.g. is my color blue?)

我在爪哇处理一个工程, 它装入图像并找到每个像素的颜色信息。 我需要用颜色定义来探测天空, 颜色定义可能看起来像天空, 使用蓝色的颜色范围。 最初似乎最好使用 RGB, 但是这需要定义所有的蓝色阴影( 无法计算 ) 。 我找到了分析方法, 每种颜色都使用 HSV 的阈值, 但不知道如何用颜色范围分别加载一些库, 如何解答它。 感谢任何帮助 。

最佳回答

您可以使用静态方法 RGBtoHSB(...) java.awt.coor 转换为 s HSV 值。然后,您可以获取色素,并将其与一个区域(为了您的目的)构成蓝色的界限进行比较,例如:

private static final float MIN_BLUE_HUE = 0.5f; // CYAN
private static final float MAX_BLUE_HUE = 0.8333333f; // MAGENTA

public static boolean isBlue(Color c) {
  float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
  float hue = hsv[0];
  if (hue >= MIN_BLUE_HUE && hue <= MAX_BLUE_HUE){
    return true;
  } 
  return false;
}

我为 MIN_BLUE_HUE MAX_BLUE_HUE 提供了一些起始值,但您设定的 MIN_BLUE_HUE 的起始值将取决于您是否愿意接受蓝色,也就是说,有多少绿色或紫色,它作为天空仍然可以接受?

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...