用labelme自己标注的数据转tusimple格式数据集
说明
通过类别labelme标注的数据转为车道线的数据,labelme标注的格式为“linestrip",如下图所示:
这里自己用的图片尺寸为1280x720大小。如果是自定图片数据大小,请修改h_samples 参数
环境
- ubuntu18.04
- opencv4.5.0
- json
- python3.7
- numpy
安装opencv_python、numpy 等第三方依赖包
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simplepip install opencv_python -i https://pypi.tuna.tsinghua.edu.cn/simple
代码
新建文件lable_to_tusimpledataset.py,并添加如下代码:
// --run--
"""
Time: 2022.8.10
Fuction: labelme标注的数据 转 tusimple格式数据集 ,车道线数据集
Author:yu_fangtusimple格式数据集:标注json 文件中每一行包括三个字段 :raw_file : 每一个数据段的第20帧图像的的 path 路径lanes 和 h_samples 是数据具体的标注内容,为了压缩,h_sample 是纵坐标(等分确定),lanes 是每个车道的横坐标,是个二维数组。-2 表示这个点是无效的点。标注的过程应该是,将图片的下半部分如70%*height 等分成N份。然后取车道线(如论虚实)与该标注线交叉的点"""
import cv2
import os
import glob
import json
import numpy as np
import shutilprint("[LOG] start ...")
# lebalme标注的文件路径,如:01.jpg,01.json ...
labelme_dir = "/media/Linux/work/clrnet/Railway_tusimple20220808"
#labelme_dir = "/media/Linux/work/clrnet/Railway_tusimple20220808_test"# 存放tusimple数据集的根目录路径
result_dir = "/media/Linux/work/clrnet/tusimple_self_202208101107"
#result_dir = "/media/Linux/work/clrnet/tusimple_self_202208101107_test"# 保存的json文件名,带后缀,命名类似tusimple数据集里的json文件名
json_file_name = "label_data_0809.json"
# 同时在clips文件夹里子文件命名为0810
clips_sub_name = os.path.splitext(json_file_name)[0].split("_")[-1]
clips_sub = os.path.join("clips",clips_sub_name)
# 判断结果文件路径文件夹是否存在
if not os.path.exists(result_dir):os.makedirs(result_dir)
# 创建clips文件夹,及子文件夹
clips_sub_dir = os.path.join(result_dir,clips_sub)
if not os.path.exists(clips_sub_dir):os.makedirs(clips_sub_dir)# 定义h_samples 纵坐标等分区间,根据自己的数据图像调整
h_samples = list(range(160, 720, 10)) # range(start,end,step)
print("h_sample:",h_samples)#批量获取图片
labelme_img = glob.glob(labelme_dir+'/*.jpg') # 根据自己的图片格式更改,这里是*.jpg格式
print("labelme_json:",labelme_img)# 写入json文件
json_file_path = os.path.join(result_dir,json_file_name)
with open(json_file_path, 'w') as wr:# 遍历img,jsonfor idx, img_path in enumerate(labelme_img):print(idx,img_path)img_name_file = os.path.basename(img_path)# 获取img名字,去掉后缀img_name = os.path.splitext(img_name_file)[0]# 获取对应的json文件路径json_path = os.path.splitext(img_path)[0] + ".json"# 初始化一个list存放单张图的所有车道线lanes = []dict_img_per = {}if os.path.isfile(json_path):img = cv2.imread(img_path,-1)img_w = img.shape[1]img_h = img.shape[0]#binary_image = np.zeros([img_h, img_w], np.uint8)# 绘制横线h_samplesbinary_image_h = np.zeros([img_h, img_w], np.uint8)for h in h_samples:cv2.line(binary_image_h,(0,h),(img_w-1,h),(255),thickness=1)# cv2.imshow("2",binary_image_h)# 加载json文件with open(json_path, 'r') as json_obj:data = json.load(json_obj)for shapes in data['shapes']:binary_image = np.zeros([img_h, img_w], np.uint8)# 单条lanesingle_lane = []label = shapes['label']# print("label:",label)points = shapes['points'] # 标注的linestrippoints = np.array(points, dtype=int)cv2.polylines(binary_image,[points],False,(255),thickness=1) # 绘制车道线img_and = cv2.bitwise_and(binary_image,binary_image_h)# 获取宽高交点for h in h_samples:start = Falsetemp_w = []for w in range(img_w):if img_and[h, w] >= 1:start = Truetemp_w.append(w)if start:half = len(temp_w) // 2median = (temp_w[half] + temp_w[~half])/2median = int(median)# print("half:",half,median)single_lane.append(median)else:single_lane.append(-2)# print("single_lane:",single_lane)# cv2.imshow("1",img_and)# cv2.waitKey(0)lanes.append(single_lane)json_obj.close()print("lanes:",lanes)raw_file = os.path.join(clips_sub,img_name_file)shutil.copy(img_path, clips_sub_dir)dict_img_per = {"lanes":lanes,"h_samples":h_samples,"raw_file":raw_file}# print("dict_img_per:",dict_img_per)# 将dict写入名称为wr的文件中# json.dump(dict_img_per, wr, indent=4) # indent控制间隔,缩进json.dump(dict_img_per, wr)wr.write('\n')else:continuewr.close()
结果
运行lable_to_tusimpledataset.py,批量生成后的结果如下图所示:
用labelme自己标注的数据转tusimple格式数据集相关推荐
- 制作自己的 tusimple 格式数据集
tusimple 格式数据集制作与标注小结 最近在看 LaneNet ,然后参考网上的博客记录一下自己制作个人 tusimple 格式数据集的过程. 1.前期准备 工具: labelme 3.6.12 ...
- 在Win10系统中使用labelme制作图像分割标签数据
在Win10系统中使用labelme制作图像分割标签数据 文章目录 在Win10系统中使用labelme制作图像分割标签数据 前言 一. 安装labelme3.16.2 1. 安装Anaconda(若 ...
- (Windows)anaconda安装Labelme并标注自己的数据集+数据集文件准备
主要参考文章: Windows下使用anaconda安装Labelme并标注自己的数据集_wangzhwsme的博客-CSDN博客_anaconda安装labelmehttps://blog.csdn ...
- VOC/YOLO/COCO数据集格式转换及LabelImg/Labelme/精灵标注助手Colabeler标注工具介绍
数据集格式:VOC(xml).YOLO(txt).COCO(json) 本文主要对Label格式,以及LabelImg.Labelme.精灵标注助手Colabeler这常用的三种数据标注软件进行介绍. ...
- NLP语义标注模型数据准备及实战
NLP语义标注模型数据准备及实战 目录 NLP语义标注模型数据准备及实战 流程示例 代码示例
- 什么是数据标注? 数据标注公司主要做什么?
一.什么是数据标注? 1.数据标注定义 数据标注是对未经处理的语音.图片.文本.视频等数据进行加工处理, 并转换为机器可识别信息的过程.原始数据一般通过数据采集获得, 随后的数据标注相当于对数据进行加 ...
- 纵断面图标注栏数据复制
新西兰本地化包中有一项小功能不错--纵断面图标注栏数据复制 刚好这几天我们自己也遇到了同样的需求: 利用纵断面来创建场地剖面, 剖面图标注栏要进行重复的设置. 于是参照新西兰本地化包中的功能, 自己也 ...
- 【labelme】标注工具报错ValueError: min() arg is an empty sequence
[labelme]标注工具报错ValueError: min() arg is an empty sequence 今天在用labelme对图片进行标注时,点到某处突然卡了,随后labelme直接退出 ...
- curvelanes数据集转tusimple格式进行车道线识别算法训练思路总结【数据清洗】
本篇文章包含内容涉及: 1.数据清洗整理(特定分辨率数据不符合要求,选择剔除.OpenCV下的resize方法) 2.写数据集格式转换脚本代码 3.可能遇到的问题 目录 前言: 任务背景 基础环境 一 ...
最新文章
- C++中std::sort/std::stable_sort/std::partial_sort的区别及使用
- [导入]几种流行的AJAX框架jQuery,Mootools,Dojo,Ext JS的对比
- python自带库处理excel-【Python】处理Excel的库Xlwings
- POJ 3358 Period of an Infinite Binary Expansion ★ (数论好题:欧拉函数)
- 阿里云系列——4.网站备案后续(详细步骤)---2015-11.12
- 便利的操作plist文件
- 【51单片机快速入门指南】4.6:I2C 与 PCF8563实时时钟日历芯片
- 分库分表解决方案之ShardingSphere
- Excel空值导入mysql_excel导入sqlserver时,数据为null的处理方法分享
- 全国中小学信息技术创新与实践大赛:软件创意编程赛道
- 【STM32】STM32F103C8T6+L298N通过PWM控制直流电机转速
- 广告牌定时器怎么设置时间_定时器怎么调时间
- gimp 抠图_GIMP 的基本操作
- 苹果4如何添加时间插件_iPhone如何添加输入法?苹果手机怎样添加手写输入?...
- CondaUpgradeError: This environment has previously been operated on by a conda version that‘s newer
- Docker 映射端口telnet不通
- 提问|Feed流设计是否应该展示「评论」?
- 浅谈MySQL中优化sql语句查询常用的30种方法
- 【计算机网络】频带和频段(图解易懂)
- activemq断线重连