Foundationpose算法复现过程记录
Foundationpose算法github地址
原论文地址
复现了一下Foundationpose,这个目前BOP排名第一的算法,简要记录一下。
- 首先下载源码
git clone https://github.com/NVlabs/FoundationPose.git
cd FoundationPose
# create conda environment
create -n foundationpose python=3.9
# activate conda environment
conda activate foundationpose
# install dependencies \\requirements.txt中的包比较多,建议分块分多次安装,避免冲突问题
python -m pip install -r requirements.txt
# Install NVDiffRast
python -m pip install --quiet --no-cache-dir git+https://github.com/NVlabs/nvdiffrast.git
# 如果上述命令安装失败,则可以从该git地址下载nvdiffrast源码然后使用 python setup.py 命令安装
# Kaolin (Optional, needed if running model-free setup)
python -m pip install --quiet --no-cache-dir kaolin==0.15.0 -f https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.0.0_cu118.html
# # 如果上述命令安装失败,则可以从该https地址下载合适版本的kaolin然后使用 pip install "/path_to_whl" 命令安装,下面的 PyTorch3D也是类似的
# PyTorch3D
python -m pip install --quiet --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py39_cu118_pyt200/download.html
# Build extensions
CMAKE_PREFIX_PATH=$CONDA_PREFIX/lib/python3.9/site-packages/pybind11/share/cmake/pybind11 bash build_all_conda.sh
- 安装eigen库
cd $HOME && wget -q https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz && \
tar -xzf eigen-3.4.0.tar.gz && \
cd eigen-3.4.0 && mkdir build && cd build
cmake .. -Wno-dev -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-std=c++14 ..
sudo make install
cd $HOME && rm -rf eigen-3.4.0 eigen-3.4.0.tar.gz
- 测试demo
python run_demo.py
得到如下可视化结果:
6. 使用自己的模型做位姿估计
这里我使用的是自己做的linemod数据集(参考这个教程:linemod数据集制作与处理)
然后修改run_demo.py代码对应的数据路径即可:
parser.add_argument('--mesh_file', type=str, default='/root/FoundationPose/Linemod_preprocessed/models/***.ply') #重建的ply模型路径
parser.add_argument('--test_scene_dir', type=str, default='/root/FoundationPose/Linemod_preprocessed/data/01') #数据路径,主要需要rgb,mask,depth以及相机内参K.txt(3*3矩阵)
另外,需要对datareader.py文件中读取mask以及内参部分的代码做小修改,根据报错来就行。
此外,还要注意模型文件.ply文件中需要有法向量信息,可以用meshlab生成。
- todo
使用nerf重建模型;
使用realsense相机完成实时位姿估计;
bug
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /io/opencv/modules/highgui/src/window.cpp, line 545
sudo apt install libgtk2.0-dev pkg-config as the prompt says for Ubuntu users -> [Same Error]
pip uninstall opencv-python-headless -> [Other Error]
pip uninstall opencv-python; pip install opencv-python -> [Solved]