util.py 1.4 KB
Newer Older
HypoX64's avatar
preview  
HypoX64 已提交
1
import os
H
hypox64 已提交
2
import shutil
H
hypox64 已提交
3

HypoX64's avatar
preview  
HypoX64 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
def Traversal(filedir):
    file_list=[]
    for root,dirs,files in os.walk(filedir): 
        for file in files:
            file_list.append(os.path.join(root,file)) 
        for dir in dirs:
            Traversal(dir)
    return file_list

def is_img(path):
    ext = os.path.splitext(path)[1]
    ext = ext.lower()
    if ext in ['.jpg','.png','.jpeg','.bmp']:
        return True
    else:
        return False

def is_video(path):
    ext = os.path.splitext(path)[1]
    ext = ext.lower()
    if ext in ['.mp4','.flv','.avi','.mov','.mkv','.wmv','.rmvb']:
        return True
    else:
        return False
H
hypox64 已提交
28
        
HypoX64's avatar
preview  
HypoX64 已提交
29 30 31 32
def  writelog(path,log):
    f = open(path,'a+')
    f.write(log+'\n')

H
hypox64 已提交
33 34 35 36 37 38 39
def makedirs(path):
    if os.path.isdir(path):
        print(path,'existed')
    else:
        os.makedirs(path)
        print('makedir:',path)

H
hypox64 已提交
40
def clean_tempfiles(tmp_init=True):
HypoX64's avatar
preview  
HypoX64 已提交
41
    if os.path.isdir('./tmp'):   
H
hypox64 已提交
42 43 44 45 46 47 48
        shutil.rmtree('./tmp')
    if tmp_init:
        os.makedirs('./tmp')
        os.makedirs('./tmp/video2image')
        os.makedirs('./tmp/addmosaic_image')
        os.makedirs('./tmp/mosaic_crop')
        os.makedirs('./tmp/replace_mosaic')
H
hypox64 已提交
49
        os.makedirs('./tmp/ROI_mask')
H
hypox64 已提交
50 51 52 53 54 55

def file_init(opt):
    if not os.path.isdir(opt.result_dir):
        os.makedirs(opt.result_dir)
        print('makedir:',opt.result_dir)
    clean_tempfiles()