当前位置:网站首页>(4) Rotating object detection data roLabelImg to DOTA format
(4) Rotating object detection data roLabelImg to DOTA format
2022-08-05 06:57:00 【Hengyoucheng】
欢迎访问个人网络日志知行空间
文章目录
roLabelImg 工具仓库地址:https://github.com/cgvict/roLabelImg
1.Enters a mode where you can draw a rotation detection frame

2.Annotation file style
roLabelImgWhen marking the rotation detection frame, first draw a regular rectangular frame,Then it is achieved by rotating a certain angle clockwise and counterclockwise around the center point of the rectangle.The definition of the rotation detection frame in the annotation file is to use(cx, cy, width, height, angle)的格式定义的,如下:
<robndbox>
<cx>1178.4388</cx>
<cy>1004.6478</cy>
<w>319.635</w>
<h>273.2016</h>
<angle>0.46</angle>
</robndbox>
(cx, cy)is the pixel coordinate of the center point of the rotation box,w的定义是在roLabelImgIn the image when drawing the initial rectanglexside length in the direction, 另一条边是h,After drawing the initial rectangle,Regardless of subsequent rotation,w和hThe pointed edge will not change.angleThe definition of the corner is the rotation of the rectangular detection framew边和XThe angle formed by the positive direction of the axis clockwise,其大小为[0,pi)
Initial rectangle detection frame:

Detect the frame after adjusting the pose:

3.DOTA数据格式
DOTAIt is an open source rotating object detection dataset of Wuhan University,See its homepagehttps://captain-whu.github.io/DOTA/dataset.html.DOTA标注文件的格式为:
x1, y1, x2, y2, x3, y3, x4, y4, category, difficult
(x1, y1, x2, y2, x3, y3, x4, y4)are the coordinates of the four vertices of the rotating object detection frame, respectively,categoryis the category of the detection frame object object
4.roLabelImgAnnotation file transferDOTA格式
Most of the open source algorithms for rotating object detection are supported by the data processing partDOTA格式,Such as Shangtang open sourcemmrotate,In order to verify the effectiveness of the algorithm on your own data set faster,The most convenient algorithm is to roLabelImg标注的xmlThe file is converted to the above label format,roLabelImgAnnotation file transferDOTAThere are four cases.
- 1) θ ∈ ( π / 2 , π ) \theta \in (\pi/2, \pi) θ∈(π/2,π),and the center pointCfall on point1右侧
- 2) θ ∈ ( π / 2 , π ) \theta \in (\pi/2, \pi) θ∈(π/2,π),and the center pointCfall on point1左侧
- 3) θ ∈ [ 0 , π / 2 ] \theta \in [0, \pi/2] θ∈[0,π/2],and the center pointCfall on point1左侧
- 4) θ ∈ [ 0 , π / 2 ] \theta \in [0, \pi/2] θ∈[0,π/2],and the center pointCfall on point1右侧

以 θ ∈ ( π / 2 , π ) \theta \in (\pi/2, \pi) θ∈(π/2,π),and the center pointCfall on point1Example on the right,

