import os import sys import numpy import subprocess import pandas as pd import time SOURCE_DIR = '/home/mc365/sources/' STROAGE_DIR = '/hdd/' LOG_EXTRACT = '/log_extract.txt' #NOTE: CHANGE CFG, WEIGHT, .data CFG_FILE = 'yolov4_7gpu.cfg' WEIGHT_FILE = 'yolov4_7gpu_last.weights' DATA_FILE = 'obj.data' FRAME_COUNTER = 0 N_OF_FRAME = 1800 SURGEON_DIR = os.path.abspath(STROAGE_DIR+os.listdir('/hdd/')[0]) CALL_DEPTH = ['python3',SOURCE_DIR+'depthsensing.py', '-c', SOURCE_DIR+CFG_FILE, '-w', SOURCE_DIR+WEIGHT_FILE, '-m', SOURCE_DIR+DATA_FILE] #print(SURGEON_DIR) def extract_surgeon (): svo2list = [file for file in os.listdir(os.path.abspath(SURGEON_DIR)) if file.endswith('2.svo')] svo2list= sorted(svo2list) del svo2list[-1] for svo in svo2list: REST_OF_CALL_DEPTH = ['-s',SURGEON_DIR+'/'+svo, '-o', SURGEON_DIR+'/'+svo[:5]+'.csv'] subprocess.call(CALL_DEPTH+REST_OF_CALL_DEPTH) def concat_csv(): csv2list = [file for file in os.listdir(os.path.abspath(SURGEON_DIR)) if file.endswith('2.csv')] csv2list = sorted(csv2list) fc = FRAME_COUNTER nf = N_OF_FRAME conc_df = pd.DataFrame(data={'x': [], 'y': [], 'z': [], 'frame': []}) for csv in csv2list: df = pd.read_csv(os.path.join(SURGEON_DIR,csv), header=0) df['frame'] = df['frame'] + fc conc_df = pd.concat([conc_df,df]) fc += nf conc_df.to_csv(os.path.join(SURGEON_DIR,'cam2.csv'), index=False) def concat_csv_with_nms(): csv2list = [file for file in os.listdir(os.path.abspath(SURGEON_DIR)) if file.endswith('2_nms.csv')] csv2list = sorted(csv2list) fc = FRAME_COUNTER nf = N_OF_FRAME conc_df = pd.DataFrame(data={'x': [], 'y': [], 'z': [], 'nms':[],'frame': []}) for csv in csv2list: df = pd.read_csv(os.path.join(SURGEON_DIR,csv), header=0) df['frame'] = df['frame'] + fc conc_df = pd.concat([conc_df,df]) fc += nf conc_df.to_csv(os.path.join(SURGEON_DIR,'cam2_nms.csv'), index=False) def log_write(): exttime = time.localtime() csv2list = [file for file in os.listdir(os.path.abspath(SURGEON_DIR)) if file.endswith('2.csv')] with open (os.path.abspath(SURGEON_DIR+LOG_EXTRACT), "a") as log_extract: log_extract.write("\n[EXTRACT] EXTRACT %d svo files finishied at %04d/%02d/%02d %02d:%02d:%02d" % (len(csv2list)-1,exttime.tm_year, exttime.tm_mon, exttime.tm_mday, exttime.tm_hour, exttime.tm_min, exttime.tm_sec)) def main(): extract_surgeon() concat_csv() concat_csv_with_nms() log_write() if __name__ == '__main__': main()