当前位置:网站首页>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
边栏推荐
- 多商户商城系统功能拆解18讲-平台端商家售后
- c语言小游戏扫雷
- 单片机开发之基本并行I/O口
- jenkins use and maintenance
- C陷阱与缺陷 第5章 库函数 5.2更新顺序文件
- Getting Started with Sentinel
- rk-boot framework combat (1)
- 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
- codeforces 线段树题单
- CesiumJS ^ source read [0] 2022 - article directory and source engineering structure
猜你喜欢

Wincc报表教程(SQL数据库的建立,wincc在数据库中保存和查询数据,调用Excel模板把数据保存到指定的位置和打印功能)

Decision tree principle and code implementation

Raspberry pie wiringPi 2.6 installed on solving gpio readall command mistakes

EA&UML日拱一卒-多任务编程超入门-(7)关于mutex,你必须知道的

devops学习(七) sonarqube 代码质检工具

指令集数据产品如何设计和实现报表协同系统——基于指令集物联网操作系统的工业协同制造项目开发实践

微信小程序获取手机号getPhoneNumber接口报错41001

【openlayers】Map【1】

Dropout回顾

微信小程序获取手机号getPhoneNumber接口报错44002
随机推荐
Huawei 14 Days - (3) Kernel Development
DFS对树的遍历及一些优化
logback过期日志文件自动删除
vim相关介绍(三)
Gao Shu Xia|Triple Integral Exercises|Uncle Gao Shu|Handwritten Notes
Windows 安装 MySQL 5.7详细步骤
rk-boot framework combat (1)
go语言序列化和反序列化及序列化后的json为空和json的key值大写如何改为小写问题
C陷阱与缺陷 第4章 链接 4.3 命名冲突与static修饰符
Raspberry pie wiringPi 2.6 installed on solving gpio readall command mistakes
卧槽,2行代码,让接口性能提升10倍
devops学习(四) Jenkins CI 持续集成
桌面软件开发框架大赏
标签分发协议(LDP)
jenkins use and maintenance
全国双非院校考研信息汇总整理 Part.4
Android 11 : 隐私和安全
Super RVRT
Elephant Swap: Provide arbitrage space in the crypto market with ePLATO
18 Lectures on Disassembly of Multi-merchant Mall System Functions