BoringBlue
文章14
标签17
分类6
通过像素点坐标裁剪图片———Python

通过像素点坐标裁剪图片———Python

例如一下坐标点:x、y
左上坐标点A:(640, 1400)
右下坐标点B:(1200,2100)

import cv2

str_file_path = '/data/pic_lib/1.jpg'
img = cv2.imread(str_file_path)
if img is None:# 判断读取文件是否为空
    print('none')
elif img.shape[0] = 2100 and img.shape[1] = 1200:# 判断图片大小是否满足裁剪位置坐标大小
    # 裁剪坐标为[y0:y1, x0:x1]
    cropped = img[1400:2100, 640:1200]
    cv2.imwrite(str_file_path, cropped)
    print('ok')
else:
    print('picture is small')
×