前言:
這篇是Labelme標(biāo)注車(chē)道線系列的第三篇聪轿,前幾篇文章可以參考
? ? ? ?圖像標(biāo)注工具Labelme標(biāo)注車(chē)道線的使用方法一
? ? ? ?圖像標(biāo)注工具Labelme標(biāo)注車(chē)道線的使用方法二
? ? ? ?Labelme標(biāo)注的數(shù)據(jù)轉(zhuǎn)換為tusimple數(shù)據(jù)集格式
前兩篇文章介紹了如何使用Labelme標(biāo)注車(chē)道線锌仅,以及批量處理標(biāo)注之后的車(chē)道線數(shù)據(jù)撒会,將標(biāo)注之后的json文件轉(zhuǎn)換為dataset。
那么饭弓,使用自己創(chuàng)建的數(shù)據(jù)集废士,如何標(biāo)注成tuSimple數(shù)據(jù)格式呢 ?這篇文章主要介紹如何使用Labelme標(biāo)注之后的車(chē)道線數(shù)據(jù)硫麻,創(chuàng)建自己的tuSimple數(shù)據(jù)集格式爸邢,使用的框架為L(zhǎng)aneNet車(chē)道線檢測(cè)。
視頻下載
數(shù)據(jù)是我在嗶哩嗶哩上下載的
需要安裝一下you -get
$ pip3 install you-get
$you-get https://www.bilibili.com/video/av28417566?from=search&seid=10103033464985238664
下載之后的視頻格式是.flv格式拿愧,鑒于方便杠河,我將他轉(zhuǎn)換為mp4格式,大家可以根據(jù)自己需求決定這一步要不要執(zhí)行浇辜。
提取成圖片
將視頻逐幀提取成圖片券敌,轉(zhuǎn)換方式非常簡(jiǎn)單,這里就不多說(shuō)了
按照前兩篇文檔標(biāo)注完成之后柳洋,就可以生成自己tuSimple數(shù)據(jù)集啦~~
有關(guān)laneNet詳情可參考基于深度神經(jīng)網(wǎng)絡(luò)LaneNet的車(chē)道線檢測(cè)待诅,歡迎大家指正~~~論文地址為?https:// arxiv .org / abs / 1802.05591
將標(biāo)注之后的數(shù)據(jù)批量處理之后,生成文件夾形式如下圖所示
打開(kāi)文件夾里面有五個(gè)文件熊镣,分別是
1卑雁、標(biāo)注之后的數(shù)據(jù)格式轉(zhuǎn)換
根據(jù)tuSimple數(shù)據(jù)集形式募书,需要得到二值化和實(shí)例化后的圖像數(shù)據(jù),也就是gt_binary_image和gt_instance_image文件中的顯示結(jié)果测蹲,
我們需要將標(biāo)注之后的數(shù)據(jù)進(jìn)行轉(zhuǎn)換
轉(zhuǎn)換代碼:
import cv2
from skimage import measure, color
from skimage.measure import regionprops
import numpy as np
import os
import copy
def skimageFilter(gray):
? ? binary_warped = copy.copy(gray)
? ? binary_warped[binary_warped > 0.1] = 255
? ? gray = (np.dstack((gray, gray, gray))*255).astype('uint8')
? ? labels = measure.label(gray[:, :, 0], connectivity=1)
? ? dst = color.label2rgb(labels,bg_label=0, bg_color=(0,0,0))
? ? gray = cv2.cvtColor(np.uint8(dst*255), cv2.COLOR_RGB2GRAY)
? ? return binary_warped, gray
def moveImageTodir(path,targetPath,name):
? ? if os.path.isdir(path):
? ? ? ? image_name = "gt_image/"+str(name)+".png"
? ? ? ? binary_name = "gt_binary_image/"+str(name)+".png"
? ? ? ? instance_name = "gt_binary_image/"+str(name)+".png"
? ? ? ? train_rows = image_name + " " + binary_name + " " + instance_name + "\n"
? ? ? ? origin_img = cv2.imread(path+"/img.png")
? ? ? ? origin_img = cv2.resize(origin_img, (1280,720))
? ? ? ? cv2.imwrite(targetPath+"/"+image_name, origin_img)
? ? ? ? img = cv2.imread(path+'/label.png')
? ? ? ? img = cv2.resize(img, (1280,720))
? ? ? ? gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
? ? ? ? binary_warped, instance = skimageFilter(gray)
? ? ? # cv2.imshow("origin_image",origin_img)
? ? ? # cv2.imshow('label_image',img)
? ? ? # cv2.imshow('binary_image.jpg',binary_warped)
? ? ? # cv2.imshow('instance_image.jpg',instance)
? ? ? # k = cv2.waitKey()
? ? ? ? cv2.imwrite(targetPath+"/ownData/"+binary_name, binary_warped)
? ? ? ? cv2.imwrite(targetPath+"/ownData/"+instance_name, instance)
? ? ? ? cv2.waitKey()
? ? ? ? cv2.destroyAllWindows()
? ? ? ? print("success create data name is : ", train_rows)
? ? ? ? return train_rows
? ? return train_rows
if __name__ == "__main__":
? ? count = 1
? ? with open("./train.txt", 'w+') as file:
? ? ? ? for images_dir in os.listdir("./images"):
? ? ? ? ? ? dir_name = os.path.join("./images", images_dir + "/annotations")
? ? ? ? ? ? for annotations_dir in os.listdir(dir_name):
? ? ? ? ? ? ? ? json_dir = os.path.join(dir_name, annotations_dir)
? ? ? ? ? ? ? ? if os.path.isdir(json_dir):
? ? ? ? ? ? ? ? ? ? train_rows = moveImageTodir(json_dir, "./", str(count).zfill(4))
? ? ? ? ? ? ? ? ? ? file.write(train_rows)
? ? ? ? ? ? ? ? ? ? count += 1
轉(zhuǎn)換之后的顯示結(jié)果:
2莹捡、調(diào)用laneNet中l(wèi)anenet_data_feed_pipline.py文件
python data_provider/lanenet_data_feed_pipline.py --dataset_dir ./data/training_data_example/ownData --tfrecords_dir ./data/training_data_example/ownData/tfrecords
顯示效果