import cv2
img_path = 'C:/Users/WZChan/Desktop/'
img = cv2.imread(img_path + 'test_600x350.jpg')
#resize img to 300x200
img_300x200 = cv2.resize(img, (200, 300))
#cv2.resize(imgfile, (width, height))
img_half = cv2.resize(img, (0, 0), fx = 0.5, fy = 0.5, interpolation = cv2.INTER_NEAREST)
img_300x300 = cv2.copyMakeBorder(img, 50, 50, 0, 0, cv2.BORDER_CONSTANT, value=(0, 0, 0))
patch = img[20:150, -180:-50]
# NOTE: its img[y: y + h, x: x + w] and *not* img[x: x + w, y: y + h]
cv2.imwrite(img_path + 'cropped_img.jpg', patch)
cv2.imwrite(img_path + 'resized_300x200.jpg', img_300x200)
cv2.imwrite(img_path + 'resized_half.jpg', img_half)
cv2.imwrite(img_path + 'resized_300x300.jpg', img_300x300)

cropped_img.jpg

resized_300x200.jpg

resized_half.jpg

resized_300x300.jpg
网友评论