栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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)




转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/701068.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号