refactor: Remove deprecated files and enhance configuration settings
- Deleted outdated markdown files and scripts related to previous implementations. - Updated `config.json` to adjust thresholds and settings for 福袋 detection and reservation handling. - Improved logging and error handling across various modules for better monitoring and user experience. - Introduced a new screenshot management module to facilitate real-time operation and success tracking. - Enhanced GUI elements to support new configuration options and improve usability.
This commit is contained in:
1 parent
8b47b506d6
commit
47e6b016c5
31 files changed
+2257
-7371
No files matched your search
@@ -1,75 +0,0 @@
|
||||
# RGB颜色范围读取工具使用说明
|
||||
|
||||
## 功能
|
||||
读取图片的RGB颜色范围,用于调试福袋检测的颜色匹配逻辑。
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 1. 读取整张图片的RGB范围
|
||||
```bash
|
||||
python tools/read_image_rgb.py pic/screenshot.png
|
||||
```
|
||||
|
||||
### 2. 读取特定坐标的RGB值
|
||||
```bash
|
||||
python tools/read_image_rgb.py pic/screenshot.png 100 200
|
||||
```
|
||||
这会显示坐标 (100, 200) 的RGB值。
|
||||
|
||||
### 3. 读取特定区域的RGB范围
|
||||
```bash
|
||||
python tools/read_image_rgb.py pic/screenshot.png 0 0 200 300
|
||||
```
|
||||
这会读取从 (0, 0) 开始,宽度200、高度300的区域的RGB范围。
|
||||
|
||||
## 实际应用示例
|
||||
|
||||
### 示例1:检测福袋图标颜色
|
||||
假设福袋图标在坐标 (165, 403) 附近:
|
||||
```bash
|
||||
# 读取单个像素
|
||||
python tools/read_image_rgb.py pic/screenshot.png 165 403
|
||||
|
||||
# 读取一个小区域(比如 10x10 像素)
|
||||
python tools/read_image_rgb.py pic/screenshot.png 160 398 10 10
|
||||
```
|
||||
|
||||
### 示例2:检测福袋详情页参与按钮颜色
|
||||
假设参与按钮在坐标 (536, 883) 附近:
|
||||
```bash
|
||||
# 读取单个像素
|
||||
python tools/read_image_rgb.py pic/screenshot.png 536 883
|
||||
|
||||
# 读取按钮区域(比如 20x20 像素)
|
||||
python tools/read_image_rgb.py pic/screenshot.png 526 873 20 20
|
||||
```
|
||||
|
||||
## 输出说明
|
||||
|
||||
### 单个像素输出
|
||||
```
|
||||
坐标 (165, 403) 的RGB值:
|
||||
R: 198
|
||||
G: 185
|
||||
B: 242
|
||||
十六进制: #C6B9F2
|
||||
```
|
||||
|
||||
### 区域/整图输出
|
||||
```
|
||||
RGB颜色范围:
|
||||
R: 190 ~ 206
|
||||
G: 173 ~ 196
|
||||
B: 234 ~ 250
|
||||
|
||||
用于代码的颜色范围判断:
|
||||
190 <= r <= 206 and 173 <= g <= 196 and 234 <= b <= 250
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 坐标基于图片的实际分辨率
|
||||
2. 如果图片是1080x2400,坐标就是实际像素坐标
|
||||
3. 如果图片是其他分辨率,需要按比例换算
|
||||
4. 区域检测会扫描区域内所有像素,计算最小和最大RGB值
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""分析福袋图标的RGB颜色范围,给出代码建议"""
|
||||
|
||||
from PIL import Image
|
||||
from collections import Counter
|
||||
|
||||
img = Image.open('assets/fudai.png').convert('RGB')
|
||||
width, height = img.size
|
||||
|
||||
# 收集非背景像素
|
||||
pixels = []
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
r, g, b = img.getpixel((x, y))
|
||||
# 排除黑色背景
|
||||
if not (r < 30 and g < 30 and b < 30):
|
||||
pixels.append((r, g, b))
|
||||
|
||||
if not pixels:
|
||||
print("No valid pixels")
|
||||
exit(1)
|
||||
|
||||
# 主要颜色
|
||||
colors = Counter(pixels)
|
||||
top_colors = colors.most_common(10)
|
||||
|
||||
print("Top 10 colors:")
|
||||
for i, ((r, g, b), count) in enumerate(top_colors, 1):
|
||||
pct = (count / len(pixels)) * 100
|
||||
print(f"{i}. RGB({r:3d}, {g:3d}, {b:3d}) - {pct:5.2f}% - #{r:02X}{g:02X}{b:02X}")
|
||||
|
||||
# RGB范围
|
||||
r_vals = [p[0] for p in pixels]
|
||||
g_vals = [p[1] for p in pixels]
|
||||
b_vals = [p[2] for p in pixels]
|
||||
|
||||
print(f"\nFull RGB range:")
|
||||
print(f" R: {min(r_vals)} ~ {max(r_vals)}")
|
||||
print(f" G: {min(g_vals)} ~ {max(g_vals)}")
|
||||
print(f" B: {min(b_vals)} ~ {max(b_vals)}")
|
||||
|
||||
# 基于主要颜色的建议范围
|
||||
if top_colors:
|
||||
main_r, main_g, main_b = top_colors[0][0]
|
||||
print(f"\nMain color: RGB({main_r}, {main_g}, {main_b})")
|
||||
print(f"\nSuggested range (main color +/- tolerance):")
|
||||
|
||||
# 容差建议
|
||||
tolerance_r = 30
|
||||
tolerance_g = 30
|
||||
tolerance_b = 30
|
||||
|
||||
r_min = max(200, main_r - tolerance_r)
|
||||
r_max = min(255, main_r + 10)
|
||||
g_min = max(150, main_g - tolerance_g)
|
||||
g_max = min(255, main_g + tolerance_g)
|
||||
b_min = max(180, main_b - tolerance_b)
|
||||
b_max = min(255, main_b + tolerance_b)
|
||||
|
||||
print(f" {r_min} <= r <= {r_max}")
|
||||
print(f" {g_min} <= g <= {g_max}")
|
||||
print(f" {b_min} <= b <= {b_max}")
|
||||
|
||||
print(f"\nCode format:")
|
||||
print(f" {r_min} <= int(px[0]) <= {r_max} and {g_min} <= int(px[1]) <= {g_max} and {b_min} <= int(px[2]) <= {b_max}")
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""对比福袋和优惠券的RGB颜色,找出区分特征"""
|
||||
|
||||
from PIL import Image
|
||||
from collections import Counter
|
||||
|
||||
print("=" * 60)
|
||||
print("福袋图标颜色分析")
|
||||
print("=" * 60)
|
||||
fudai = Image.open('assets/fudai.png').convert('RGB')
|
||||
fudai_pixels = [(r,g,b) for y in range(fudai.height) for x in range(fudai.width)
|
||||
for r,g,b in [fudai.getpixel((x,y))] if not (r<30 and g<30 and b<30)]
|
||||
fudai_colors = Counter(fudai_pixels)
|
||||
fudai_top = fudai_colors.most_common(5)
|
||||
print("Top 5 colors:")
|
||||
for (r,g,b), count in fudai_top:
|
||||
print(f" RGB({r:3d}, {g:3d}, {b:3d}) - {count/len(fudai_pixels)*100:5.2f}%")
|
||||
|
||||
fudai_r = [p[0] for p in fudai_pixels]
|
||||
fudai_g = [p[1] for p in fudai_pixels]
|
||||
fudai_b = [p[2] for p in fudai_pixels]
|
||||
print(f"\nRGB range: R[{min(fudai_r)}-{max(fudai_r)}] G[{min(fudai_g)}-{max(fudai_g)}] B[{min(fudai_b)}-{max(fudai_b)}]")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("优惠券颜色分析")
|
||||
print("=" * 60)
|
||||
coupon = Image.open('assets/coupon.png').convert('RGB')
|
||||
coupon_pixels = [(r,g,b) for y in range(coupon.height) for x in range(coupon.width)
|
||||
for r,g,b in [coupon.getpixel((x,y))] if not (r<30 and g<30 and b<30)]
|
||||
coupon_colors = Counter(coupon_pixels)
|
||||
coupon_top = coupon_colors.most_common(5)
|
||||
print("Top 5 colors:")
|
||||
for (r,g,b), count in coupon_top:
|
||||
print(f" RGB({r:3d}, {g:3d}, {b:3d}) - {count/len(coupon_pixels)*100:5.2f}%")
|
||||
|
||||
coupon_r = [p[0] for p in coupon_pixels]
|
||||
coupon_g = [p[1] for p in coupon_pixels]
|
||||
coupon_b = [p[2] for p in coupon_pixels]
|
||||
print(f"\nRGB range: R[{min(coupon_r)}-{max(coupon_r)}] G[{min(coupon_g)}-{max(coupon_g)}] B[{min(coupon_b)}-{max(coupon_b)}]")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("区分特征分析")
|
||||
print("=" * 60)
|
||||
|
||||
# 优惠券的主要红色特征
|
||||
coupon_red = [p for p in coupon_pixels if p[0] > 250 and p[1] < 100 and p[2] < 120]
|
||||
if coupon_red:
|
||||
red_r = [p[0] for p in coupon_red]
|
||||
red_g = [p[1] for p in coupon_red]
|
||||
red_b = [p[2] for p in coupon_red]
|
||||
print(f"\n优惠券红色区域:")
|
||||
print(f" R: {min(red_r)}-{max(red_r)}")
|
||||
print(f" G: {min(red_g)}-{max(red_g)}")
|
||||
print(f" B: {min(red_b)}-{max(red_b)}")
|
||||
print(f" 特征: 高R值(>{min(red_r)}),低G值(<{max(red_g)}),低B值(<{max(red_b)})")
|
||||
|
||||
# 福袋的主要颜色特征
|
||||
fudai_pink = [p for p in fudai_pixels if p[0] > 225 and p[1] > 180 and p[2] > 190]
|
||||
if fudai_pink:
|
||||
pink_r = [p[0] for p in fudai_pink]
|
||||
pink_g = [p[1] for p in fudai_pink]
|
||||
pink_b = [p[2] for p in fudai_pink]
|
||||
print(f"\n福袋粉红色区域:")
|
||||
print(f" R: {min(pink_r)}-{max(pink_r)}")
|
||||
print(f" G: {min(pink_g)}-{max(pink_g)}")
|
||||
print(f" B: {min(pink_b)}-{max(pink_b)}")
|
||||
print(f" 特征: 高R值(>{min(pink_r)}),高G值(>{min(pink_g)}),高B值(>{min(pink_b)})")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("建议的排除条件")
|
||||
print("=" * 60)
|
||||
print("\n优惠券红色特征(需要排除):")
|
||||
print(" - R > 250 且 G < 100 且 B < 120 (鲜艳红色)")
|
||||
print(" - R > 250 且 G < 150 且 B < 150 (较宽松的红色)")
|
||||
print("\n福袋粉红色特征(需要保留):")
|
||||
print(" - R > 225 且 G > 180 且 B > 190 (粉红色)")
|
||||
print("\n建议的福袋检测条件:")
|
||||
print(" R > 225 and R <= 255")
|
||||
print(" G > 180 and G <= 255")
|
||||
print(" B > 190 and B <= 255")
|
||||
print(" AND NOT (R > 250 and G < 100 and B < 120) # 排除优惠券红色")
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
福袋图标RGB颜色范围检测工具
|
||||
自动排除黑色背景,只检测福袋图标本身的RGB范围
|
||||
"""
|
||||
|
||||
import sys
|
||||
from PIL import Image
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def get_fudai_rgb_range(image_path: str, exclude_bg: bool = True, bg_threshold: int = 30):
|
||||
"""检测福袋图标的RGB颜色范围(排除背景)
|
||||
|
||||
参数:
|
||||
image_path: 图片路径
|
||||
exclude_bg: 是否排除背景色(默认True,排除RGB值都小于30的像素)
|
||||
bg_threshold: 背景色阈值(RGB值都小于此值认为是背景)
|
||||
"""
|
||||
try:
|
||||
img = Image.open(image_path)
|
||||
img_rgb = img.convert("RGB")
|
||||
width, height = img_rgb.size
|
||||
|
||||
print(f"图片尺寸: {width} x {height}")
|
||||
print(f"图片模式: {img.mode}")
|
||||
print("-" * 60)
|
||||
|
||||
# 收集所有非背景像素的RGB值
|
||||
pixels = []
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
try:
|
||||
r, g, b = img_rgb.getpixel((x, y))
|
||||
# 如果启用背景排除,跳过黑色/深色背景
|
||||
if exclude_bg and r < bg_threshold and g < bg_threshold and b < bg_threshold:
|
||||
continue
|
||||
pixels.append((r, g, b))
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if not pixels:
|
||||
print("错误: 没有检测到有效像素(可能整张图都是背景色)")
|
||||
return None
|
||||
|
||||
# 计算RGB范围
|
||||
r_values = [p[0] for p in pixels]
|
||||
g_values = [p[1] for p in pixels]
|
||||
b_values = [p[2] for p in pixels]
|
||||
|
||||
r_min, r_max = min(r_values), max(r_values)
|
||||
g_min, g_max = min(g_values), max(g_values)
|
||||
b_min, b_max = min(b_values), max(b_values)
|
||||
|
||||
# 计算RGB平均值(用于参考)
|
||||
r_avg = sum(r_values) // len(r_values)
|
||||
g_avg = sum(g_values) // len(g_values)
|
||||
b_avg = sum(b_values) // len(b_values)
|
||||
|
||||
print(f"\n福袋图标RGB颜色范围(已排除背景):")
|
||||
print(f" R: {r_min} ~ {r_max} (平均值: {r_avg})")
|
||||
print(f" G: {g_min} ~ {g_max} (平均值: {g_avg})")
|
||||
print(f" B: {b_min} ~ {b_max} (平均值: {b_avg})")
|
||||
print(f"\n有效像素数: {len(pixels)} / {width * height}")
|
||||
|
||||
# 分析主要颜色(找出最常见的RGB组合)
|
||||
print(f"\n主要颜色分析:")
|
||||
color_counter = Counter(pixels)
|
||||
top_colors = color_counter.most_common(5)
|
||||
for i, (color, count) in enumerate(top_colors, 1):
|
||||
r, g, b = color
|
||||
percentage = (count / len(pixels)) * 100
|
||||
print(f" {i}. RGB({r}, {g}, {b}) - 占比 {percentage:.1f}% - #{r:02X}{g:02X}{b:02X}")
|
||||
|
||||
# 生成代码建议
|
||||
print(f"\n" + "=" * 60)
|
||||
print("用于代码的颜色范围判断(建议):")
|
||||
print("=" * 60)
|
||||
|
||||
# 方法1:使用完整范围(容错性最好,但可能误检)
|
||||
print(f"\n方法1:完整范围(容错性最好)")
|
||||
print(f" {r_min} <= r <= {r_max} and {g_min} <= g <= {g_max} and {b_min} <= b <= {b_max}")
|
||||
|
||||
# 方法2:使用平均值±范围(更精确,但需要根据实际情况调整)
|
||||
r_range = max(10, (r_max - r_min) // 2)
|
||||
g_range = max(10, (g_max - g_min) // 2)
|
||||
b_range = max(10, (b_max - b_min) // 2)
|
||||
|
||||
print(f"\n方法2:平均值±范围(更精确)")
|
||||
print(f" {r_avg - r_range} <= r <= {r_avg + r_range} and "
|
||||
f"{g_avg - g_range} <= g <= {g_avg + g_range} and "
|
||||
f"{b_avg - b_range} <= b <= {b_avg + b_range}")
|
||||
|
||||
# 方法3:基于主要颜色的范围(最精确,但可能漏检)
|
||||
if top_colors:
|
||||
main_r, main_g, main_b = top_colors[0][0]
|
||||
tolerance = 20 # 容差
|
||||
print(f"\n方法3:主要颜色±容差(最精确,基于主要颜色RGB({main_r}, {main_g}, {main_b}))")
|
||||
print(f" {main_r - tolerance} <= r <= {main_r + tolerance} and "
|
||||
f"{main_g - tolerance} <= g <= {main_g + tolerance} and "
|
||||
f"{main_b - tolerance} <= b <= {main_b + tolerance}")
|
||||
|
||||
# 当前代码中的范围(用于对比)
|
||||
print(f"\n当前代码中的范围(用于对比):")
|
||||
print(f" 190 <= r <= 206 and 173 <= g <= 196 and 234 <= b <= 250")
|
||||
|
||||
return {
|
||||
"r_range": (r_min, r_max),
|
||||
"g_range": (g_min, g_max),
|
||||
"b_range": (b_min, b_max),
|
||||
"r_avg": r_avg,
|
||||
"g_avg": g_avg,
|
||||
"b_avg": b_avg,
|
||||
"pixel_count": len(pixels)
|
||||
}
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"错误: 找不到图片文件: {image_path}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"错误: {type(e).__name__}: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("用法: python tools/read_fudai_rgb.py <图片路径>")
|
||||
print("示例: python tools/read_fudai_rgb.py pic/fudai_icon.png")
|
||||
sys.exit(1)
|
||||
|
||||
image_path = sys.argv[1]
|
||||
get_fudai_rgb_range(image_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
图片RGB颜色范围读取工具
|
||||
|
||||
用法:
|
||||
python tools/read_image_rgb.py <图片路径> [x] [y] [width] [height]
|
||||
|
||||
示例:
|
||||
# 读取整张图片的RGB范围
|
||||
python tools/read_image_rgb.py pic/screenshot.png
|
||||
|
||||
# 读取特定坐标的RGB值
|
||||
python tools/read_image_rgb.py pic/screenshot.png 100 200
|
||||
|
||||
# 读取特定区域的RGB范围
|
||||
python tools/read_image_rgb.py pic/screenshot.png 0 0 200 300
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def get_rgb_range(image_path: str, x: int = None, y: int = None, width: int = None, height: int = None):
|
||||
"""读取图片的RGB颜色范围
|
||||
|
||||
参数:
|
||||
image_path: 图片路径
|
||||
x: 起始X坐标(可选,用于区域检测)
|
||||
y: 起始Y坐标(可选,用于区域检测)
|
||||
width: 区域宽度(可选,用于区域检测)
|
||||
height: 区域高度(可选,用于区域检测)
|
||||
|
||||
返回:
|
||||
dict: 包含RGB范围信息的字典
|
||||
"""
|
||||
try:
|
||||
img = Image.open(image_path)
|
||||
img_rgb = img.convert("RGB")
|
||||
img_width, img_height = img_rgb.size
|
||||
|
||||
print(f"图片尺寸: {img_width} x {img_height}")
|
||||
print(f"图片模式: {img.mode}")
|
||||
print("-" * 60)
|
||||
|
||||
# 如果指定了坐标,读取单个像素
|
||||
if x is not None and y is not None:
|
||||
if not (0 <= x < img_width and 0 <= y < img_height):
|
||||
print(f"错误: 坐标 ({x}, {y}) 超出图片范围")
|
||||
return None
|
||||
|
||||
r, g, b = img_rgb.getpixel((x, y))
|
||||
print(f"坐标 ({x}, {y}) 的RGB值:")
|
||||
print(f" R: {r}")
|
||||
print(f" G: {g}")
|
||||
print(f" B: {b}")
|
||||
print(f" 十六进制: #{r:02X}{g:02X}{b:02X}")
|
||||
return {"r": r, "g": g, "b": b, "x": x, "y": y}
|
||||
|
||||
# 如果指定了区域,读取区域范围
|
||||
if x is not None and y is not None and width is not None and height is not None:
|
||||
x_end = min(x + width, img_width)
|
||||
y_end = min(y + height, img_height)
|
||||
|
||||
print(f"区域: ({x}, {y}) 到 ({x_end-1}, {y_end-1})")
|
||||
print(f"区域大小: {x_end - x} x {y_end - y}")
|
||||
|
||||
pixels = []
|
||||
for py in range(y, y_end):
|
||||
for px in range(x, x_end):
|
||||
try:
|
||||
r, g, b = img_rgb.getpixel((px, py))
|
||||
pixels.append((r, g, b))
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if not pixels:
|
||||
print("错误: 区域中没有有效像素")
|
||||
return None
|
||||
|
||||
r_values = [p[0] for p in pixels]
|
||||
g_values = [p[1] for p in pixels]
|
||||
b_values = [p[2] for p in pixels]
|
||||
|
||||
r_min, r_max = min(r_values), max(r_values)
|
||||
g_min, g_max = min(g_values), max(g_values)
|
||||
b_min, b_max = min(b_values), max(b_values)
|
||||
|
||||
print(f"\nRGB颜色范围:")
|
||||
print(f" R: {r_min} ~ {r_max}")
|
||||
print(f" G: {g_min} ~ {g_max}")
|
||||
print(f" B: {b_min} ~ {b_max}")
|
||||
print(f"\n用于代码的颜色范围判断:")
|
||||
print(f" {r_min} <= r <= {r_max} and {g_min} <= g <= {g_max} and {b_min} <= b <= {b_max}")
|
||||
print(f"\n像素总数: {len(pixels)}")
|
||||
|
||||
return {
|
||||
"r_range": (r_min, r_max),
|
||||
"g_range": (g_min, g_max),
|
||||
"b_range": (b_min, b_max),
|
||||
"pixel_count": len(pixels)
|
||||
}
|
||||
|
||||
# 读取整张图片的RGB范围
|
||||
print("扫描整张图片...")
|
||||
pixels = []
|
||||
for py in range(img_height):
|
||||
for px in range(img_width):
|
||||
try:
|
||||
r, g, b = img_rgb.getpixel((px, py))
|
||||
pixels.append((r, g, b))
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if not pixels:
|
||||
print("错误: 图片中没有有效像素")
|
||||
return None
|
||||
|
||||
r_values = [p[0] for p in pixels]
|
||||
g_values = [p[1] for p in pixels]
|
||||
b_values = [p[2] for p in pixels]
|
||||
|
||||
r_min, r_max = min(r_values), max(r_values)
|
||||
g_min, g_max = min(g_values), max(g_values)
|
||||
b_min, b_max = min(b_values), max(b_values)
|
||||
|
||||
print(f"\n整张图片的RGB颜色范围:")
|
||||
print(f" R: {r_min} ~ {r_max}")
|
||||
print(f" G: {g_min} ~ {g_max}")
|
||||
print(f" B: {b_min} ~ {b_max}")
|
||||
print(f"\n像素总数: {len(pixels)}")
|
||||
|
||||
return {
|
||||
"r_range": (r_min, r_max),
|
||||
"g_range": (g_min, g_max),
|
||||
"b_range": (b_min, b_max),
|
||||
"pixel_count": len(pixels)
|
||||
}
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"错误: 找不到图片文件: {image_path}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"错误: {type(e).__name__}: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
image_path = sys.argv[1]
|
||||
|
||||
# 解析参数
|
||||
x = int(sys.argv[2]) if len(sys.argv) > 2 else None
|
||||
y = int(sys.argv[3]) if len(sys.argv) > 3 else None
|
||||
width = int(sys.argv[4]) if len(sys.argv) > 4 else None
|
||||
height = int(sys.argv[5]) if len(sys.argv) > 5 else None
|
||||
|
||||
# 如果只提供了x和y,就是读取单个像素
|
||||
if x is not None and y is not None and width is None and height is None:
|
||||
get_rgb_range(image_path, x=x, y=y)
|
||||
# 如果提供了x, y, width, height,就是读取区域
|
||||
elif x is not None and y is not None and width is not None and height is not None:
|
||||
get_rgb_range(image_path, x=x, y=y, width=width, height=height)
|
||||
# 否则读取整张图片
|
||||
else:
|
||||
get_rgb_range(image_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in new issue
Block a user