文章目录
- 一、效果演示
- 二、环境配置
- 三、模型配置
- 四、相机配置
- 五、部分代码:
- 六、仓库链接:
一、效果演示
- Colorimage:
- Colorimage and depthimage:
二、环境配置
1.一个可以运行YOLOv5的python环境
pip install -r requirements.txt
2.一个realsense相机和pyrealsense2库
pip install pyrealsense2
在下面两个环境中测试成功
三、模型配置
修改模型配置文件,以yolov5s为例。
如果使用自己训练的模型,需要进行相应的修改。
weight: "weights/yolov5s.pt"
input_size: 640
class_num: 80
class_name: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
'hair drier', 'toothbrush' ]
threshold:
iou: 0.45
confidence: 0.6
device: '0'
四、相机配置
分辨率好像只能改特定的参数,不然会报错。d435i可以用 1280x720, 640x480, 848x480。
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)
profile = pipeline.start(config)
五、部分代码:
下方代码实现从像素坐标系到相机坐标系转换,并且标注中心点以及三维坐标信息。
for i in range(len(xyxy_list)):
ux = int((xyxy_list[i][0]+xyxy_list[i][2])/2)
uy = int((xyxy_list[i][1]+xyxy_list[i][3])/2)
dis = aligned_depth_frame.get_distance(ux, uy)
camera_xyz = rs.rs2_deproject_pixel_to_point(
depth_intrin, (ux, uy), dis)
camera_xyz = np.round(np.array(camera_xyz), 3)
camera_xyz = camera_xyz.tolist()
cv2.circle(canvas, (ux,uy), 4, (255, 255, 255), 5)
cv2.putText(canvas, str(camera_xyz), (ux+20, uy+10), 0, 1,
[225, 255, 255], thickness=2, lineType=cv2.LINE_AA)
camera_xyz_list.append(camera_xyz)
六、仓库链接:
代码已上传github:yolov5_d435i_detection
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)