旋转边界框:XML标注文件可视化

python代码:

# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import os, cv2
import numpy as np

xml_file = 'C:/Users/liuqian/Desktop/ceshi/annotation/G0000_0000_0450.xml'
tree = ET.parse(xml_file)
root = tree.getroot()
imgfile = 'C:/Users/liuqian/Desktop/ceshi/images/G0000_0000_0450.png'
im = cv2.imread(imgfile)
for object in root.findall('object'):
    object_name = object.find('name').text
    #bndbox = object.find('bndbox').text
    X0 = float(object.find('bndbox').find('x0').text)
    Y0 = float(object.find('bndbox').find('y0').text)
    X1 = float(object.find('bndbox').find('x1').text)
    Y1 = float(object.find('bndbox').find('y1').text)
    X2 = float(object.find('bndbox').find('x2').text)
    Y2 = float(object.find('bndbox').find('y2').text)
    X3 = float(object.find('bndbox').find('x3').text)
    Y3 = float(object.find('bndbox').find('y3').text)
    X0 = int(X0)
    Y0 = int(Y0)
    X1 = int(X1)
    Y1 = int(Y1)
    X2 = int(X2)
    Y2 = int(Y2)
    X3 = int(X3)
    Y3 = int(Y3)
    #print(X0)
    #box = cv2.boxPoints(bndbox)
    newBox = [[X0, Y0], [X1, Y1], [X2, Y2], [X3, Y3]]
    color = (4, 250, 7)

    #img = np.zeros([120, 120], dtype=np.uint8)
    point = np.array(newBox).astype(int)
    box = np.int32(point)

    #cv2.line(img, tuple(point[0]), tuple(point[1]), color, 2)
    #cv2.line(img, tuple(point[1]), tuple(point[2]), color, 2)
    #cv2.line(img, tuple(point[2]), tuple(point[3]), color, 2)
    #v2.line(img, tuple(point[3]), tuple(point[0]), color, 2)
    #cv2.rectangle(im, (int(X0), int(Y0)), (int(X1), int(Y1)),(int(X2), int(Y2)),(int(X3), int(Y3)), color, 2)

    #image = np.expand_dims(img, axis=2)
    #image = np.concatenate((image, image, image), axis=-1)

    cv2.drawContours(im, [box], 0, (0, 0, 255), 3)

    font = cv2.FONT_HERSHEY_SIMPLEX
    cv2.putText(im, object_name, (X0, Y0 - 7), font, 0.5, (6, 230, 230), 2)
    cv2.imshow('01', im)
cv2.imwrite('C:/Users/liuqian/Desktop/ceshi/02.png', im)

可视化之后:
在这里插入图片描述
参考博客:
https://www.bbsmax.com/A/WpdKygN1JV/
https://blog.csdn.net/gusui7202/article/details/83410188?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-8.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-8.channel_param

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值