chatgpt,输出图片正方形剪裁操作,图片原坐标剪裁补黑边不变形resize

	        # 左右扩5,上下扩5# image = image.crop((max(0, box[0] - 8), max(0, box[1] - 8), min(w, box[2] + 8), min(h, box[3] + 8)))image = image.convert("RGB")bgr_image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)img = bgr_image  #上下左右扩增8个像素后的图片h, w, _ = img.shape# 补黑边border_len = max(h, w)## 1 已经剪裁过的图片以最长边resize ,补充黑边变成正方形,不变形操作border_img = cv2.copyMakeBorder(img,top=(border_len - h) // 2,bottom=(border_len - h) // 2 + (border_len - h) % 2,left=(border_len - w) // 2,right=(border_len - w) // 2 + (border_len - w) % 2,borderType=cv2.BORDER_CONSTANT,value=(0, 0, 0))# 扩充为正方形square_len = 224            resized_img = cv2.resize(border_img, (square_len, square_len), interpolation=cv2.INTER_CUBIC)# 保存图片cv2.imwrite(save_img_name, resized_img)                                            
在这里插入代码片

本文链接:https://my.lmcjl.com/post/10886.html

展开阅读全文

4 评论

留下您的评论.