Tusimple 数据集可视化

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()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值