累了就要打游戏 2020-08-25 15:13:10 3350 收藏 25
分类专栏: # Open3D 文章标签: 点云 Open3D C++
版权
Open3D
专栏收录该内容
5 篇文章1 订阅
订阅专栏
20200825:今天七夕,呱呱呱
Open3D是一个支持三维数据处理的开源库,支持C ++和Python。后端经过高度优化,并设置为并行化。MIT协议。
官网:http://www.open3d.org/
GitHub: https://github.com/intel-isl/Open3D
python版本安装方便:pip install open3d 或者
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple open3d
下面介绍C++版本的配置(相比于一行python代码,C++真是牛逼)
一、下载源码
GitHub地址:https://github.com/intel-isl/Open3D
1.1 克隆源码【笔者的源码路径为 D:/Open3D/Open3D】
1.2 切换版本【笔者用过的版本为 v0.8.0 和 v0.10.0】
1.3 更新子模块【用于获取第三方库!很重要!】
注意:v0.8.0更新的时候没有报错;但是v0.10.0更新的时候失败了【抱着试试的心态继续进行,后续没出错,感觉是我 git 用的还不熟练的原因吧】
结果如下:
二、CMake编译
2.1 设置路径
【source code: D:/Open3D/Open3D; build binaries: D:/Open3D】
【笔者设置 CMAKE/CMAKE_INSTALL_PREFIX 的路径为 D:/Open3D/install】
2.2 generator选择 Visual Studio 15 2017【官方建议 VS2019及以上】,optional platform for generator 选择x64
2.3 Configure -> Configure done
2.4 Generate -> Generating done
三、生成解决方案
3.1 打开
VS2017打开 D:/Open3D/Open3D.sln【官方建议 VS2019及以上】Release-x64
3.2 将CMakePredefinedTargets/ALL_BUILD设为启动项,右击生成
【v0.8.0版本报错了:...\VS2017\IDE\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(209,5): error MSB6006: “cmd.exe”已退出,代码为 9009。后续没报错,所以貌似好像应该可能大概 没啥影响吧】
【v0.10.0版本没有报错:成功61个】
3.3 打包包
右击 CMakePredefinedTargets/INSTALL,仅用于项目 -> 仅生成INSTALL;
在 D:/Open3D/install 中会生成CMake文件、头文件、静态库,如下图
四、测试
官方参考:http://www.open3d.org/docs/release/cpp_project.html#create-cplusplus-project【very nice】
4.1 下载测试文件
下载TestVisualizer.cpp和 CMakeLists.txt到 F:/testVisualizer【路径随便改,高兴就行】
4.2 修改TestVisualizer.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[])
{
/* add by lljydyx */
argc = 4;
argv[1] = "pointcloud";
argv[2] = "F:/rabbit.pcd";
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;
}
CMakeList.txt 如下:
cmake_minimum_required(VERSION 3.1)
set (CMAKE_CXX_STANDARD 14)
project(TestVisualizer)
# Find installed Open3D, this imports
# Open3D_INCLUDE_DIRS
# Open3D_LIBRARIES
# Open3D_LIBRARY_DIRS
# Open3D_C_FLAGS
# Open3D_CXX_FLAGS
# Open3D_EXE_LINKER_FLAGS
if(WIN32)
find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/CMake)
else()
find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/lib/CMake)
list(APPEND Open3D_LIBRARIES dl)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Open3D_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}")
# Set OS-specific things here
if(WIN32)
if (ENABLE_GUI)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE")
# Filament is built with /MT[d], but by default CMake automatically
# sets "/MD" and "/MDd". They can't coexist, so we need to replace them.
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif()
elseif(CYGWIN)
elseif(APPLE)
elseif(UNIX)
add_definitions(-DUNIX)
add_compile_options(-Wno-deprecated-declarations)
add_compile_options(-Wno-unused-result)
add_definitions(-O3)
endif(WIN32)
# Open3D
if (Open3D_FOUND)
message(STATUS "Found Open3D ${Open3D_VERSION}")
# link_directories must be before add_executable
link_directories(${Open3D_LIBRARY_DIRS})
add_executable(TestVisualizer TestVisualizer.cpp)
target_link_libraries(TestVisualizer ${Open3D_LIBRARIES})
target_include_directories(TestVisualizer PUBLIC ${Open3D_INCLUDE_DIRS})
# Hot fix windows dll not found issue, assumming we're using the Release build
option(BUILD_SHARED_LIBS "Whether Open3D was build as shared library" OFF)
if(WIN32 AND BUILD_SHARED_LIBS)
message("Will copy Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/Release")
add_custom_command(TARGET TestVisualizer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_INSTALL_PREFIX}/bin/Open3D.dll
${CMAKE_CURRENT_BINARY_DIR}/Release)
endif()
if(WIN32 AND ENABLE_GUI)
message("Will copy SDL2.dll to ${CMAKE_CURRENT_BINARY_DIR}/Release")
add_custom_command(TARGET TestVisualizer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_INSTALL_PREFIX}/lib/SDL2.dll
${CMAKE_CURRENT_BINARY_DIR}/Release)
endif()
else ()
message(SEND_ERROR "Open3D not found")
endif ()
4.3 按照官方参考进行 CMake 编译【笔者的Open3D_DIR路径为 D:/Open3D/install/CMake 】
4.4 Configure -> Configure done
4.5 Generate -> Generating done
五、运行
VS2017打开 F:\testVisualizer\build\TestVisualizer.sln,Release-x64
将ALL_BUILD设置为启动项,右击生成。
将TestVisualizer设置为启动项,运行结果如下
————————————————
版权声明:本文为CSDN博主「累了就要打游戏」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xinjiang666/article/details/108208133