Open ohm-zx opened 3 months ago
我也遇到的同样的问题,请问您解决了吗,
我也是同样的问题,请问您解决了吗
@1gjjuser1 @hxlei0827 @ohm-zx import os os.environ['DISPLAY']='1'
我通过使用open3d的方法,写了可视化的代码 import open3d as o3d import numpy as np import json import os
pointcloud_file_path = 'E:/mmdetection3d-main/demo/data/kitti/000008.bin' result_file_path = 'E:/mmdetection3d-main/outputs/preds/000008.json' # 更新路径
if not os.path.exists(pointcloud_file_path): raise FileNotFoundError(f"No such file or directory: '{pointcloud_file_path}'")
if not os.path.exists(result_file_path): raise FileNotFoundError(f"No such file or directory: '{result_file_path}'")
pcd = np.fromfile(pointcloud_file_path, dtype=np.float32).reshape(-1, 4) points = pcd[:, :3] # 提取点的坐标
pcd_open3d = o3d.geometry.PointCloud() pcd_open3d.points = o3d.utility.Vector3dVector(points)
with open(result_file_path) as f: results = json.load(f)
geometries = [pcd_open3d]
for bbox in results['bboxes_3d']: center = bbox[:3] extent = bbox[3:6] rotation = bbox[6]
# 创建Open3D的OrientedBoundingBox对象
obb = o3d.geometry.OrientedBoundingBox(center, np.eye(3), extent)
obb.rotate(o3d.geometry.get_rotation_matrix_from_xyz((0, 0, rotation)))
obb.color = (1, 0, 0) # 设置为红色
geometries.append(obb)
o3d.visualization.draw_geometries(geometries)
bro, you can try this: To set the environment variable DISPLAY across the entire environment, you can use different methods depending on the operating system. Here are some common approaches:
On Linux/MacOS
Temporary Setting (valid only for the current terminal session):
export DISPLAY=1
Permanent Setting (valid for all terminal sessions):
Open your shell configuration file, such as ~/.bashrc or ~/.bash_profile, and add the following line:
export DISPLAY=1
Save the file and run the following command to apply the changes:
source ~/.bashrc
On Windows
Using Command Prompt (valid only for the current session):
set DISPLAY=1
In Python If you want to set the environment variable within a Python script and have it valid for the entire script, you can use the following code:
import os
os.environ['DISPLAY'] = '1'
This will only be valid for the current Python process. For a system-wide setting, use one of the methods mentioned above.
我通过使用open3d的方法,写了可视化的代码 import open3d as o3d import numpy as np import json import os
使用绝对路径
pointcloud_file_path = 'E:/mmdetection3d-main/demo/data/kitti/000008.bin' result_file_path = 'E:/mmdetection3d-main/outputs/preds/000008.json' # 更新路径
if not os.path.exists(pointcloud_file_path): raise FileNotFoundError(f"No such file or directory: '{pointcloud_file_path}'")
if not os.path.exists(result_file_path): raise FileNotFoundError(f"No such file or directory: '{result_file_path}'")
读取点云数据
pcd = np.fromfile(pointcloud_file_path, dtype=np.float32).reshape(-1, 4) points = pcd[:, :3] # 提取点的坐标
创建Open3D点云对象
pcd_open3d = o3d.geometry.PointCloud() pcd_open3d.points = o3d.utility.Vector3dVector(points)
读取推理结果
with open(result_file_path) as f: results = json.load(f)
创建几何对象列表
geometries = [pcd_open3d]
解析结果并绘制检测框
for bbox in results['bboxes_3d']: center = bbox[:3] extent = bbox[3:6] rotation = bbox[6]
# 创建Open3D的OrientedBoundingBox对象 obb = o3d.geometry.OrientedBoundingBox(center, np.eye(3), extent) obb.rotate(o3d.geometry.get_rotation_matrix_from_xyz((0, 0, rotation))) obb.color = (1, 0, 0) # 设置为红色 geometries.append(obb)
使用 Open3D 可视化点云和检测结果
o3d.visualization.draw_geometries(geometries)
thanks, it works! 请问之后如何把点云的检测框叠加到png图片上呢?
Prerequisite
Task
I'm using the official example scripts/configs for the officially supported tasks/models/datasets.
Branch
main branch https://github.com/open-mmlab/mmdetection3d
Environment
cuda113 open3d 0.18.0 pytorch 1.11.0 windows10 gpu nvidia geforce rtx 3080
Reproduces the problem - code sample
无
Reproduces the problem - command or script
运行推理demo:python demo/pcd_demo.py demo/data/kitti/000008.bin pointpillars_hv_secfpn_8xb6-160e_kitti-3d-car.py hv_pointpillars_secfpn_6x8_160e_kitti-3d-car_20220331_134606-d42d15ed.pth --show
Reproduces the problem - error message
mmengine - WARNING - Display device not found.
--show
is forced to False c:\users\pc\desktop\mmdetection3d\mmdet3d\models\dense_heads\anchor3d_head.py:94: UserWarning: dir_offset and dir_limit_offset will be depressed and be incorporated into box coder in the future warnings.warn( Loads checkpoint by local backend from path: hv_pointpillars_secfpn_6x8_160e_kitti-3d-car_20220331_134606-d42d15ed.pth 06/27 18:04:48 - mmengine - WARNING - Failed to search registry with scope "mmdet3d" in the "function" registry tree. As a workaround, the current "function" registry in "mmengine" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmdet3d" is a correct scope, or whether the registry is initialized. C:\Users\PC\anaconda3\envs\z_open\lib\site-packages\mmengine\visualization\visualizer.py:196: UserWarning: Failed to add <class 'mmengine.visualization.vis_backend.LocalVisBackend'>, please provide thesave_dir
argument. warnings.warn(f'Failed to add {vis_backend.class}, ' C:\Users\PC\anaconda3\envs\z_open\lib\site-packages\torch\functional.py:568: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:2228.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] [Open3D WARNING] invalid color in PaintUniformColor, clipping to [0, 1] Inference ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━06/27 18:04:53 - mmengine - INFO - results have been saved at output
Additional information
这个可视化问题如何解决,我配置的环境哪里有问题吗? How to solve this visualization problem, and where is there a problem with my configured environment?