当前位置:网站首页>从txt中读取数据转成yolo格式数据
从txt中读取数据转成yolo格式数据
2022-07-23 16:56:00 【星神学Java】
import os
import cv2
def changeLable(path):
fileList = os.listdir(path)
for fileName in fileList:
# 打开标签文件
fileLabel = open(path + "/" + fileName, "r+")
# 取出文件名并拼接.jpg
imgName = fileName.split(".")[0]+".jpg"
print("所需图片{}".format(imgName))
imagePath = "E:/iron/coco/image/"+imgName
print("图片地址{}".format(imagePath))
img = cv2.imread(imagePath)
h_img, w_img = img.shape[:2]
print("图片宽:{}\t高:{}".format(w_img,h_img))
info = fileLabel.read()
kind = info.split(" ")[0]
x1 = int(info.split(" ")[1])
x2 = int(info.split(" ")[2])
y2 = int(info.split(" ")[3])
y1 = int(info.split(" ")[4])
cenX = int(x1 + (x2-x1) / 2)
cenY = int(y1 + (y2-y1) / 2)
wide = (x2 - x1)
high = (y2 - y1)
print("中心点坐标({},{})\t宽:{}\t高:{}\n".format(cenX, cenY, wide, high))
# 归一化
newKind = "0"
newcenX = cenX/w_img
newcenY = cenY/h_img
newWide = wide/w_img
newHigh = high/h_img
print("归一化后中心点坐标({},{})\t宽:{}\t高:{}\n".format(newcenX, newcenY, newWide, newHigh))
info = newKind + " " + str(newcenX) + " " + str(newcenY) + " " + str(newWide) + " " + str(newHigh)
print(info)
newLabelPath="E:/iron/coco/label"
file = open(newLabelPath + "/" + fileName, "w+")
file.write(info)
fileLabel.close()
file.close()
if __name__ == "__main__":
changeLable("E:/iron/original/label")
边栏推荐
- Great God "magic change" airpods, equipped with usb-c interface, 3D printing shell makes maintenance easier
- Know two things: how does redis realize inventory deduction and prevent oversold?
- quota的使用方法
- Google正在改进所有产品中的肤色表现 践行“图像公平”理念
- .NET Core 实现后台任务(定时任务)Longbow.Tasks 组件(三)
- 手写bind、call、apply其实很简单
- What does MySQL access port mean_ What is the port number of the database port
- Integer and = = compare
- @JPA annotation in entity
- 【ONNX】动态输入尺寸的问题(多输出/多输入)
猜你喜欢

1259. Disjoint handshake dynamic programming

Three things programmers want to do most | comics

Redis【超强超细 入门教程】

Digital security giant entrust revealed that it was attacked by blackmail software gangs in June

【2020】【论文笔记】相变材料与超表面——

Access intranet rds+mysql through SSH

Learn about spark project on nebulagraph
![[2020] [paper notes] optically controlled spectral ratio adjustable y based on two-dimensional photonic crystal——](/img/d5/b4c82b2a9b34036e182ea9f1b14618.png)
[2020] [paper notes] optically controlled spectral ratio adjustable y based on two-dimensional photonic crystal——

11.神经网络基本概念
![Redis [super superfine introductory tutorial]](/img/a6/02b3e670067292d884bab7425b4ffb.png)
Redis [super superfine introductory tutorial]
随机推荐
Design of UART interface based on FPGA
quota的使用方法
Error reporting caused by the use of responsebodyadvice interface and its solution
电子元件-电阻
?前台传参的问题待确认
多线程【全面学习 图文精讲】
Understanding and simple implementation of time2vec
[attack and defense world web] difficulty Samsung 9-point introductory question (end): Fakebook, favorite_ number
【2022】【论文笔记】太赫兹量子阱——
1、 Reptile concept and basic process
The original path is not original [if there is infringement, please contact the original blogger to delete]
Opencv (13): brief introduction to cv2.findcontours, cv:: findcontours and description of cv2.findcontours function in various versions of opencv
什么是堆栈以及堆栈的区别
Problems and methods of creating multiple projects under one solution in VS2010
398. Random number index hash table method
Learn and understand Architecture Design from business development
去中心化存储面临的挑战
Jetpack Compose之Navigation组件使用
Redis [2022 latest interview question]
FPGA实现IIC协议(一)IIC总线协议