当前位置:网站首页>The file marked by labelme is converted to yolov5 format
The file marked by labelme is converted to yolov5 format
2022-07-03 03:09:00 【AphilGuo】
import json
import os
def convert(img_size, box):
x1 = box[0]
y1 = box[1]
x2 = box[2]
y2 = box[3]
center_x = (x1 + x2) * 0.5 / img_size[0]
center_y = (y1 + y2) * 0.5 / img_size[1]
w = abs((x2 - x1)) * 1.0 / img_size[0]
h = abs((y2 - y1)) * 1.0 / img_size[1]
return (center_x, center_y, w, h)
def convert1(img_size, box):
x1 = box[0]
y1 = box[1]
center_x = x1 / img_size[0]
center_y = y1 / img_size[1]
return (center_x, center_y)
def decode_json(jsonfloder_path, json_name):
txt_name = '/yolov5_labels/' + json_name[0:-5] + '.txt'
# txt Save the location
txt_file = open(txt_name, 'w') # te files
json_path = os.path.join(json_folder_path, json_name)
data = json.load(open(json_path, 'r'))
img_w = data['imageWidth']
img_h = data['imageHeight']
for i in data['shapes']:
if (i['shape_type'] == 'rectangle'): # Rectangular box dimensions only
x1 = float(i['points'][0][0])
y1 = float(i['points'][0][1])
x2 = float(i['points'][1][0])
y2 = float(i['points'][1][1])
if x1 < 0 or x2 < 0 or y1 < 0 or y2 < 0:
continue
else:
bb = (x1, y1, x2, y2)
bbox = convert((img_w, img_h), bb)
if i['label'] == "jc_re":
txt_file.write("0 " + " ".join([str(a) for a in bbox])+" ")
# elif i['label'] == "jc_point":
# txt_file.write("1 " + " ".join([str(a) for a in bbox]) + '\n')
# elif i['label'] == "Computer":
# txt_file.write("2 " + " ".join([str(a) for a in bbox]) + '\n')
# else:
# txt_file.write("3 " + " ".join([str(a) for a in bbox]) + '\n')
elif (i['shape_type'] == 'point'): # Applicable point annotation
x1 = float(i['points'][0][0])
y1 = float(i['points'][0][1])
if x1 < 0 or y1 < 0:
continue
else:
bb = (x1, y1)
bbox = convert1((img_w, img_h), bb)
if i['label'] == "jc_point":
# txt_file.write(" ".join([str(a) for a in bbox]) + "\n")
txt_file.write(" ".join([str(a) for a in bbox])+" ")
if __name__ == "__main__":
json_folder_path = 'json_path' # json Folder path
json_names = os.listdir(json_folder_path) # file name
for json_name in json_names: # output all files
if json_name[-5:] == '.json': # just work for json files
decode_json(json_folder_path, json_name)
边栏推荐
- Use optimization | points that can be optimized in recyclerview
- js根据树结构查找某个节点的下面的所有父节点或者子节点
- Installation and use of memory leak tool VLD
- VS 2019配置tensorRT
- What happens between entering the URL and displaying the page?
- Andwhere multiple or query ORM conditions in yii2
- Three. JS local environment setup
- QT based tensorrt accelerated yolov5
- What does it mean when lambda is not entered?
- Distributed transaction
猜你喜欢

函数栈帧的创建与销毁
![MySQL practice 45 [global lock and table lock]](/img/23/fd58c185ae49ed6c04f1a696f10ff4.png)
MySQL practice 45 [global lock and table lock]

Creation and destruction of function stack frame

I2C 子系统(一):I2C spec

Kubernetes family container housekeeper pod online Q & A?
![MySQL practice 45 [SQL query and update execution process]](/img/cd/3a635f0c3bb4ac3c8241cb77285cc8.png)
MySQL practice 45 [SQL query and update execution process]

内存泄漏工具VLD安装及使用
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/c7/6b5ab4ff7379bfccff7cdbb358ff8f.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]

The process of connecting MySQL with docker

Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
随机推荐
Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
MySQL Real combat 45 [SQL query and Update Execution Process]
[C语言]给账号密码进行MD5加密
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
C # general interface call
Cron表达式介绍
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling
I2C 子系统(二):I3C spec
Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
I2C subsystem (II): I3C spec
I2C 子系统(一):I2C spec
Yiwen takes you to know ZigBee
JS finds all the parent nodes or child nodes under a node according to the tree structure
当lambda没有输入时,是何含义?
docker安装mysql
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
销毁Session和清空指定的属性
C语言初阶-指针详解-庖丁解牛篇
Sous - système I2C (IV): débogage I2C
VS code配置虚拟环境