在相机标定过程中需要在众多图片中挑选固定张数的图片,此时可以使用python脚本进行筛选
import os
from shutil import copy
def abstract(source_path,to_path,interval=200):
files = os.listdir(source_path)
num_png = len(files)
n=int(num_png/interval)
for file in files:
for i in range(0,num_png,n):
if file=='%06d' % i+'.png':
source_file = os.path.join(source_path, file)
print(source_file)
to_file = os.path.join(to_path, file)
if not os.path.exists(to_path):
os.makedirs(to_path)
copy(source_file, to_file)
if __name__ == '__main__':
source_path1='/home/luoyh/Desktop/intrinsic/cam_back'
source_path2='/home/luoyh/Desktop/intrinsic/cam_front_center'
source_path3='/home/luoyh/Desktop/intrinsic/cam_front_right'
source_path4='/home/luoyh/Desktop/intrinsic/cam_left_back'
source_path5='/home/luoyh/Desktop/intrinsic/cam_right_front'
to_path1 = "./cam_back"
to_path2 = "./cam_front_center"
to_path3 = "./cam_front_right"
to_path4 = "./cam_left_back"
to_path5 = "./cam_right_front"
abstract(source_path1,to_path1)
abstract(source_path2,to_path2,150)
abstract(source_path3,to_path3)
abstract(source_path4,to_path4)
abstract(source_path5,to_path5)