1. 程式人生 > >crop和resize操作區別

crop和resize操作區別

net tro 剪切 str ext rect 結果 code nts

crop:對圖像進行剪切

resize:對圖像進行伸縮

實踐代碼

import cv2
bb2d = [30, 30, 72 ,42]
image = cv2.imread(‘car.png‘)
pt1 = (int(bb2d[0]), int(bb2d[1]))
pt2 = (int(bb2d[0]) + int(bb2d[2]), int(bb2d[1]) + int(bb2d[3]))
cv2.rectangle(image, pt1, pt2, (0,0,255))
cv2.imshow(‘original‘,image)
image = cv2.imread(‘car.png‘)
image_cropped = image[int(bb2d[1]):int(bb2d[1]) + int(bb2d[3]),
                      int(bb2d[0]):int(bb2d[0]) + int(bb2d[2])]
cv2.imshow(‘cropped‘,image_cropped)
image_resized = cv2.resize(image_cropped,(224,224))
cv2.imshow(‘resized‘,image_resized)
cv2.waitKey(0)

運行結果

技術分享圖片

crop和resize操作區別