Ubuntu18.04源码安装Open3D

本文档详细介绍了如何在Ubuntu上安装Open3D,包括克隆源码、依赖安装、编译和安装步骤。之后,通过创建一个简单的C++程序`demo.cpp`来测试Open3D的安装,并提供了`CMakeLists.txt`配置文件。测试过程包括读取 ply 文件并使用 Open3D 的可视化功能展示点云。最后,演示了如何通过命令行使用Open3D打开文件进行查看。

安装Open3D

git clone https://github.com/isl-org/Open3D.git
cd Open3D
sh util/install_deps_ubuntu.sh
mkdir build
cd build
cmake ..
make -j4
sudo make install

测试安装是否成功:

这里写一个简单的文件编译运行试试

文件如下:

demo.cpp文件如下:

#include <iostream>
#include <memory>
#include <thread>
#include <open3d/Open3D.h>

// A simplified version of examples/Cpp/Visualizer.cpp to demonstrate linking
// an external project to Open3D.
int main(int argc, char *argv[])
{
    using namespace open3d;

    utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
    if (argc < 3)
    {
        utility::LogInfo("Open3D {}\n", OPEN3D_VERSION);
        utility::LogInfo("\n");
        utility::LogInfo("Usage:\n");
        utility::LogInfo("    > TestVisualizer [mesh|pointcloud] [filename]\n");
        //CI will execute this file without input files, return 0 to pass
        return 0;
    }

    std::string option(argv[1]);
    if (option == "mesh")
    {
        auto mesh_ptr = std::make_shared<geometry::TriangleMesh>();
        if (io::ReadTriangleMesh(argv[2], *mesh_ptr))
        {
            utility::LogInfo("Successfully read {}\n", argv[2]);
        }
        else
        {
            utility::LogWarning("Failed to read {}\n\n", argv[2]);
            return 1;
        }
        mesh_ptr->ComputeVertexNormals();
        visualization::DrawGeometries({mesh_ptr}, "Mesh", 1600, 900);
    }
    else if (option == "pointcloud")
    {
        auto cloud_ptr = std::make_shared<geometry::PointCloud>();
        if (io::ReadPointCloud(argv[2], *cloud_ptr))
        {
            utility::LogInfo("Successfully read {}\n", argv[2]);
        }
        else
        {
            utility::LogWarning("Failed to read {}\n\n", argv[2]);
            return 1;
        }
        cloud_ptr->NormalizeNormals();
        visualization::DrawGeometries({cloud_ptr}, "PointCloud", 1600, 900);
    }
    else
    {
        utility::LogWarning("Unrecognized option: {}\n", option);
        return 1;
    }
    utility::LogInfo("End of the test.\n");

    return 0;
}

CMakeLists.txt文件如下:

cmake_minimum_required(VERSION 3.0)
project(open3d_test)
set (CMake policy CMP0074)
set(CMAKE_CXX_STANDARD 11)

find_package( Open3D  REQUIRED)

include_directories(${Open3D_INCLUDE_DIRS})
link_directories(${Open3D_LIBRARY_DIRS})

add_executable(TestVisualizer demo.cpp)
target_link_libraries(TestVisualizer ${Open3D_LIBRARIES})

target_include_directories(TestVisualizer PUBLIC ${Open3D_INCLUDE_DIRS})

mkdir build
cd build
cmake ..
make -j4
cd build
./TestVisualizer pointcloud 文件路径名(此处我选择的是一个ply文件)
 

打开效果如下:

如果想通过Open3D查看文件:

终端输入

open3d draw 文件名

 

参考:

Ubuntu18.04 install Open3D C++ and Python version - Katastros

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值