plt 调整子图间距 和裁剪

ai#  子图间距
plt.tight_layout(rect=[0, 0.2, 1, 0.9]) # 自适应图是否重叠,参数是坐标,是子图的覆盖区域,从左0到右1,从下0到上0.9 plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.1, hspace=0.1)

 

cv2裁剪

import cv2
import os
import matplotlib.pyplot as plt
import sys

for each_mask_dir in os.listdir('./'):
    if '.py' in each_mask_dir:
        continue
    if '(' not in each_mask_dir:
        continue
    # if '100_10(0.2)_20(0.2)'  in each_mask_dir:
    #     continue
    dir_path = './{}'.format(each_mask_dir)
    for each_img_name in os.listdir(dir_path):
        if '.jpg' not in each_img_name:
            continue
        print('each_img_name:',each_img_name)
        step_num = each_img_name.split('.')[0]
        print('step_num:',step_num)
        img_path = '{}/{}'.format(dir_path,each_img_name)
        # if img_path == './100_10(0.2)_20(0.2)/step0_0.jpg':
        #     print('跳过',img_path)
        #     continue
        print('img_path:',img_path)
        each_img = cv2.imread(img_path)

        # plt.imshow(each_img)
        # plt.axis('off')
        # plt.show()

        margin = 1
        img1 = each_img[112 :319,13-margin:626+margin]
        save_dir = img_path.replace('./','./Clip_dir/').split('/step')[0]
        if not os.path.exists(save_dir):
            os.mkdir(save_dir)
        cv2.imwrite(img_path.replace('./','./Clip_dir/'), img1)
        #
        # clip_dir = './Clip_dir'
        # if not os.path.exists(clip_dir):
        #     os.mkdir(clip_dir)
        # save_path1 = '{}/{}_(1).jpg'.format(clip_dir,step_num)

        # print('save_path2:',save_path2)
        # cv2.imwrite(save_path1,img1)

        # sys.exit(2)

        print()

 

posted @ 2023-01-24 23:43  山…隹  阅读(262)  评论(0编辑  收藏  举报