VOC数据集复现标注信息

提示:代码仅供参考


前言

目标检测
用于VOC数据集复现标注信息,可能不太准确,可以更改参数


一、VOC数据集

博主一般使用MakeSense标注图片,这段代码可以用来复现标注好的信息,也可以用于其他已存的开源数据集

二、使用步骤

1.引入库

代码如下(示例):

import os
import xml.etree.ElementTree as ET
import cv2 as cv

2.读入数据

代码如下(示例):

def convert_annotation(img):
    in_file = open('D:/pycharm/pic_anno_enh/1_000001.xml', encoding='utf-8')
    tree=ET.parse(in_file)
    root = tree.getroot()
    loac=[]
    for obj in root.iter('object'):

        #确定坐标
        xmlbox = obj.find('bndbox')
        b = (int(float(xmlbox.find('xmin').text)), int(float(xmlbox.find('ymin').text)), int(float(xmlbox.find('xmax').text)), int(float(xmlbox.find('ymax').text)))
        loac.append(b)
    return loac

if __name__=="__main__":
    img_=r'D:\pycharm\pic_jpeg_enh\1_000001.jpg'
    loaction=convert_annotation(img_)
    #print(loaction)
    print(img_)
    img = cv.imread(img_)
    for b in loaction:
        x1=b[0]
        y1=b[1]
        x2=b[2]
        y2=b[3]
        cv.rectangle(img,(x1,y1),(x2,y2),color=(0,0,255),thickness=9)
    print(img.shape)
    # print(int(img.shape[1]/10),int(img.shape[0]/10))
    if img.shape[0]>3000:
        img=cv.resize(img,(int(img.shape[1]/5),int(img.shape[0]/5)),interpolation=cv.INTER_AREA)
    print(img.shape)

    cv.imshow(os.path.basename(img_), img)
    cv.waitKey(0)  # 参数为0,代表任意键关闭图片;若为数字,则为毫秒延时
    cv.destroyAllWindows()

总结

以上就是今天要讲的内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值