import subprocess
import os
from os import path
import shutil
plypath=r"D:\Point_cloud\AVS_dataset"
ply_name={"Ford_01_AVS_1mm":"Ford_01_AVS_1mm\\Ford_01_1mm-0100.ply",\
"Ford_02_AVS_1mm":"Ford_02_AVS_1mm\\Ford_02_1mm-0100.ply",\
"Ford_03_AVS_1mm":"Ford_03_AVS_1mm\\Ford_03_1mm-0100.ply",
"Livox_01_all_in_one_1mm":"Livox_01_all_in_one_1mm\\Livox_01_all_1mm-0000.ply",\
"Livox_02_all_in_one_1mm":"Livox_01_all_in_one_1mm\\Livox_01_all_1mm-0000.ply",}
cfg_path=r"D:\AVS\code\74\Geometry\cfg\script"
condition={"C1-limitlossyG-lossyA-ai":("r1","r2","r3","r4","r5","r6"),\
"C2-losslessG-lossyA-ai":("r1","r2","r3","r4","r5","r6"),\
"C3-losslessG-limitlossyA-ai":("r1","r2","r3","r4","r5"),\
"C4-losslessG-losslessA-ai":" "}
bin_kind=("0")
framed_count={"Ford_01_AVS_1mm":10,\
"Ford_02_AVS_1mm":600,\
"Ford_03_AVS_1mm":600,\
"Livox_01_all_in_one_1mm":387,\
"Livox_02_all_in_one_1mm":387}
compressed_init={"Ford_01_AVS_1mm":"compressed-0100.bin",\
"Ford_02_AVS_1mm":"compressed-0100.bin",\
"Ford_03_AVS_1mm":"compressed-0100.bin",\
"Livox_01_all_in_one_1mm":"compressed-0000.bin",\
"Livox_02_all_in_one_1mm":"compressed-0000.bin"}
workpath=path.dirname(__file__)
Text_path=workpath+"\\"+"Text"
if os.path.exists(Text_path):
shutil.rmtree(Text_path)
os.mkdir(Text_path)
text_condition=("C1-limitlossyG-lossyA-ai","C2-losslessG-lossyA-ai","C3-losslessG-limitlossyA-ai",\
"C4-losslessG-losslessA-ai")
for con_dir in text_condition:
os.mkdir(Text_path+"\\"+con_dir)
name=type(condition["C1-limitlossyG-lossyA-ai"])
def run(exe_dir,ply_dir,cfg_path,text_dir,name):
temp_file=open(text_dir,'a')
encode_dir=exe_dir+"_encoder.exe"
encode_cfg=cfg_path+"\\"+"encoder.cfg"
encode_args=encode_dir+" -c "+encode_cfg+" --input "+ ply_dir+\
" --bitstream "+workpath+"\\"+"compressed.bin --md5_file_name md5.txt "\
"--frames_to_be_coded "+str(framed_count[name])+" --recon "+workpath+"\\"+"reconstruct.ply"
decode_dir=exe_dir+"_decoder.exe"
decode_cfg=cfg_path+"\\"+"decoder.cfg"
decode_args=decode_dir+" -c "+decode_cfg+" --bitstream "+workpath+"\\"+ compressed_init[name]+" --md5_file_name md5.txt "\
"--frames_to_be_coded "+str(framed_count[name])+" --recon "+workpath+"\\"+"dec.ply"
encoder=subprocess.Popen(encode_args,stdout=temp_file)
encoder.wait()
decoder=subprocess.Popen(decode_args,stdout=temp_file)
decoder.wait()
def begin(ply_name,condition,bin_kind):
for name in ply_name:
for CD in condition:
for QP in condition[CD]:
for B in bin_kind:
exe_dir=workpath+"\\"+B
ply_dir=plypath+"\\"+ply_name[name]
cfg_dir=cfg_path+"\\"+CD+"\\"+name+"\\"+QP
text_dir=Text_path+"\\"+CD+"\\"+name+"_"+B+".txt"
run(exe_dir,ply_dir,cfg_dir,text_dir,name)
begin(ply_name,condition,bin_kind)
今天自己动手写了一个利用模块subprocess中的类Popen调用可执行文件,注意这个模块由于是可以调用多个线程,所以在同一个代码块写两个subprocess.Popen的时候,需要调用这个封装类的wait()函数,否则会出现乱序的问题。或者直接调用这个类的**subprocess.call(encode_args,stdout=temp_file)**也可以达到两个线程之间相互等待的一个过程。