import cv2
size = 416
stride = 32
img = cv2.imread("zidane.jpg")
h,w = img.shape[:2]
r = min(size/h,size/w)
nw,nh = int(w * r-0.1), int(h * r-0.1)
pw,ph = (nw//stride+1)*stride,(nh//stride+1)*stride
pl,pt = (pw-nw)//2,(ph-nh)//2
pr,pb = pw-nw-pl,ph-nh-pt
img_rs = cv2.resize(img,(nw,nh),interpolation=cv2.INTER_LINEAR)
img_pd = cv2.copyMakeBorder(img_rs, pt, pb, pl, pr, cv2.BORDER_CONSTANT, value=(114, 114, 114))
cv2.imwrite("rect.jpg",img_pd)
Rect Traing for saving memory
最新推荐文章于 2024-07-25 21:08:02 发布