import cv2
import numpy as np
import os
save_id = 0
img_path = 'F:\\cpmdata\\ATL350_croptest\\'defdev(img_path,name):
img = cv2.imread(img_path)
cl = np.zeros([560,1224,3])
cr = np.zeros([560,1224,3])
cl = img[:,0:1224]
cr = img[:,1224:2448]
cv2.imwrite('F:\\cpmdata\\1224_560\\'+name.split('.')[0]+'L.bmp',cl)
cv2.imwrite('F:\\cpmdata\\1224_560\\'+name.split('.')[0]+'R.bmp',cr)
if __name__ == '__main__':
for root,dirs,files in os.walk(img_path):
print(root)
for name in files:
print(os.path.join(root,name))
dev(os.path.join(root,name),name)
标注文件 坐标反算
import os
def wtxt(rtxt,ltxt):
rtxt ='F:\\txttest\\annotation\\'+rtxt
ltxt = 'F:\\txttest\\annotation\\'+ltxt
input_file = open(rtxt, 'r+')
f_new = open(ltxt, 'a')
forlinein input_file:
line1 = line.strip()
line1 = line.split(' ')
line2 = line1
if(int(line1[-4])==0):
s = str(int(line1[1])+1224)
line2[1] = str(s)
print(line2)
tems=' '
tema = tems.join(line2)
#tema = tema.replace(line1[1], s)#f_new.write('\n')
f_new.write(tema)
if (int(line1[-4]) == 1):
tem = int(line1.index(line1[-3]))
for i in range(1, tem - 1, 2):
s = str(int(line1[i]) + 1224)
line2[i] = str(s)
tems = ' '
tema = tems.join(line2)
f_new.write(tema)
input_file.close()
f_new.close()
img_path= 'F:\\txttest\\annotation'
L = []
R = []
for root,dirs,filesin os.walk(img_path):
for i in range(0,len(files),2):
L.append(files[i])
for i in range(1,len(files),2):
R.append(files[i])
for i in range(len(L)):
wtxt(R[i],L[i])
copy rename files
import shutil
import os
#img_path= 'F:\\txttest\\annotation'
img_path1= 'F:\\txttest\\2448annotation'
des_path = 'F:\\txttest\\2448data'
L=[]
# '''rename'''
# for root,dirs,files inos.walk(img_path1):
# for file in files:
# os.rename(os.path.join(root,file),os.path.join(root,file.split('L')[0]+file.split('L')[1]))
# '''movefile'''
# for root,dirs,files inos.walk(img_path1):
# for i in range(0,len(files),2):
# shutil.copy(img_path+'\\'+files[i],'F:\\txttest\\2448annotation')
for root,dirs,files inos.walk(img_path1):
for i in files:
print('F:\\cpmdata\\ATL350_2448\\'+i.split('.')[0]+'.bmp')
shutil.copy('F:\\cpmdata\\ATL350_2448\\'+i.split('.')[0]+'.bmp','F:\\txttest\\2448data')