Kitti格式化数据可视化脚本visualize1.py
import numpy as np
import cv2
from PIL import Image
import os
def visualize_kitti_format_data(image_path, label_path):
'''
image_path: 图片路径
label_path: 标签路径
'''
assert os.path.exists(image_path), "图片路径不存在"
assert os.path.exists(label_path), "标签路径不存在"
image = cv2.imread(image_path)
with open(label_path, 'r') as f:
lines = f.readlines()
for line in lines:
line = line.strip().split()
if line[0] == 'Car':
x_min, y_min, x_max, y_max = map(int, line[4:8])
cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 255, 0), 2)
# 展示图片
img = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
img.show()
# 示例
if __name__ == '__main__':
image_path = 'data/image.png'
label_path = 'data/label.txt'
visualize_kitti_format_data(image_path, label_path)
下载地址
用户评论