A(x1, y1),B(x3, y3),D(x2, y2),E(x4, y4)The coordinates of the point can be obtained from the relationship between the above triangles:
β = ∠ C A V 2 = a r c t a n h w + π − θ \beta = \angle CAV_2 = arctan\frac{h}{w}+ \pi - \theta β=∠CAV2=arctanwh+π−θ
d = w 6 2 + h 2 2 d = \frac{\sqrt{w^62+h^2}}{2} d=2w62+h2
x 1 = c x − d c o s β y 1 = c y + d s i n β x 2 = c x + d c o s β y 2 = c y − d s i n β x 3 = x 1 − h c o s ( θ − π 2 ) y 4 = y 1 − h s i n ( θ − π 2 ) x 4 = x 2 + h c o s ( θ − π 2 ) y 4 = y 2 + h s i n ( θ − π 2 ) x1 = cx - d cos\beta \\ y1 = cy + d sin\beta \\ x2 = cx + d cos\beta \\ y2 = cy - d sin\beta \\ x3 = x1 - hcos(\theta - \frac{\pi}{2}) \\ y4 = y1 - hsin(\theta - \frac{\pi}{2}) \\ x4 = x2 + hcos(\theta - \frac{\pi}{2}) \\ y4 = y2 + hsin(\theta - \frac{\pi}{2}) x1=cx−dcosβy1=cy+dsinβx2=cx+dcosβy2=cy−dsinβx3=x1−hcos(θ−2π)y4=y1−hsin(θ−2π)x4=x2+hcos(θ−2π)y4=y2+hsin(θ−2π)
The other three cases can also be found.
转换代码见:
def convert_rolabelimg2dota(xml_path:str) -> None:
""" Args: - `xml_path` (str) : path to roLabelImg label file, like /xx/xx.xml Returns: - `box_points` (list): shape (N, 8 + 1), N is the number of objects, 8 + 1 is \ `(x1, y1, x2, y2, x3, y3, x4, y4, class_name)` """
with open(xml_path) as f:
tree = ET.parse(f)
root = tree.getroot()
size = root.find('size')
width = int(size.find('width').text)
height = int(size.find('height').text)
objects = root.iter('object')
boxes = [] # list of tuple(cz, cy, w, h, angle), angle is in [0-pi)
for obj in objects:
if obj.find('type').text == 'robndbox':
rbox_node = obj.find('robndbox')
cat = obj.find('name').text
rbox = dict()
for key in ['cx', 'cy', 'w', 'h', 'angle']:
rbox[key] = float(rbox_node.find(key).text)
boxes.append(list((*rbox.values(), cat)))
print(f"bboxes: {
boxes}")
box_points = [] # list of box defined with four vertices
for box in boxes:
cx, cy, w, h, ag, cat = box
alpha_w = math.atan(w / h)
alpha_h = math.atan(h / w)
d = math.sqrt(w**2 + h**2) / 2
if ag > math.pi / 2:
beta = ag - math.pi / 2 + alpha_w
if beta <= math.pi / 2:
x1, y1 = cx + d * math.cos(beta), cy + d * math.sin(beta)
x2, y2 = cx - d * math.cos(beta), cy - d * math.sin(beta)
elif beta > math.pi / 2:
beta = math.pi - beta
x1, y1 = cx - d * math.cos(beta), cy + d * math.sin(beta)
x2, y2 = cx + d * math.cos(beta), cy - d * math.sin(beta)
x3, y3 = x1 - h * math.cos(ag - math.pi / 2), y1 - h * math.sin(ag - math.pi / 2)
x4, y4 = x2 + h * math.cos(ag - math.pi / 2), y2 + h * math.sin(ag - math.pi / 2)
elif ag <= math.pi / 2:
beta = ag + alpha_h
if beta <= math.pi / 2:
x1, y1 = cx + d * math.cos(beta), cy + d * math.sin(beta)
x2, y2 = cx - d * math.cos(beta), cy - d * math.sin(beta)
elif beta > math.pi / 2:
beta = math.pi - beta
x1, y1 = cx - d * math.cos(beta), cy + d * math.sin(beta)
x2, y2 = cx + d * math.cos(beta), cy - d * math.sin(beta)
x3, y3 = x1 - w * math.cos(ag), y1 - w * math.sin(ag)
x4, y4 = x2 + w * math.cos(ag), y2 + w * math.sin(ag)
points = np.array([x1, y1, x3, y3, x2, y2, x4, y4], dtype=np.int32)
points[0::2] = np.clip(points[0::2], 0, width)
points[1::2] = np.clip(points[1::2], 0, height)
box_points.append([*points, cat])
return box_points
完整代码见gitee仓库object_detection_task
参考资料
边栏推荐
- 矩阵的构造
- 邮件管理 过滤邮件
- UDP group (multi)cast
- typescript60-泛型工具类型(readonly)
- VS Code私有服务器部署(私有化)
- Source code analysis of Nacos configuration service (full)
- Hong Kong International Jewellery Show and Hong Kong International Diamond, Gem and Pearl Show kick off
- Day9 of Hegong Daqiong team vision team training - camera calibration
- 【C语言】结构体变量数据通过 void* 传入到函数中
- Nacos cluster construction
猜你喜欢

2022杭电多校六 1007-Shinobu loves trip(同余方程)

typescript61-泛型工具类型(pick)

Jenkins详细配置

Quick Start to Drools Rule Engine (1)

scikit-image image processing notes

Tips for formatting code indentation
![In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]](/img/b5/03f55bb9058c08a48eae368233376c.png)
In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]

不太会讲爱,其实已经偷偷幸福很久啦----我们的故事

DNSlog外带数据注入

如何将.asd恢复为Word文档
随机推荐
(四)旋转物体检测数据roLabelImg转DOTA格式
LaTeX使用frame制作PPT图片没有标号
HelloWorld
香港国际珠宝展及香港国际钻石、宝石及珍珠展揭幕
(2022杭电多校六)1010-Planar graph(最小生成树)
防抖函数和节流函数
ndk编译so库
typescript67-索引查询类型
邮件管理 过滤邮件
typescript60-泛型工具类型(readonly)
uniapp打包次数限制怎么办?只需两步就能解决
在小程序中关于js数字精度丢失的解决办法
技术分析模式(八)双顶和底
盒子模型中过度约束问题及其解决办法
农场游戏果园系统+牧场养殖系统+广告联盟模式流量主游戏小程序APP V1
MyCat配置文件
Jenkins详细配置
开启防火墙iptable规则后,系统网络变慢
淘宝客APP带自营商城本地生活CPS外卖优惠电影票话费更新渠道跟单生活特权V3
Pytorch distributed parallel processing