当前位置:网站首页>YOLO数据格式说明与转换
YOLO数据格式说明与转换
2022-07-29 23:46:00 【子燕若水】
转载:YOLO数据格式说明与转换_lokvke的博客-CSDN博客_yolo数据集格式
YOLO数据格式说明与转换
1. YOLO数据格式说明
2. 代码
1. YOLO数据格式说明
yolo标注格式保存在.txt文件中,一共5个数据,用空格隔开,举例说明如下图所示:
假设图像的高和宽分别为h, w,bbox的左上角坐标为(x1, y2),右下角坐标为(x2, y2),则可求得bbox中心坐标(x_c, y_c)为:
x_c = x1 + (x2 - x1)/2 = (x1 + x2)/2
y_c = y1 + (y2 - y1)/2 = (y1 + y2)/2
假设yolo的5个数据分别为:label, x_, y_, w_, h_,则有对应关系:
x_ = (x1 + x2) / 2w
y_ = (y1 + y2) / 2h
w_ = (x2 - x1) / w
h_ = (y2 - y1) / h
反过来,则有:
x1 = w * x_ - 0.5 * w * w_
x2 = w * x_ + 0.5 * w * w_
y1 = h * y_ - 0.5 * h * h_
y2 = h * y_ + 0.5* h * h_
2. 代码
import cv2
# 假设图像为test.jpg
img = cv2.imread('test.jpg')
h, w, _ = img.shape
# yolo标注数据文件名为786_rgb_0616.txt
with open('786_rgb_0616.txt', 'r') as f:
temp = f.read()
temp = temp.split()
# ['1', '0.43906', '0.52083', '0.34687', '0.15']
# 根据第1部分公式进行转换
x_, y_, w_, h_ = eval(temp[1]), eval(temp[2]), eval(temp[3]), eval(temp[4])
x1 = w * x_ - 0.5 * w * w_
x2 = w * x_ + 0.5 * w * w_
y1 = h * y_ - 0.5 * h * h_
y2 = h * y_ + 0.5* h * h_
# 画图验证,注意画图坐标要转换成int格式
cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (255, 0, 0))
cv2.imshow('windows', img)
cv2.waitKey(0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
返回结果如下图所示,可以看到正确框选出了目标,验证正确。
结束。
————————————————
版权声明:本文为CSDN博主「lokvke」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43508499/article/details/118600392
边栏推荐
猜你喜欢

Unity Addressables

Getting Started with Sentinel

接口测试的概念、目的、流程、测试方法有哪些?
![CesiumJS ^ source read [0] 2022 - article directory and source engineering structure](/img/6a/0a446eb00fb73275897cbfb336e0b0.png)
CesiumJS ^ source read [0] 2022 - article directory and source engineering structure

第一范式、第二范式、第三范式

关于MySQL索引的一些个人理解(部分参考MySQL45讲)

EA&UML日拱一卒-多任务编程超入门-(8)多任务安全的数据类

NumPy(二)

EA & UML Sun Arch - State Diagram :: Redraw Button State Diagram

How to design and implement report collaboration system for instruction set data products——Development practice of industrial collaborative manufacturing project based on instruction set IoT operating
随机推荐
C陷阱与缺陷 第4章 链接 4.1 什么是链接器
论文精读——YOLOv3: An Incremental Improvement
Design for failure 12 common design ideas
管理区解耦架构见过吗?能帮客户解决大难题的
devops学习(三) K8环境部署jenkins
Some personal understandings about MySQL indexes (partially refer to MySQL45 lectures)
单片机开发之拓展并行I/O口
【云原生Kubernetes】二进制搭建Kubernetes集群(中)——部署node节点
[Cloud native Kubernetes] Build a Kubernetes cluster in binary (middle) - deploy node nodes
容器化数据库必经之道
卧槽,2行代码,让接口性能提升10倍
Codeforces Round #805 (Div. 3)总结
Super RVRT
jenkins搭建部署详细步骤
[2023 School Recruitment Questions] Summary of Common Interview Questions (7. Common Bus Protocols) (Continuously updated with subsequent interviews....)
idea设置自动去除未引用(不再引用)的引用
y81. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Monitoring Extension (12)
C陷阱与缺陷 第4章 链接 4.4 形参、实参与返回值
MySQL六脉神剑,SQL通关大总结
Huawei 14 Days - (3) Kernel Development