码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2020-11-20 12:21:54      阅读:33      评论:0      收藏:0      [点我收藏+]

标签:遍历   实例   pat   pen   break   shape   imshow   load   personal   

# -*- 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))

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

标签:遍历   实例   pat   pen   break   shape   imshow   load   personal   

原文地址:https://www.cnblogs.com/ymec/p/13985599.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!