import os
import cv2
import numpy as np
import json
from time import sleep
# tusimple 数据集地址
basedir = r'F:\data\tusimple'
def get_laneData(filepath, y_samples, gt_lanes):
img = None
imgLable = None
if os.path.exists(filepath) and gt_lanes:
img = cv2.imread(filepath) # 读取图片
# 获取点
labelPos = [[(x, y) for (x, y) in zip(lane, y_samples) if x >= 0]
for lane in gt_lanes]
labelPos = [lane for lane in labelPos if len(lane) > 0]
# 绘制点
imgLable = img.copy()
for lpos in labelPos:
for point in lpos:
cv2.circle(imgLable, point, 2, (0, 0, 255), 2)
# 对没有车道线的图片仅读取图片
elif os.path.exists(filepath):
img = cv2.imread(filepath)
imgLable = None
else:
print("no image")
return img, imgLable
text_path = r'test_label.json'
for line in open(os.path.join(basedir, text_path)):
# 读取数据
data = json.loads(line)
y_samples = data['h_samples']
gt_lanes = data['lanes']
path = data['raw_file']
# 获取img以及绘制的imglabel
img, imglabel = get_laneData(os.path.join(
basedir, path.strip('\n')), y_samples, gt_lanes)
# 均存在
if img.any() and imglabel is not None:
imglabel = cv2.resize(imglabel, (1024, 512))
cv2.imshow('dsh', imglabel)
sleep(0.1)
# 无线
elif img.any() is not None:
cv2.imshow('dsh', img)
sleep(0.1)
# 退出判断
if cv2.waitKey(1) & 0xFF == ord('q'): # 按q退出
cv2.waitKey(0)
cv2.destroyAllWindows()
12-19
03-29
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-19
3565
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交