将tusimple转换为lanenet-lane-detection可以训练的方式

2020-12-22 06:30

阅读:786

# -*- coding: utf-8 -*-
import cv2
import json
import numpy as np

base_path = "D:/Personal_Task/A3_ADASProject/Traffic_Line/dataset/train_set/"
targetpath = "D:/Personal_Task/A3_ADASProject/Traffic_Line/dataset/"
traintxt_path = "D:/Personal_Task/A3_ADASProject/Traffic_Line/dataset/train.txt"
file = open(base_path + ‘label_data_0313.json‘, ‘r‘)

# image_name = "gt_image/" + str(name) + ".png"
# binary_name = "gt_binary_image/" + str(name) + ".png"
# instance_name = "gt_instance_image/" + str(name) + ".png"
image_num = 0

for line in file.readlines():
with open("D:/Personal_Task/A1_manka_tusimple_make/new_train.txt", ‘w+‘) as file:
image_name = "gt_image/" + str(image_num).zfill(4) + ".png"
binary_name = "gt_binary_image/" + str(image_num).zfill(4) + ".png"
instance_name = "gt_instance_image/" + str(image_num).zfill(4) + ".png"
train_rows = image_name + " " + binary_name + " " + instance_name + "\n"
file.write(train_rows)

data = json.loads(line)
# print data[‘raw_file‘]
# 取第 29 帧 看一下处理的效果

image = cv2.imread(base_path + data[‘raw_file‘])
# 二进制图像数组初始化
binaryimage = np.zeros((image.shape[0], image.shape[1], 1), np.uint8)
# 实例图像数组初始化
instanceimage = binaryimage.copy()
arr_width = data[‘lanes‘]
arr_height = data[‘h_samples‘]
width_num = len(arr_width)
height_num = len(arr_height)
# print width_num
# print height_num
# 遍历纵坐标
for i in range(height_num):
lane_hist = 40
# 遍历各个车道的横坐标
for j in range(width_num):
# 端点坐标赋值
if arr_width[j][i - 1] > 0 and arr_width[j][i] > 0:
binaryimage[int(arr_height[i]), int(arr_width[j][i])] = 255
instanceimage[int(arr_height[i]), int(arr_width[j][i])] = lane_hist
if i > 0:
# 画线,线宽10像素
cv2.line(binaryimage, (int(arr_width[j][i - 1]), int(arr_height[i - 1])),
(int(arr_width[j][i]), int(arr_height[i])), 255, 10)
cv2.line(instanceimage, (int(arr_width[j][i - 1]), int(arr_height[i - 1])),
(int(arr_width[j][i]), int(arr_height[i])), lane_hist, 10)
lane_hist += 50
# cv2.imshow(‘image.jpg‘, image)
# cv2.waitKey()
# cv2.imshow(‘binaryimage.jpg‘, binaryimage)
# cv2.waitKey()
# cv2.imshow(‘instanceimage.jpg‘, instanceimage)
# cv2.waitKey()
cv2.imwrite(targetpath + "/" + image_name, image)
cv2.imwrite(targetpath + "/" + binary_name, binaryimage)
cv2.imwrite(targetpath + "/" + instance_name, instanceimage)
# break
# string1=base_path+"gt_image_binary/"+str(image_num)+".png"
# string2=base_path+"gt_image_instance/"+str(image_num)+".png"
# string3=base_path+"raw_image/"+str(image_num)+".png"
# cv2.imwrite(string1,binaryimage)
# cv2.imwrite(string2,instanceimage)
# cv2.imwrite(string3,image)
print(str(image_num) + " over")
image_num = image_num + 1

file.close()
print("total image_num:" + str(image_num))


评论


亲,登录后才可以留言!