增加图片处理操作

This commit is contained in:
Voge1imkafig 2025-07-08 10:41:14 +08:00
parent 614c277dae
commit 44a797c59b
6 changed files with 68 additions and 39 deletions

View File

@ -12,7 +12,8 @@ from tools.content_tools import (
from tools.get_pictures import ( from tools.get_pictures import (
make_Thumbnail,resize_and_reduce_quality, make_Thumbnail,resize_and_reduce_quality,
get_picture_nums,find_image,collect_defect_data get_picture_nums,find_image,collect_defect_data,
process_picture_data
) )
from tools.Get_Json import (get_project_info,get_jizu_info, from tools.Get_Json import (get_project_info,get_jizu_info,
@ -179,7 +180,11 @@ async def generate_report(base_info, baogao_info):
temperature = shigong_data['temperature'] #温度 temperature = shigong_data['temperature'] #温度
wind_speed = shigong_data['windSpeed'] #风速 wind_speed = shigong_data['windSpeed'] #风速
weather = get_weather(shigong_data["weatherCode"]) #天气 weather = get_weather(shigong_data["weatherCode"]) #天气
#拉取图片数据
picture_data = get_picture(turbine_id) picture_data = get_picture(turbine_id)
#获取缺陷图列表和典型图列表
defect_pictures, typical_pictures = process_picture_data(picture_data, image_source_to_find)
#处理图片数据
date_year_month = get_year_month(baogao_date) date_year_month = get_year_month(baogao_date)

View File

@ -4,4 +4,4 @@ GETJIZUINFO = "/turbine/detail/{turbineId}"
GETSHIGONGINFO = "/t-construction/list" GETSHIGONGINFO = "/t-construction/list"
GETWEATHERINFO = "/weather-type/{weatherCode}" GETWEATHERINFO = "/weather-type/{weatherCode}"
GETPICTURELIST = "/image/list" GETPICTURELIST = "/image/list"
GETPARTLIST = "/part/list" GETPARTLIST = "/part/list"

View File

@ -53,7 +53,7 @@ def get_part_list(turbineId : str) -> dict:
def get_picture(turbineId : str): def get_picture(turbineId : str) -> list[dict]:
"""获取对应机组所有图片 """获取对应机组所有图片
Args: Args:
@ -61,40 +61,32 @@ def get_picture(turbineId : str):
Return: Return:
list: 包含所有图片信息的列表(按部件分list) list: 包含所有图片信息的列表(按部件分list)
[ [
[ {
{ "imageId": "图片id",
"imageId": "字符串", "imageName": "图片名",
"imageName": "字符串", "imagePath": "图片路径",
"imagePath": "字符串", "partId": "部件id",
"partId": "字符串", "partName": "部件名",
"partName": "字符串", "imageResolution": "字符串",
"imageResolution": "字符串", "focalDistance": "字符串/None",
"focalDistance": "字符串/None", "shootingTime": "字符串/None",
"shootingTime": "字符串/None", "cameraManufacturer": "字符串/None",
"cameraManufacturer": "字符串/None", "cameraModel": "字符串/None",
"cameraModel": "字符串/None", "weather": "字符串/None",
"weather": "字符串/None", "weatherLabel": "字符串/None",
"weatherLabel": "字符串/None", "humidness": "数值/None",
"humidness": "数值/None", "temperature": "字符串/None",
"temperature": "字符串/None", "windLevel": "数值/None",
"windLevel": "数值/None", "shootingMethod": "字符串/None",
"shootingMethod": "字符串/None", "shootingMethodLabel": "字符串/None",
"shootingMethodLabel": "字符串/None", "shootingDistance": "数值/None",
"shootingDistance": "数值/None", "collectorName": "字符串/None",
"collectorName": "字符串/None", "imageType": "None",
"imageType": "None", "imageTypeLabel": "None",
"imageTypeLabel": "None", "audioList": "None",
"audioList": "None", "gps": "字符串/None"
"gps": "字符串/None" },
}, ...
...
],
[
{
// 相同结构的字典对象
},
...
]
] ]
""" """
picturerul = DTURL + GETPICTURELIST picturerul = DTURL + GETPICTURELIST
@ -104,6 +96,15 @@ def get_picture(turbineId : str):
params = { params = {
"partId" : part_id, "partId" : part_id,
} }
result.append(get_data(picturerul, params = params)) for images in get_data(picturerul, params = params):
result.append(images)
print(f"图片数据获取成功:{result}")
return result return result
def find_defect_record(defect_pictures : list[dict]):
"""查找缺陷图片的缺陷记录
Args:
defect_pictures (list[dict]): 缺陷图列表
"""

View File

@ -231,4 +231,27 @@ def create_thumbnail(file_path: str, size: tuple) -> Image:
return new_img return new_img
except Exception as e: except Exception as e:
print(f"图片处理有问题:{e}") print(f"图片处理有问题:{e}")
return None return None
def process_picture_data(picture_data : list[dict],
image_source_to_find : list[str],
quexian_type : str,
dianxing_type : str) -> tuple[list[str], list[str]]:
"""处理从数据库获取的图片数据
Args:
picture_data (list[dict]): 图片数据
image_source_to_find (list[str]): 要查找的图片来源枚举(外内防雷)
quexian_type (str): 缺陷类型枚举值
dianxing_type (str): 典型类型枚举值
Returns:
tuple(
defct_pictures, 缺陷图列表
dianxing_pictures 典型图列表
)
"""
#过滤目标来源的图片数据
picture_data = [pic for pic in picture_data if pic['imageSource'] in image_source_to_find]
#分别择出缺陷图和典型图
return [pic for pic in picture_data if pic['imageType'] == quexian_type], [pic for pic in picture_data if pic['imageType'] == dianxing_type]