import os
import cv2
import numpy as np
import json
def crop_img(path):
"""
:param path: 文件路径
:return: 无
将图像裁成6份,上下二等分,左右三等分
"""
files = os.listdir(path)
for i, file in enumerate(files):
print("第 %d 共 %d" % (i + 1, len(files)))
filepath = os.path.join(path,file)
img = cv2.imdecode(np.fromfile(filepath, dtype=np.uint8), -1)
h,w = img.shape
for j in range(6):
imgj = img[int((j//3) * (h/2)):int((j//3 + 1) * (h/2)),int((j%3) * (w/3)):int((j%3 + 1) * (w/3))]
cv2.imencode('.jpg', imgj)[1].tofile(os.path.join(path,'%03d_%d.jpg'%(i,j)))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21