自动驾驶数据集KITTI【10】画出所有的2d侦测框

import pandas as pd
import numpy as np
import cv2

frame=120#有10帧

#数据单位
COLUMN_NAMES=['frame', 'track_id', 'type', 'truncated', 'occluded', 'alpha', 'bbox_left', 'bbox_top','bbox_right', 
              'bbox_bottom', 'height', 'width', 'length', 'pos_x', 'pos_y', 'pos_z', 'rot_y']
df = pd.read_csv('/home/sk/Desktop/data/training/label_02/0000.txt',header=None,sep=' ')
df.columns = COLUMN_NAMES
df.head()#head()方法,默认读取前五行,如果想显示更多,那么在括号内赋值
df.type.isin(['Truck','Van','Tram'])
df.loc[df.type.isin(['Truck','Van','Tram']),'type']='Car'
df = df[df.type.isin(['Car','Pedestrian','Cyclist'])]
df.loc[2,['bbox_left' ,'bbox_top','bbox_right','bbox_bottom']]
box=np.array(df.loc[2,['bbox_left' ,'bbox_top','bbox_right','bbox_bottom']])

image = cv2.imread('/home/sk/Desktop/data/kitti/2011_09_26/2011_09_26_drive_0005_sync/image_00/data/%010d.png'%frame)
boxes = np.array(df[df.frame==frame][['bbox_left' ,'bbox_top','bbox_right','bbox_bottom']])
types = np.array(df[df.frame==frame]['type'])

DETECTION_COLOR_DICT= {'Car':(255,255,0),'Pedestrian':(0,226,255),'Cyclist':(141,40,255)}

for typ,box in zip(types,boxes):
    top_left = int(box[0]),int(box[1])
    bottom_right = int(box[2]),int(box[3])
    cv2.rectangle(image,top_left,bottom_right,DETECTION_COLOR_DICT[typ],2)

cv2.imshow("image",image)
cv2.waitKey(0)
cv2.destroyAllWindows()

效果如图所示:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值