You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
206 lines
7.0 KiB
206 lines
7.0 KiB
import os, sys, shutil, subprocess, shlex,oss2,requests |
|
sys.path.append('e:\\libs\\') |
|
import config |
|
import xml.etree.ElementTree as ET |
|
import common |
|
def is_already(pid): |
|
|
|
if not os.path.exists("D://make2/export_build_info/finished.txt"): |
|
#创建文件 |
|
with open("D://make2/export_build_info/finished.txt", 'w') as f: |
|
f.write("") |
|
return False |
|
#读取已经完成的pid |
|
with open("D://make2/export_build_info/finished.txt", 'r') as f: |
|
lines = f.readlines() |
|
for line in lines: |
|
if str(pid) == str(line.strip()): |
|
return True |
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def writeImageList(pid): |
|
# pid = "185005" |
|
imageListTxt = f"D://{pid}/{pid}_imageList.txt" |
|
if not os.path.exists(imageListTxt): |
|
with open(imageListTxt, 'w') as f: |
|
f.write("") |
|
filePath = f"D://{pid}//{pid}.rcproj" |
|
tree = ET.parse(filePath) |
|
root = tree.getroot() |
|
fileName = [] |
|
for input_tag in root.findall(".//input"): |
|
tempFileName = input_tag.get("fileName") |
|
if tempFileName: |
|
fileName.append(tempFileName) |
|
sourceFileNames = [] |
|
for sourceFile in fileName: |
|
tempSourceName = sourceFile.replace(f"D:\{pid}\photo1\\","") |
|
tempSourceName = tempSourceName.replace(f"D:\{pid}\photo2\\","") |
|
print("tempSourceName",tempSourceName) |
|
#遍历指定的文件减价 |
|
for file in os.listdir(f"D://{pid}/depthAndMask"): |
|
if ".jpg.depth.exr" not in file: |
|
continue |
|
#截取图片名称 |
|
tempName = file.replace(".depth.exr","") |
|
if tempName == tempSourceName: |
|
#sourceFileNames.append(sourceFile) |
|
#写入到文件中 |
|
print(f"写入到文件-{sourceFile}") |
|
with open(imageListTxt, 'a+') as f: |
|
f.write(f"{sourceFile}\n") |
|
|
|
|
|
def exportInfo(pid): |
|
newCopyFilePath = f"D://{pid}/{pid}.rcproj" |
|
#判断是否存在目录,不存在则创建 |
|
depthMaskPath = f"D://{pid}/depthAndMask" |
|
#删除文件夹 |
|
try: |
|
shutil.rmtree(depthMaskPath) |
|
except Exception as e: |
|
print(e) |
|
|
|
|
|
if not os.path.exists(f"D://{pid}/depthAndMask"): |
|
os.makedirs(f"D://{pid}/depthAndMask") |
|
|
|
imageListTxt = f"D://{pid}/{pid}_imageList.txt" |
|
try: |
|
os.remove(imageListTxt) |
|
except Exception as e: |
|
print(e) |
|
|
|
if not os.path.exists(imageListTxt): |
|
with open(imageListTxt, 'w') as f: |
|
f.write("") |
|
|
|
maskPath = f"D://{pid}/mask" |
|
|
|
try: |
|
shutil.rmtree(maskPath) |
|
except Exception as e: |
|
print(f"删除文件夹失败{e}") |
|
if not os.path.exists(f"D://{pid}/mask"): |
|
os.makedirs(f"D://{pid}/mask") |
|
|
|
depthPath = f"D://{pid}/depth" |
|
try: |
|
shutil.rmtree(depthPath) |
|
except Exception as e: |
|
print(e) |
|
|
|
if not os.path.exists(f"D://{pid}/depth"): |
|
os.makedirs(f"D://{pid}/depth") |
|
|
|
registrationPath = f"D://{pid}/reg" |
|
try: |
|
shutil.rmtree(registrationPath) |
|
except Exception as e: |
|
print(e) |
|
if not os.path.exists(registrationPath): |
|
os.makedirs(registrationPath) |
|
|
|
#如果存在则执行打开命令 |
|
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} -load "{newCopyFilePath}" -exportRegistration "D://{pid}/reg/{pid}_registration.out" "D://make2/config/registration_export_config.xml" -exportDepthAndMask "D://{pid}/depthAndMask" "D://make2/config/depth_mask_config.xml" -quit' |
|
# print(cmd) |
|
cmd = shlex.split(cmd) |
|
res = subprocess.run(cmd) |
|
|
|
writeImageList(pid) |
|
|
|
#删除掉 depthMaskPath 里 文件名 包含 _1. 的文件 |
|
for file in os.listdir(depthMaskPath): |
|
#将遍历出来的文件名进行判断,如果是_8.jpg.mask _1.jpg.mask 写入到pid_imgList.txt中 |
|
# if "_8.jpg.mask" in file: |
|
# jpgPath = f"D://{pid}/photo2/"+file.replace(".mask", "") |
|
# jpgPath = jpgPath.replace(".png", "") |
|
# print("_8",jpgPath) |
|
# with open(imageListTxt, 'a+') as f: |
|
# f.write(f"{jpgPath}\n") |
|
|
|
# if "_1.jpg.mask" in file: |
|
# jpgPath = f"D://{pid}/photo1/"+file.replace(".mask", "") |
|
# jpgPath = jpgPath.replace(".png", "") |
|
# print("_1",jpgPath) |
|
# with open(imageListTxt, 'a+') as f: |
|
# f.write(f"{jpgPath}\n") |
|
|
|
if "_1." in file: |
|
os.remove(f"{depthMaskPath}/{file}") |
|
|
|
if "_8.jpg.mask" in file: |
|
try: |
|
shutil.move(f"{depthMaskPath}/{file}",maskPath) |
|
except Exception as e: |
|
print(f"移动文件失败1{e}") |
|
|
|
|
|
if "_8.jpg.depth" in file: |
|
try: |
|
shutil.move(f"{depthMaskPath}/{file}",depthPath) |
|
except Exception as e: |
|
print(f"移动文件失败2{e}") |
|
|
|
|
|
writeImageList(str(pid)) |
|
|
|
#删除已存在数据,防止版本冲突 |
|
try: |
|
deleteList = [] |
|
for obj in oss2.ObjectIterator(config.oss_bucket,prefix=f'objs/auto/{pid}/model_info_v2'): |
|
deleteList.append(obj.key) |
|
config.oss_bucket.batch_delete_objects(deleteList) |
|
except Exception as e: |
|
print("") |
|
|
|
#上传到oss 上 |
|
#将 D:\{pid}\{pid}_registration.out 上传到 oss model_info |
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/model_info_v2/{pid}_registration.out', f'D://{pid}/reg/{pid}_registration.out') |
|
# imageList.txt |
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/model_info_v2/{pid}_imageList.txt', imageListTxt) |
|
if os.path.exists(f"{depthMaskPath}/imageList.txt"): |
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/model_info_v2/imageList.txt', f"{depthMaskPath}/imageList.txt") |
|
# depth 和 mask 上传 |
|
print("上传 mask") |
|
for file in os.listdir(maskPath): |
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/model_info_v2/mask/{file}', f"{maskPath}/{file}") |
|
|
|
print("上传 depth") |
|
for file in os.listdir(depthPath): |
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/model_info_v2/depth/{file}', f"{depthPath}/{file}") |
|
|
|
#上传几遍照片 |
|
print("上传 reg") |
|
for file in os.listdir(registrationPath): |
|
if "_1.jpg" in file: |
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/model_info_v2/reg/photo1/{file}', f"{registrationPath}/{file}") |
|
|
|
if "_8.jpg" in file: |
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/model_info_v2/reg/photo2/{file}', f"{registrationPath}/{file}") |
|
|
|
tempFile = f"D://{pid}//finish.txt" |
|
#创建文件 |
|
with open(tempFile, 'w') as f: |
|
f.write("") |
|
|
|
print(f"完成的PID-{pid}") |
|
|
|
|
|
#写入到指定的文件中 |
|
with open("D://make2/pid.text", 'a+') as f: |
|
f.write(f"{pid},") |
|
|
|
#删除文件 |
|
# common.removeFolder(str(pid)) |
|
# shutil.rmtree(f"D://{pid}",ignore_errors=True) |
|
|
|
#插入队列 |
|
tempUrl = "https://mp.api.suwa3d.com/api/customerP3dLog/addGaussianRedisQueneu?pid="+str(pid) |
|
requests.get(tempUrl) |
|
|
|
# exportInfo("181593") |