提交 20f6a93d authored 作者: 陈泽健's avatar 陈泽健

封装亮度判断的compare_brightness函数处理,后续通过亮度判断灯光是否正确打开。

上级 faf0358e
...@@ -41,3 +41,66 @@ def swipe_up(app_driver): ...@@ -41,3 +41,66 @@ def swipe_up(app_driver):
# 执行滑动操作 # 执行滑动操作
app_driver.swipe(start_x, start_y, end_x, end_y, duration=500) app_driver.swipe(start_x, start_y, end_x, end_y, duration=500)
from PIL import Image
import numpy as np
import os
import logging
# 配置日志记录
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def compare_brightness(light_down_path, light_on_path, threshold=50):
"""
对比两张图片的亮度,返回亮度是否增加的布尔值。
light_on_path:传入暗色的图片
light_down_path:传入亮色的图片
"""
try:
image1 = Image.open(light_down_path).convert('L') # 转换为灰度图像
image2 = Image.open(light_on_path).convert('L') # 转换为灰度图像
# 将图像转换为numpy数组
array1 = np.array(image1)
array2 = np.array(image2)
# 计算平均亮度
avg_brightness1 = np.mean(array1)
avg_brightness2 = np.mean(array2)
logging.info(f"关闭灯光时的平均亮度: {avg_brightness1}")
logging.info(f"打开灯光时的平均亮度: {avg_brightness2}")
# 判断亮度是否增加,考虑阈值
brightness_increase = avg_brightness2 - avg_brightness1
logging.info(f"亮度变化量: {brightness_increase}")
return brightness_increase > threshold
except Exception as e:
logging.error(f"对比亮度时发生错误: {e}", exc_info=True)
return False
# if __name__ == '__main__':
# logging.info("开始对比亮度")
#
# image1_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\Base\暗图.jpg'
# image2_path = r'D:\GithubData\自动化\ubains-module-test\预定系统\Base\亮图.jpg'
#
# # 检查图片路径是否存在
# if not os.path.exists(image1_path):
# logging.error(f"图片 {image1_path} 不存在")
# exit(1)
# if not os.path.exists(image2_path):
# logging.error(f"图片 {image2_path} 不存在")
# exit(1)
#
# # 对比两张截图的亮度
# result = compare_brightness(image1_path, image2_path)
# logging.info(f"亮度比较结果: {result}")
#
# if result:
# logging.info("灯光已成功打开")
# else:
# logging.error("灯光未成功打开")
...@@ -2,6 +2,8 @@ import csv ...@@ -2,6 +2,8 @@ import csv
import glob import glob
import re import re
import urllib import urllib
import numpy as np
import requests import requests
import json import json
import hmac import hmac
......
...@@ -142,3 +142,5 @@ ...@@ -142,3 +142,5 @@
- 调整富创数据,调整标准版定时任务的启动标签为预定系统功能,执行预定系统全部功能自动化验证。 - 调整富创数据,调整标准版定时任务的启动标签为预定系统功能,执行预定系统全部功能自动化验证。
29. 2024-12-27 29. 2024-12-27
- 补充展厅中控屏的灯光控制以及窗帘控制。 - 补充展厅中控屏的灯光控制以及窗帘控制。
30. 2024-12-30
- 封装亮度判断的compare_brightness函数处理,后续通过亮度判断灯光是否正确打开。
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论