124 lines
5.8 KiB
Python
124 lines
5.8 KiB
Python
import os, sys, time, shutil, subprocess, shlex, json,oss2
|
||
import platform
|
||
if platform.system() == 'Windows':
|
||
sys.path.append('e:\\libs\\')
|
||
else:
|
||
sys.path.append('/data/deploy/make3d/make2/libs/')
|
||
|
||
import config, libs, libs_db
|
||
|
||
def upload_xmp(pid):
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 上传xmp文件之前先删除oss上的xmp文件所在目录...')
|
||
pid = str(pid)
|
||
psid = libs.getPSid(pid)
|
||
#移除掉旧的文件夹
|
||
#config.oss_bucket.delete_object(f'xmps/{pid}/')
|
||
#删除oss 上的文件夹里的内容
|
||
|
||
#判断是否存在该目录
|
||
if config.oss_bucket.object_exists(f'xmps/{psid}/') == True:
|
||
object_list = oss2.ObjectIterator(config.oss_bucket, prefix=f'xmps/{psid}/')
|
||
if not any(object_list):
|
||
config.oss_bucket.batch_delete_objects([obj.key for obj in object_list])
|
||
|
||
start_time = time.time()
|
||
workdir = os.path.join(config.workdir, pid)
|
||
##psid = libs.getPSid(pid)
|
||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/{psid}.rcbox', os.path.join(workdir, f'{pid}.rcbox'))
|
||
for xmp in os.listdir(os.path.join(workdir, 'photo1')):
|
||
if xmp.endswith('.xmp'):
|
||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/mesh/{xmp}', os.path.join(workdir, 'photo1', xmp))
|
||
for xmp in os.listdir(os.path.join(workdir, 'photo2')):
|
||
if xmp.endswith('.xmp'):
|
||
config.oss_bucket.put_object_from_file(f'xmps/{psid}/texture/{xmp}', os.path.join(workdir, 'photo2', xmp))
|
||
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} xmp文件上传完成,共费时{time.time() - start_time}秒')
|
||
|
||
def main(pid, lock=False):
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 开始计算相机位姿...')
|
||
start_time = time.time()
|
||
libs.down_from_oss(config.oss_bucket, config.workdir, pid)
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 图片下载完成,共费时{libs.diff_time(start_time)}')
|
||
|
||
start_time = time.time()
|
||
photo1_path = os.path.join(config.workdir, pid, 'photo1')
|
||
photo2_path = os.path.join(config.workdir, pid, 'photo2')
|
||
photos1_count = len(os.listdir(photo1_path))
|
||
photos2_count = len(os.listdir(photo2_path))
|
||
if photos1_count + photos2_count < 164:
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} photo1数量{photos1_count} photo2数量{photos2_count},未能覆盖所有相机,是否继续计算相机位姿?')
|
||
continue_or_not = input('是否继续计算相机位姿?(y/n)')
|
||
if continue_or_not == 'y':
|
||
pass
|
||
else:
|
||
sys.exit(0)
|
||
|
||
if lock:
|
||
exportxmp = ' -exportXMP "D:\\make2\\config\\exportXMP.config.lock.xml" '
|
||
else:
|
||
exportxmp = ' -exportXMP "D:\\make2\\config\\exportXMP.config.xml" '
|
||
|
||
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} \
|
||
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" \
|
||
-addFolder "{os.path.join(config.workdir, pid, "photo1")}" -selectAllImages \
|
||
-detectMarkers "D:\\make2\\config\\detectMarkers.config.xml" \
|
||
-align -align \
|
||
{exportxmp} \
|
||
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit'
|
||
print(cmd)
|
||
cmd = shlex.split(cmd)
|
||
res = subprocess.run(cmd)
|
||
|
||
# TODO:加入report相机位姿质量评估
|
||
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} photo1相机位姿完成,共费时{libs.diff_time(start_time)}')
|
||
|
||
for xmp in os.listdir(photo1_path):
|
||
if xmp.endswith('.xmp'):
|
||
shutil.copy(os.path.join(photo1_path, xmp), os.path.join(photo2_path, xmp.replace('_1.xmp', '_8.xmp')))
|
||
|
||
psid = libs.getPSid(pid)
|
||
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} \
|
||
-load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" {config.r["setTextureFalse"]} \
|
||
-addFolder "{os.path.join(config.workdir, pid, "photo2")}" -selectAllImages \
|
||
-detectMarkers "D:\\make2\\config\\detectMarkers.config.xml" \
|
||
{libs.get_defineDistances(psid)} -update -align -align {config.r2["setRegion"]} \
|
||
{exportxmp} \
|
||
-exportReconstructionRegion "{os.path.join(config.workdir, pid, f"{pid}.rcbox")}" \
|
||
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}"'
|
||
print(cmd)
|
||
cmd = shlex.split(cmd)
|
||
res = subprocess.run(cmd)
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} photo2相机位姿完成,共费时{libs.diff_time(start_time)}')
|
||
|
||
# TODO:加入report相机位姿质量评估
|
||
if not lock:
|
||
upload_or_not = input('是否上传oss?(y/n)')
|
||
if upload_or_not == 'y':
|
||
upload_xmp(pid)
|
||
#上传坐标的话要判断该影棚是否走新的建模系统,如果不是走新的建模系统,就要更新为走新的建模系统
|
||
libs_db.change_to_new_make_psid(psid)
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} xmp文件上传完成,共费时{libs.diff_time(start_time)}')
|
||
|
||
delete_or_not = input('是否删除本地文件?(y/n)')
|
||
if delete_or_not == 'y':
|
||
shutil.rmtree(os.path.join(config.workdir, pid))
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 本地文件已删除')
|
||
else:
|
||
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 本地文件未删除')
|
||
|
||
if __name__ == '__main__':
|
||
if len(sys.argv) == 2:
|
||
pids = sys.argv[1].split(',')
|
||
for pid in pids:
|
||
main(pid)
|
||
elif len(sys.argv) == 3:
|
||
pids = sys.argv[1].split(',')
|
||
for pid in pids:
|
||
if sys.argv[2] == 'lock':
|
||
main(pid, lock=True)
|
||
else:
|
||
main(pid, lock=False)
|
||
else:
|
||
print(f'useage: python {sys.argv[0]} pid1,pid2,pid3 [lock]')
|
||
sys.exit(1) |