import numpy as np import cv2 import os import glob #画像に関する情報 width_trim_info = [500,1000] #横のトリム height_trim_info = [500,1000] #縦のトリム #表に関する情報 start_img_num = 50 #表のはじまりの画像番号 skip_img_num = 5 #飛ばし画像の数 table_direction = 0 #横:0, 縦:1 table_length = 5 #指定の方向の画像数 table_name = "table.png" #挿入文字の情報 text_start_num = 300 test_step_num = 5 text_font = "times new roman" test_size = 5 text_position = (50,50) text_unit = "deg." folderpath = os.getcwd() filepathes = sorted(glob.glob(folderpath + "/*.png"))[50:] img_table = [] table_ele = np.empty(0) for png_i,filepath in enumerate(filepathes): if png_i%skip_img_num == 0: img = cv2.imread(filepath) img = cv2.imread(filepath)[height_trim_info[0]:height_trim_info[1],width_trim_info[0]:width_trim_info[1]] cv2.putText(img, str(text_start_num + (test_step_num*skip_img_num*png_i)) +text_unit, text_position, cv2.FONT_HERSHEY_DUPLEX, 1.0, (0,0,0),2,cv2.LINE_AA) if png_i%(skip_img_num*table_length)==0: if not len(table_ele) == 0: img_table.append(table_ele) table_ele = img else: if table_direction == 0: table_ele = np.hstack([table_ele,img]) elif table_direction == 1: table_ele = np.vstack([table_ele,img]) else: print("Please input correct value for table direction") for table_i,table_ele in enumerate(img_table): if table_i == 0: img = table_ele else: if table_direction == 0: table_ele = np.hstack([img,table_ele]) else: table_ele = np.vstack([img,table_ele]) cv2.imwrite(folderpath +"/"+ table_name, img)