From 916c0e6e15052dc1de9a68d7418f4ec5269767a9 Mon Sep 17 00:00:00 2001 From: dongchangxi <458593490@qq.com> Date: Fri, 3 Jan 2025 17:09:22 +0800 Subject: [PATCH] 1 --- new_studio_to_reg/get_new_studio_reg_info.py | 2 +- new_studio_to_reg/tools_to_xmps.py | 51 +++++++++++++++++--- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/new_studio_to_reg/get_new_studio_reg_info.py b/new_studio_to_reg/get_new_studio_reg_info.py index eab51bf..f84ea45 100644 --- a/new_studio_to_reg/get_new_studio_reg_info.py +++ b/new_studio_to_reg/get_new_studio_reg_info.py @@ -1,4 +1,4 @@ -import os, sys, time, shutil, subprocess, shlex, json,oss2,redis +import os, sys, time, shutil, subprocess, shlex, json,oss2,redis,requests import platform if platform.system() == 'Windows': sys.path.append('e:\\libs\\') diff --git a/new_studio_to_reg/tools_to_xmps.py b/new_studio_to_reg/tools_to_xmps.py index 7f72ba8..5856187 100644 --- a/new_studio_to_reg/tools_to_xmps.py +++ b/new_studio_to_reg/tools_to_xmps.py @@ -7,7 +7,11 @@ else: sys.path.append('/data/deploy/make3d/make2/libs/') import config, libs, libs_db - +import cv2 +import numpy as np +from PIL import Image +from PIL.ExifTags import TAGS +import piexif #检测是否存在 rate_xmps 文件,如果没有则要创建该影棚对应的rate_xmps文件 def check_rate_xmps(pid): @@ -33,16 +37,47 @@ def clearExifAndRotate(imagePath, rotate=90): # # 保存处理后的图片 # img.save(imagePath) + clear_exif(imagePath,imagePath) + rotate_image(imagePath, 90, imagePath) # 打开图像 - with Image.open(imagePath) as img: - # 使用RGB模式打开图像来丢弃可能存在的EXIF信息 - img = img.convert("RGB") - img = img.rotate(rotate) - # 保存图像,保存时不会带有原始的任何元数据 - img.save(imagePath, quality=100) # 对于JPEG,可以调整质量参数 - + # with Image.open(imagePath) as img: + # # 使用RGB模式打开图像来丢弃可能存在的EXIF信息 + # img = img.convert("RGB") + # img = img.rotate(rotate) + # # 保存图像,保存时不会带有原始的任何元数据 + # img.save(imagePath, quality=100) # 对于JPEG,可以调整质量参数 + +# 1. 清除 EXIF 信息 +def clear_exif(image_path, output_path): + # 使用 Pillow 打开图像并清除 EXIF + image = Image.open(image_path) + + # 创建不包含EXIF信息的副本 + image_no_exif = Image.new(image.mode, image.size) + image_no_exif.paste(image, (0, 0)) + + # 保存不包含EXIF的图像 + image_no_exif.save(output_path) + +# 2. 旋转图像 +def rotate_image(image_path, angle, output_path): + # 使用 OpenCV 读取图像 + image = cv2.imread(image_path) + + # 获取图像的中心 + center = (image.shape[1] // 2, image.shape[0] // 2) + + # 获取旋转矩阵 + rotation_matrix = cv2.getRotationMatrix2D(center, angle, 1.0) + + # 执行旋转 + rotated_image = cv2.warpAffine(image, rotation_matrix, (image.shape[1], image.shape[0])) + + # 保存旋转后的图像 + cv2.imwrite(output_path, rotated_image) + #如果老影棚没有做过旋转坐标的照片的,则要做一次旋转坐标 def rateImages(pid): #遍历文件夹下的所有图片