diff --git a/main_step1.py b/main_step1.py index 24fb02e..a90a313 100644 --- a/main_step1.py +++ b/main_step1.py @@ -94,30 +94,6 @@ def detect_markers(psid, pid): # photo3 exist, 设置photo3的xmp文件,不参与建模 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=""): libs_db.start_task({"task_type": "make", "task_key": pid}) @@ -131,10 +107,7 @@ def step1(pid, experience=False, makeloop=True,task_distributed_id="",isNoColorT # 下载图片 start_time = time.time() 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}') 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) continue else: - experience = True + experience = False step1(pid, experience, makeloop,task_distributed_id,isNoColorTexture) else: step1(pid, experience, makeloop,task_distributed_id,isNoColorTexture) @@ -242,7 +215,7 @@ if __name__ == '__main__': experience = False if sys.argv[2] == '1': print('演示测试...') - experience = True + experience = False elif sys.argv[2] == 'NoColorTexture': isNoColorTexture = "NoColorTexture" pids = sys.argv[1].split(',') diff --git a/main_step2.py b/main_step2.py index b710962..65d9e33 100644 --- a/main_step2.py +++ b/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') else: + pass #设置photo2参与贴图,因为有的时候贴图会黑 directory = os.path.join(config.workdir, pid, 'photo2') for root, dirs, files in os.walk(directory): @@ -112,9 +113,16 @@ def make3d(pid): if isExistPoint == True: cmdSmall = "-align" #{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} \ -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) cmd = shlex.split(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文件不存在') 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")): 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")}"\ -exportModel "{pid}" "{os.path.join(config.workdir, pid, "output", f"{pid}.obj")}" "d:\\make2\\config\\ModelExportParams102.xml" -quit' @@ -145,7 +164,7 @@ def make3d(pid): else: # new version #判断是否要进行高精模 if common.task_need_high_model(pid): - calulate_type = 'calculateHighModel' + calulate_type = 'calculateHighModel' else: calulate_type = 'calculateNormalModel' diff --git a/main_step3.py b/main_step3.py index f871a5a..344b441 100644 --- a/main_step3.py +++ b/main_step3.py @@ -6,7 +6,7 @@ if platform.system() == 'Windows': #sys.path.append('libs') else: 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): """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())}) print("step3 已执行完成") #return - + common.removeFolder(str(pid)) def main(pid): if pid == '0': while True: