Python 扣取yolo标签中的图像示例并保存

Python 扣取yolo标签中的图像示例并保存,第1张

Python 扣取yolo标签中的图像示例并保存
import cv2
import os

file_path = "./ktxx"
save_path = "./plate_num"
imgs_list = os.listdir(file_path)

for img_name in imgs_list:
    if img_name.endswith(".jpg"):
        image = cv2.imread(os.path.join(file_path, img_name))
        img_w, img_h = image.shape[1], image.shape[0]
        file_read = open(os.path.join(file_path, img_name[0:-4] + ".txt"), "r")
        for line in file_read.readlines():
            count = 1
            bbox = line.split(" ")
            if int(bbox[0]) == 10:  # 确定是车牌的标注
                center_x = round(float(bbox[1]) * img_w)
                center_y = round(float(bbox[2]) * img_h)
                bbox_width = round(float(bbox[3]) * img_w)
                bbox_height = round(float(bbox[4]) * img_h)
                xmin = int(center_x - bbox_width / 2)
                ymin = int(center_y - bbox_height / 2)
                xmax = int(center_x + bbox_width / 2)
                ymax = int(center_y + bbox_height / 2)
                save_image = image[ymin:ymax, xmin:xmax]
                cv2.imwrite(os.path.join(save_path, img_name[0:-4] + "_" + str(count) + ".jpg"), save_image)
    print(img_name)




欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5701182.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存