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.
185 lines
8.0 KiB
185 lines
8.0 KiB
import os, sys, time, shlex, subprocess, shutil, requests, cv2, numpy as np |
|
from PIL import Image |
|
import platform |
|
if platform.system() == 'Windows': |
|
sys.path.append('e:\\libs\\') |
|
#sys.path.append('libs') |
|
else: |
|
sys.path.append('/data/deploy/make3d/make2/libs/') |
|
import config, libs, libs_db,main_service_db |
|
# 2. 手动操作建模做成建模 |
|
# 2.0 检测是否存在项目,不存在就下载,存在就清除项目其它无用的文件 |
|
# 2.1 初始化工程, 根据参数 加入 photo1 或者 photo 2 的 照片, 对齐 , 导出坐标, 将坐标复制到 另外一个文件夹, 测距, 重建区域, 然后调用step2 |
|
|
|
#根据pid 检测是否存在项目,不存在就下载,存在就清除项目其它无用的文件 |
|
def check_pid_file(pid): |
|
#检测是否存在目录 |
|
path = os.path.join(config.workdir, pid) |
|
if not os.path.exists(path): |
|
#不存在就在就下载目录 |
|
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)}') |
|
else: |
|
#存在的话就检测是否有photo1 和 photo2 之外的目录或者文件,有的话就删除 |
|
for file in os.listdir(path): |
|
if file != 'photo1' and file != 'photo2': |
|
if os.path.isfile(os.path.join(path, file)): |
|
os.remove(os.path.join(path, file)) |
|
else: |
|
shutil.rmtree(os.path.join(path, file)) |
|
|
|
#判断photo1 和 photo2 目录里的文件是否存在xmp 文件,存在的话就删除 |
|
for file in os.listdir(os.path.join(path, 'photo1')): |
|
if file.endswith('.xmp'): |
|
os.remove(os.path.join(path, 'photo1', file)) |
|
|
|
for file in os.listdir(os.path.join(path, 'photo2')): |
|
if file.endswith('.xmp'): |
|
os.remove(os.path.join(path, 'photo2', file)) |
|
|
|
|
|
#根据参数初始化操作 |
|
def cmd_run(pid,usePhoto = "1",lock=False): |
|
pid = str(pid) |
|
#检测文件并且下载处理文件 |
|
check_pid_file(pid) |
|
|
|
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)) |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} photo1数量{photos1_count} photo2数量{photos2_count}') |
|
|
|
#xmp 坐标是要用 lock的 还是 unlock 的 |
|
if lock: |
|
exportxmp = ' -exportXMP "D:\\make2\\config\\exportXMP.config.lock.xml" ' |
|
else: |
|
exportxmp = ' -exportXMP "D:\\make2\\config\\exportXMP.config.xml" ' |
|
|
|
usePhoto = "photo"+str(usePhoto) |
|
|
|
#执行命令 |
|
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, usePhoto)}" -selectAllImages \ |
|
-detectMarkers "D:\\make2\\config\\detectMarkers.config.xml" \ |
|
-align -align -align -align \ |
|
{exportxmp} \ |
|
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit' |
|
print(cmd) |
|
cmd = shlex.split(cmd) |
|
res = subprocess.run(cmd) |
|
|
|
#根据参数转变路劲,复制photo1 里的xmp 文件到 photo2 里,或者 photo2 里的xmp 文件到 photo1 里 |
|
sourceFile = photo1_path |
|
targetFile = photo2_path |
|
if usePhoto == "photo2": |
|
sourceFile = photo2_path |
|
targetFile = photo1_path |
|
#复制xmp文件 |
|
for xmp in os.listdir(sourceFile): |
|
if xmp.endswith('.xmp'): |
|
if usePhoto == "photo1": |
|
shutil.copy(os.path.join(sourceFile, xmp), os.path.join(targetFile,xmp.replace('_1.xmp', '_8.xmp'))) |
|
|
|
if usePhoto == "photo2": |
|
shutil.copy(os.path.join(sourceFile, xmp), os.path.join(targetFile,xmp.replace('_8.xmp', '_1.xmp'))) |
|
|
|
|
|
|
|
#如果是photo2的话,就要将photo2 的 xmp 重命名成 _8.xmp |
|
# if usePhoto == "photo2": |
|
# for xmp in os.listdir(sourceFile): |
|
# if xmp.endswith('.xmp'): |
|
# #重名名.xmp 结尾的文件 |
|
# os.rename(os.path.join(sourceFile, xmp), os.path.join(sourceFile,xmp.replace('_1.xmp', '_8.xmp'))) |
|
# print("坐标复制完成") |
|
# exit() |
|
|
|
#将两组图片进行重新对齐 然后重建区域 |
|
psid = libs.getPSid(pid) |
|
cmd = f'{config.rcbin} -setInstanceName {pid} \ |
|
-load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" {config.r["setTextureFalse"]} \ |
|
-addFolder "{targetFile}" -selectAllImages \ |
|
-detectMarkers "D:\\make2\\config\\detectMarkers.config.xml" \ |
|
{libs.get_defineDistances(psid)} -update -align -align -align -align {config.r2["setRegion"]} \ |
|
{exportxmp} \ |
|
-exportReconstructionRegion "{os.path.join(config.workdir, pid, f"{pid}.rcbox")}" \ |
|
-selectImage "{os.path.join(config.workdir,pid,"photo2")}/*" -enableTexturingAndColoring true \ |
|
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit' |
|
|
|
|
|
|
|
|
|
print(cmd) |
|
cmd = shlex.split(cmd) |
|
res = subprocess.run(cmd) |
|
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} step1完成,共费时{libs.diff_time(start_time)}') |
|
|
|
#调用step2 |
|
time.sleep(2) |
|
# os.system(f'python main_step2.py {pid}') |
|
os.system(f'python D://make2/export_build_info/main_step2.py {pid}') |
|
|
|
|
|
def is_already(pid): |
|
|
|
|
|
#读取已经完成的pid |
|
with open("D://make2/export_build_info/finished.txt", 'r') as f: |
|
lines = f.readlines() |
|
for line in lines: |
|
print("line",str(line.strip())) |
|
if str(pid) == str(line.strip()): |
|
print("匹配成功") |
|
return True |
|
return False |
|
|
|
if __name__ == '__main__': |
|
already = [184219,184215,184209,184069,184059,183868,183817,183791,183613,183054,182855,182854,184206,184201,184199,184164,184087,184076,184029,184013,183993,183952,183888,183882,183824,183815,183812] |
|
|
|
arrPids = [184219,184215,184209,184206,184201,184199,184164,184087,184076,184069,184059,184029,184013,183993,183952,183888,183882,183868,183824,183817,183815,183812,183791,183777,183715,183705,183670,183613,183573,182974,182983,182985,182989,182997,183007,183051,183060,183054,183053,183097,183119,183108,183139,183141,183155,183163,183169,183180,183191,183196,183214,183244,183266,183278,183275,183309,183402,183422,183440,182974,182964,182958,182956,182916,182855,182854,182820,182787,182800,182809,182780,182772,182770,182766,182754,182742,182740,182723,182707,182647,182643,182614,182595,182563,182557,182547,182546,182538,182530,182517,182498,182478,182452,182386,182352,182285,182266,182260,182230,182224] |
|
for pid in arrPids: |
|
if pid in already: |
|
continue |
|
print("正在处理-",pid) |
|
|
|
|
|
|
|
if is_already(str(pid)) == True: |
|
continue |
|
# i += 1 |
|
# continue |
|
#写入到 |
|
with open("D://make2/export_build_info/finished.txt", 'a+') as f: |
|
f.write(f"{pid}\n") |
|
|
|
|
|
cmd_run(str(pid),usePhoto = "1",lock=False) |
|
|
|
# if len(sys.argv) == 2: |
|
# pids = sys.argv[1].split(',') |
|
# for pid in pids: |
|
# cmd_run(pid,usePhoto = "1",lock=False) |
|
# elif len(sys.argv) == 3: |
|
# pids = sys.argv[1].split(',') |
|
# for pid in pids: |
|
# if sys.argv[2] == '2': |
|
# cmd_run(pid,usePhoto = "2",lock=False) |
|
# else: |
|
# cmd_run(pid,usePhoto = "1",lock=False) |
|
# elif len(sys.argv) == 4: |
|
# pids = sys.argv[1].split(',') |
|
# usePhoto = sys.argv[2] |
|
# lock = sys.argv[3] |
|
# for pid in pids: |
|
# cmd_run(pid,usePhoto = usePhoto,lock=lock) |
|
|
|
# else: |
|
# print(f'useage: python {sys.argv[0]} pid1,pid2,pid3 photo = 1/2 lock = True/False') |
|
# sys.exit(1) |