Browse Source

优化

master
dongchangxi 2 years ago
parent
commit
2093ff5526
  1. 31
      main_step1.py
  2. 21
      main_step2.py
  3. 4
      main_step3.py

31
main_step1.py

@ -94,30 +94,6 @@ def detect_markers(psid, pid):
# photo3 exist, 设置photo3的xmp文件,不参与建模 # photo3 exist, 设置photo3的xmp文件,不参与建模
libs.set_photo_join_type(config.workdir, pid, 'photo3', filename.split('_')[0], mesh='0', texture='1') libs.set_photo_join_type(config.workdir, pid, 'photo3', filename.split('_')[0], mesh='0', texture='1')
def cal_reconstruction_region(psid, pid):
def fix_region():
region_filename = os.path.join(config.workdir, pid, f'{pid}.rcbox')
with open(region_filename, 'r') as f:
lines = f.readlines()
lines = [line.replace('"NONE" globalCoordinateSystemWkt="NONE" globalCoordinateSystemName="NONE"', '"+proj=geocent +ellps=WGS84 +no_defs" globalCoordinateSystemName="local:1 - Euclidean"') for line in lines]
add_photo3 = ' '
if os.path.exists(os.path.join(config.workdir, pid, 'photo3')):
add_photo3 = ' -addFolder "' + os.path.join(config.workdir, pid, 'photo3') + '" '
cmd = f'{config.rcbin} {config.r2["init"]} -setInstanceName {pid} \
-load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" \
-addFolder "{os.path.join(config.workdir, pid, "photo2")}" -align {add_photo3} \
-detectMarkers "D:\\make2\\config\\detectMarkers.config.xml" {libs.get_defineDistances(psid)} -align -align \
-update {config.r2["setRegion"]} \
-exportControlPointsMeasurements "{os.path.join(config.workdir, pid, f"{pid}.controlPoints.csv")}" "D:\\make2\\config\\exportControlPoints.config.xml" \
-selectAllImages -exportXMP "D:\\make2\\config\\exportXMP.config.xml" \
-exportReconstructionRegion "{os.path.join(config.workdir, pid, f"{pid}.rcbox")}" \
-save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit'
print(cmd)
cmd = shlex.split(cmd)
res = subprocess.run(cmd)
fix_region()
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 重建区域计算完成')
def step1(pid, experience=False, makeloop=True,task_distributed_id="",isNoColorTexture=""): def step1(pid, experience=False, makeloop=True,task_distributed_id="",isNoColorTexture=""):
libs_db.start_task({"task_type": "make", "task_key": pid}) libs_db.start_task({"task_type": "make", "task_key": pid})
@ -131,9 +107,6 @@ def step1(pid, experience=False, makeloop=True,task_distributed_id="",isNoColorT
# 下载图片 # 下载图片
start_time = time.time() start_time = time.time()
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 开始下载图片...') print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 开始下载图片...')
if experience:
libs.down_from_oss(config.oss_bucket, config.workdir, pid, per=50)
else:
libs.down_from_oss(config.oss_bucket, config.workdir, pid) libs.down_from_oss(config.oss_bucket, config.workdir, pid)
os.system(f'python tools/downxmps.py {pid}') os.system(f'python tools/downxmps.py {pid}')
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 图片下载完成,共费时{libs.diff_time(start_time)}') print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {pid} 图片下载完成,共费时{libs.diff_time(start_time)}')
@ -223,7 +196,7 @@ def main(pid, experience=False, makeloop=True,task_distributed_id="",isNoColorTe
time.sleep(3) time.sleep(3)
continue continue
else: else:
experience = True experience = False
step1(pid, experience, makeloop,task_distributed_id,isNoColorTexture) step1(pid, experience, makeloop,task_distributed_id,isNoColorTexture)
else: else:
step1(pid, experience, makeloop,task_distributed_id,isNoColorTexture) step1(pid, experience, makeloop,task_distributed_id,isNoColorTexture)
@ -242,7 +215,7 @@ if __name__ == '__main__':
experience = False experience = False
if sys.argv[2] == '1': if sys.argv[2] == '1':
print('演示测试...') print('演示测试...')
experience = True experience = False
elif sys.argv[2] == 'NoColorTexture': elif sys.argv[2] == 'NoColorTexture':
isNoColorTexture = "NoColorTexture" isNoColorTexture = "NoColorTexture"
pids = sys.argv[1].split(',') pids = sys.argv[1].split(',')

21
main_step2.py

@ -46,6 +46,7 @@ def make3d(pid):
#修改文件内容不参与贴图 #修改文件内容不参与贴图
libs.set_photo_join_type(config.workdir, pid, 'photo2', file.split("_")[0], mesh='0', texture='0') libs.set_photo_join_type(config.workdir, pid, 'photo2', file.split("_")[0], mesh='0', texture='0')
else: else:
pass
#设置photo2参与贴图,因为有的时候贴图会黑 #设置photo2参与贴图,因为有的时候贴图会黑
directory = os.path.join(config.workdir, pid, 'photo2') directory = os.path.join(config.workdir, pid, 'photo2')
for root, dirs, files in os.walk(directory): for root, dirs, files in os.walk(directory):
@ -112,9 +113,16 @@ def make3d(pid):
if isExistPoint == True: if isExistPoint == True:
cmdSmall = "-align" cmdSmall = "-align"
#{config.r1["init"]} #{config.r1["init"]}
if common.task_need_high_model(pid):
calulate_type = '-mvsHigh'
else:
calulate_type = '-mvs'
cmd = f'{config.rcbin} -load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" {cmdSmall} \ cmd = f'{config.rcbin} -load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" {cmdSmall} \
-set "sfmEnableCameraPrior=True" -align -set "sfmEnableCameraPrior=False" -align -setReconstructionRegion "{os.path.join(config.workdir, pid, f"{pid}.rcbox")}" \ -set "sfmEnableCameraPrior=True" -align -set "sfmEnableCameraPrior=False" -align -setReconstructionRegion "{os.path.join(config.workdir, pid, f"{pid}.rcbox")}" \
-mvs -modelSelectMaximalConnectedComponent -modelInvertSelection -modelRemoveSelectedTriangles -closeHoles -clean -simplify {simplify_value} -smooth -unwrap -calculateTexture -renameModel {pid} -save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit' {calulate_type} -modelSelectMaximalConnectedComponent -modelInvertSelection -modelRemoveSelectedTriangles -closeHoles -clean -simplify {simplify_value} -smooth -unwrap -calculateTexture -renameModel {pid} -save "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}" -quit'
print(cmd) print(cmd)
cmd = shlex.split(cmd) cmd = shlex.split(cmd)
res = subprocess.run(cmd) res = subprocess.run(cmd)
@ -129,10 +137,21 @@ def make3d(pid):
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} rcproj文件不存在') print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} rcproj文件不存在')
return return
#复制文件
shutil.copy(os.path.join(config.workdir, pid, f'{pid}.rcproj'), os.path.join(config.workdir, pid, f'{pid}_screen.rcproj'))
time.sleep(2)
#打开工程文件
cmd = f'{config.rcbin} -load "{os.path.join(config.workdir, pid, f"{pid}_screen.rcproj")}"'
cmd = shlex.split(cmd)
res = subprocess.run(cmd)
#创建指定文件夹 #创建指定文件夹
if not os.path.exists(os.path.join(config.workdir, pid, "output")): if not os.path.exists(os.path.join(config.workdir, pid, "output")):
os.makedirs(os.path.join(config.workdir, pid, "output")) os.makedirs(os.path.join(config.workdir, pid, "output"))
#判断output目录下是否有文件,有的话删除
files = os.listdir(os.path.join(config.workdir, pid, "output"))
#执行导出 #执行导出
cmd = f'{config.rcbin} -load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}"\ cmd = f'{config.rcbin} -load "{os.path.join(config.workdir, pid, f"{pid}.rcproj")}"\
-exportModel "{pid}" "{os.path.join(config.workdir, pid, "output", f"{pid}.obj")}" "d:\\make2\\config\\ModelExportParams102.xml" -quit' -exportModel "{pid}" "{os.path.join(config.workdir, pid, "output", f"{pid}.obj")}" "d:\\make2\\config\\ModelExportParams102.xml" -quit'

4
main_step3.py

@ -6,7 +6,7 @@ if platform.system() == 'Windows':
#sys.path.append('libs') #sys.path.append('libs')
else: else:
sys.path.append('/data/deploy/make3d/make2/libs/') sys.path.append('/data/deploy/make3d/make2/libs/')
import config, libs, libs_db,main_service_db import config, libs, libs_db,main_service_db,common
def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifiers=False): def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifiers=False):
"""Returns a transformed, triangulated copy of the mesh""" """Returns a transformed, triangulated copy of the mesh"""
@ -217,7 +217,7 @@ def step3(pid,task_distributed_id=""):
main_service_db.update_task_distributed({"id":task_distributed_id,"status":2,"finished_at":time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}) main_service_db.update_task_distributed({"id":task_distributed_id,"status":2,"finished_at":time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())})
print("step3 已执行完成") print("step3 已执行完成")
#return #return
common.removeFolder(str(pid))
def main(pid): def main(pid):
if pid == '0': if pid == '0':
while True: while True:

Loading…
Cancel
Save