From 7719c3ca4fdc3b5bbadf2032ddf7262afb7727eb Mon Sep 17 00:00:00 2001 From: ERR0RPR0MPT Date: Sun, 14 Apr 2024 03:53:42 +0800 Subject: [PATCH] =?UTF-8?q?update=20v0.0.9=20-=20=E8=A7=A6=E6=91=B8?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=9C=86=E5=BD=A2=E5=8C=BA=E5=9F=9F=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 7f241bd..b4270bf 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +import math + from PIL import Image import subprocess import copy @@ -15,7 +17,7 @@ COM_BAUDRATE = 9600 # Android 多点触控数量 MAX_SLOT = 12 # 检测区域的像素值范围 -AREA_SCOPE = 65 +AREA_SCOPE = 50 # Android 设备实际屏幕大小 (单位:像素) ANDROID_ABS_MONITOR_SIZE = (1600, 2560) # Android 设备触控屏幕大小 (单位:像素) @@ -161,6 +163,7 @@ def microsecond_sleep(sleep_time): pass +# 选择方形区域的9个点作为判定 # def get_colors_in_area(x, y): # colors = set() # 使用集合来存储颜色值,以避免重复 # for dx in [-AREA_SCOPE, 0, AREA_SCOPE]: @@ -170,9 +173,29 @@ def microsecond_sleep(sleep_time): # return list(colors) +# 优化代码执行效率 +# def get_colors_in_area(x, y): +# colors = {str(exp_image.getpixel((x + dx, y + dy))[0]) for dx in [-AREA_SCOPE, 0, AREA_SCOPE] for dy in +# [-AREA_SCOPE, 0, AREA_SCOPE] if 0 <= (x + dx) < exp_image_width and 0 <= (y + dy) < exp_image_height} +# return list(colors) + + +# 选择圆形区域的9个点作为判定 def get_colors_in_area(x, y): - colors = {str(exp_image.getpixel((x + dx, y + dy))[0]) for dx in [-AREA_SCOPE, 0, AREA_SCOPE] for dy in - [-AREA_SCOPE, 0, AREA_SCOPE] if 0 <= (x + dx) < exp_image_width and 0 <= (y + dy) < exp_image_height} + colors = set() # 使用集合来存储颜色值,以避免重复 + num_points = 24 # 要获取的点的数量 + angle_increment = 360.0 / num_points # 角度增量 + cos_values = [math.cos(math.radians(i * angle_increment)) for i in range(num_points)] + sin_values = [math.sin(math.radians(i * angle_increment)) for i in range(num_points)] + for i in range(num_points): + dx = int(AREA_SCOPE * cos_values[i]) + dy = int(AREA_SCOPE * sin_values[i]) + px = x + dx + py = y + dy + if 0 <= px < exp_image_width and 0 <= py < exp_image_height: + pixel = exp_image.getpixel((px, py)) + color = str(pixel[0]) + colors.add(color) return list(colors)