backend.color¶
color ¶
函数:
| 名称 | 描述 |
|---|---|
hsv_web2cv |
将 HSV 颜色从 Web 格式转换为 OpenCV 格式。 |
hsv_cv2web |
将 HSV 颜色从 OpenCV 格式转换为 Web 格式。 |
rgb_to_hsv |
将 RGB 颜色转换为 HSV 颜色。 |
hsv_to_rgb |
将 HSV 颜色转换为 RGB 颜色。 |
in_range |
判断颜色是否在范围内。 |
find |
在图像中查找指定颜色的点。 |
color_distance_map |
计算图像中每个像素点到目标颜色的HSL距离,并返回归一化后的距离矩阵。 |
find_all |
在图像中查找所有符合指定颜色的点。 |
dominant_color |
提取图像的主色调。 |
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
RgbColor |
颜色。三元组 |
|
HsvColor |
HSV颜色。三元组 |
RgbColor
module-attribute
¶
RgbColor = RgbColorTuple | RgbColorStr
颜色。三元组 (r, g, b) 或十六进制颜色字符串 #RRGGBB
hsv_web2cv ¶
hsv_web2cv(h: int, s: int, v: int) -> HsvColor
hsv_cv2web ¶
hsv_cv2web(h: int, s: int, v: int) -> HsvColor
rgb_to_hsv ¶
rgb_to_hsv(c: RgbColor) -> HsvColor
hsv_to_rgb ¶
hsv_to_rgb(c: HsvColor) -> RgbColor
in_range ¶
in_range(color: RgbColor, range: tuple[HsvColor, HsvColor]) -> bool
find ¶
find(image: MatLike | str, color: RgbColor, *, rect: Rect | None = None, threshold: float = 0.95, method: Literal['rgb_dist'] = 'rgb_dist') -> tuple[int, int] | None
在图像中查找指定颜色的点。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
MatLike | str
|
图像。可以是 MatLike 或图像文件路径。 注意如果参数为 MatLike,则颜色格式必须为 BGR,而不是 RGB。 |
必需 |
|
RgbColor
|
颜色。可以是整数三元组 |
必需 |
|
Rect | None
|
查找范围。如果为 None,则在整个图像中查找。 |
None
|
|
float
|
阈值,越大表示越相似,1 表示完全相似。默认为 0.95。 |
0.95
|
|
Literal['rgb_dist']
|
'rgb_dist'
|
color_distance_map ¶
color_distance_map(image: MatLike | str, color: RgbColor, *, rect: RectTuple | None = None) -> np.ndarray
find_all ¶
find_all(image: MatLike | str, color: RgbColor, *, rect: Rect | None = None, threshold: float = 0.95, method: Literal['rgb_dist'] = 'rgb_dist', filter_method: Literal['point', 'contour'] = 'contour', max_results: int | None = None) -> list[FindColorPointResult]
在图像中查找所有符合指定颜色的点。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
MatLike | str
|
图像。可以是 MatLike 或图像文件路径。 注意如果参数为 MatLike,则颜色格式必须为 BGR,而不是 RGB。 |
必需 |
|
RgbColor
|
颜色。可以是整数三元组 |
必需 |
|
Rect | None
|
查找范围。如果为 None,则在整个图像中查找。 |
None
|
|
float
|
阈值,越大表示越相似,1 表示完全相似。默认为 0.95。 |
0.95
|
|
Literal['rgb_dist']
|
比较算法。默认为 'rgb_dist',且目前也只有这个方法。 |
'rgb_dist'
|
|
Literal['point', 'contour']
|
查找方法。
|
'contour'
|
|
int | None
|
最大返回结果数量。如果为 None,则返回所有结果。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
list[FindColorPointResult]
|
结果列表。 |