赞
踩
图片分块/裁剪代码
import cv2 import os # Returns a list of all folders with participant numbers # img_path = glob.glob("F:/test/*jpg") # for path in img_path: # img = cv2.imread(path) # cv2.imshow('img',img) # cv2.waitKey(1000) # 循环处理列表中的所有图片 path = os.path.expanduser("F:\split\\test\\bad/") for f in os.listdir(path): # print(f.strip()[0:-4]) path = "F:\split\\test\\bad/" + f.strip() print(path) img = cv2.imread(path) # cv2.imshow('img', img) # shap[0] height,shape[1] width hei = img.shape[0] wid = img.shape[1] # 裁剪后图片的区域个数 num = 2 for i in range(0, num): print(i) # 调整裁剪区域像素位置 hei_0 = 0 hei_1 = int(hei) wid_0 = int(i * wid / num) wid_1 = int((i + 1) * wid / num)-40 # 图片分块裁剪操作 roiImg = img[hei_0:hei_1, wid_0:wid_1] # cv2.imshow("[ROIImg]", roiImg) # 图片保存路径 path = "F:\out\\test\\bad/" + f.strip()[0:-4] + "_" + str(i) + ".jpg" cv2.imwrite(path, roiImg)
主要采用了python的切片操作。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。