import os
import cv2
from PIL import Image
#image和label原路径和缩放后的保存路径
label_path="/home/yangguide/Downloads/training/label_2"
new_label_path="/home/yangguide/Downloads/training/label"
image_path="/home/yangguide/Downloads/training/image_2"
new_image_path="/home/yangguide/Downloads/training/image"
for root,dirs,files in os.walk(label_path):
for name in files:
if name.endswith(".txt"):
filename=root+"/"+name #原label里.txt文件全路径名
filename2=new_label_path+"/"+name #缩放后的label里.txt文件全路径名
file_name = name.split('.')[0]
file_path=image_path+"/"+file_name+".jpg"
img = Image.open(file_path)
weight = img.size[0]
height = img.size[1]
target_size=[320,480] #打算缩放的尺寸
img = cv2.imread(file_path)
old_size= img.shape[0:2]
ratio = min(float(target_size[i])/(old_size[i]) for i
Python实现keep_ratio批量缩放图片和label尺寸
最新推荐文章于 2024-12-12 10:36:20 发布
本文介绍了一种图像缩放及对应标注文件调整的方法,通过Python实现,详细讲解了如何保持目标检测框的位置准确,适用于计算机视觉项目的数据预处理。

最低0.47元/天 解锁文章
9163

被折叠的 条评论
为什么被折叠?



