import os, time, json, requests, shutil, psutil from tqdm import tqdm from PIL import Image, ImageEnhance import config from concurrent.futures import ThreadPoolExecutor def find_blender_bin_path(): base_path = 'C:\\Program Files\\Blender Foundation\\' if os.path.exists(base_path): for dir in os.listdir(base_path): if dir.startswith('Blender'): blender_bin_path = base_path + dir + '\\blender.exe' return f'"{blender_bin_path}"' else: print('未找到blender安装目录') exit(1) # def resize_photos(photo_path, ratio=0.5): # for filename in os.listdir(photo_path): # if filename.endswith('.jpg'): # img = Image.open(os.path.join(photo_path, filename)) # img = rotate_image(img) # w, h = img.size # img = img.resize((int(w * ratio), int(h * ratio))) # img.save(os.path.join(photo_path, filename)) # def rotate_image(image): # # 检查图像的EXIF数据是否包含方向信息 # try: # exif = image._getexif() # orientation = exif.get(0x0112) # except: # orientation = None # # 根据方向信息旋转图像 # if orientation == 3: # image = image.rotate(180, expand=True) # elif orientation == 6: # image = image.rotate(270, expand=True) # elif orientation == 8: # image = image.rotate(90, expand=True) # return image # def get_ps_adjust_photo_para(psid): # res = requests.get(config.urls['get_ps_adjust_photo_para_url'], params={'id': psid}) # print(res.json()) # paras = res.json()['data'] # brightness_factor, saturation_factor, temperature_factor = float(paras['brightness']), float(paras['saturation']), float(paras['colorTemperature']) # return brightness_factor, saturation_factor, temperature_factor # def getPSid(pid): # res = requests.get(config.urls['get_psid_url'], params={'pid': pid}) # print('get_psid_url:', res.url) # print('res:', res.text) # res = json.loads(res.text) # return str(res['data']) # def getHeadCount(pid): # return 1 # res = requests.get(config.urls['get_printinfo_url'], params={'id': pid}) # print('get_printinfo_url:', res.url) # print('res:', res.text) # if res.status_code != 200: # print('获取人数失败,程序退出') # exit(1) # res = json.loads(res.text) # return res['data']['headcount'] # def get_ps_type(pid): # # return 1:圆形影棚 2:方形影棚 # #res = requests.get(config.urls['get_ps_type_url'], params={'pid': pid}) # return 2 # def find_valid_camera_on_oss(pid): # if get_ps_type(pid) == 1: # print('当前拍照影棚为:圆形影棚') # cameras = (103, 93, 113) # else: # print('当前拍照影棚为:方形影棚') # cameras = (74, 64, 84) # find_camera = 0 # for camera in cameras: # objectkey = f'photos/{pid}/photo2/{camera}_8.jpg' # find = config.oss_bucket.object_exists(objectkey) # if find: # find_camera = camera # break # print('找到有效正脸相机:', find_camera) # if find_camera == 0: # print('{cameras}没有找到照片,程序退出') # exit(1) # return find_camera # def set_photos_join_type(workdir, pid, photoN, mesh = '0', texture='0'): # photoN_path = os.path.join(workdir, pid, photoN) # for xmp in os.listdir(photoN_path): # if xmp.endswith('.xmp'): # xmp_path = os.path.join(photoN_path, xmp) # with open(xmp_path, 'r') as f: # lines = f.readlines() # lines = [line.replace('xcr:InMeshing="0"', f'xcr:InMeshing="{mesh}"') for line in lines] # lines = [line.replace('xcr:InMeshing="1"', f'xcr:InMeshing="{mesh}"') for line in lines] # lines = [line.replace('xcr:InTexturing="0"', f'xcr:InTexturing="{texture}"') for line in lines] # lines = [line.replace('xcr:InTexturing="1"', f'xcr:InTexturing="{texture}"') for line in lines] # with open(xmp_path, 'w') as f: # f.writelines(lines) def set_photo_join_type(workdir, pid, photoN, camera_id, mesh = '0', texture='0'): if photoN == 'photo1': filename = os.path.join(workdir, pid, photoN, f'{camera_id}_1.xmp') else: filename = os.path.join(workdir, pid, photoN, f'{camera_id}_8.xmp') with open(filename, 'r') as f: lines = f.readlines() lines = [line.replace('xcr:InMeshing="0"', f'xcr:InMeshing="{mesh}"') for line in lines] lines = [line.replace('xcr:InMeshing="1"', f'xcr:InMeshing="{mesh}"') for line in lines] lines = [line.replace('xcr:InTexturing="0"', f'xcr:InTexturing="{texture}"') for line in lines] lines = [line.replace('xcr:InTexturing="1"', f'xcr:InTexturing="{texture}"') for line in lines] with open(filename, 'w') as f: f.writelines(lines) def diff_time(start_time): # 按照分:秒的方式返回时间差 end_time = time.time() diff = end_time - start_time m, s = divmod(diff, 60) return f'{int(m)}分{int(s)}秒'