Browse Source

init project

Marc Klinge 1 year ago
commit
e853b2fee6
5 changed files with 141 additions and 0 deletions
  1. 8 0
      .gitignore
  2. 41 0
      3d-scanner.cpp
  3. 73 0
      CMakeLists.txt
  4. 19 0
      README.md
  5. BIN
      test.ply

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+.ply
+CmakeFiles/
+.vscode/
+3d-scanner
+cmake_install.cmake
+CMakeCache.txt
+compile_commands.json
+Makefile

+ 41 - 0
3d-scanner.cpp

@@ -0,0 +1,41 @@
+#include <librealsense2/rs.hpp>
+#include <iostream>
+
+int main(int argc, char *argv[])
+try
+{
+
+    rs2::pointcloud pc;
+    rs2::points points;
+    rs2::pipeline pipe;
+
+    pipe.start();
+
+    auto frames = pipe.wait_for_frames();
+
+    auto color = frames.get_color_frame();
+
+    // For cameras that don't have RGB sensor, we'll map the pointcloud to infrared instead of color
+    if (!color)
+        color = frames.get_infrared_frame();
+
+    pc.map_to(color);
+
+    auto depth = frames.get_depth_frame();
+
+    points = pc.calculate(depth);
+
+    points.export_to_ply("test.ply", color);
+
+    return EXIT_SUCCESS;
+}
+catch (const rs2::error &e)
+{
+    std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
+    return EXIT_FAILURE;
+}
+catch (const std::exception &e)
+{
+    std::cerr << e.what() << std::endl;
+    return EXIT_FAILURE;
+}

+ 73 - 0
CMakeLists.txt

@@ -0,0 +1,73 @@
+#  minimum required cmake version: 3.1.0
+cmake_minimum_required(VERSION 3.1.0)
+
+project(3d-scanner)
+
+# Save the command line compile commands in the build output
+set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
+
+# Make project require C++11
+include(CheckCXXCompilerFlag)
+CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
+CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
+if(COMPILER_SUPPORTS_CXX11)
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+elseif(COMPILER_SUPPORTS_CXX0X)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+endif()
+
+# commented all Windows related lines, might add later for Windows support
+
+# Simple non robust way to find the librealsense library
+# if(WIN32)
+#     if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
+#         set(LIBRARY_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\lib\\x64")          # TODO: Update this variable to correct path - folder where realsense2.lib is found
+#         set(DLL_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\bin\\x64")              # TODO: Update this variable to correct path - folder where realsense2.dll is found
+#     else()
+#         set(LIBRARY_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\lib\\x86")          # TODO: Update this variable to correct path - folder where realsense2.lib is found
+#         set(DLL_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\bin\\x86")              # TODO: Update this variable to correct path - folder where realsense2.dll is found
+#     endif()
+#     set(PROJECT_BINARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/\$\(Configuration\)")                # TODO: Update this variable to correct path - folder to which your project will compile
+#     set(ADDITIONAL_INCLUDE_DIRS "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\include")   # TODO: Update this variable to correct path - folder where librealsense2 folder is found
+# endif()
+
+
+# find_library(REALSENSE2_FOUND realsense2 HINTS ${LIBRARY_DIR} REQUIRED)
+# if(NOT REALSENSE2_FOUND)
+#     SET(REALSENSE2_FOUND "realsense2")
+#     message(WARN "Failed to find_library(realsense2)")
+# endif()
+find_package(realsense2 REQUIRED)
+find_package(OpenCV 4 REQUIRED)
+# find_package(GLFW3 REQUIRED)
+
+# set(SOURCES 3d-scanner.cpp ${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/openglHelper.hpp)
+add_executable(3d-scanner 3d-scanner.cpp)
+include_directories(3d-scanner ${realsense2_INCLUDE_DIR})
+# include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdParty)
+# include_directories(/opt/homebrew/include/)
+# target_link_libraries(3d-scanner ${DEPENDENCIES})
+target_link_libraries(3d-scanner ${realsense2_LIBRARY})
+target_link_libraries(3d-scanner ${OpenCV_LIBS})
+# target_link_libraries(3d-scanner glfw)
+# set_target_properties (3d-scanner PROPERTIES FOLDER Examples)s
+
+# Post Build script to copy realsense2.dll
+# if(WIN32)
+# message(STATUS "Adding Post build script to copy realsense2.dll to project's binary folder")
+# message(STATUS "Will try to copy from ${DLL_DIR} to ${PROJECT_BINARY_OUTPUT_PATH}")
+# add_custom_command(TARGET 3d-scanner POST_BUILD        # Adds a post-build event to 3d-scanner
+#     COMMAND ${CMAKE_COMMAND} -E copy_if_different              # which executes "cmake - E copy_if_different..."
+#         "${DLL_DIR}/realsense2.dll"                            # <--this is in-file
+#         ${PROJECT_BINARY_OUTPUT_PATH})                 # <--this is out-file path
+# endif()
+
+install(
+    TARGETS
+
+    3d-scanner
+
+    RUNTIME DESTINATION
+    ${CMAKE_INSTALL_PREFIX}/bin
+)

+ 19 - 0
README.md

@@ -0,0 +1,19 @@
+# realsense-3d-scanner
+3D Scanning Software for intel realsense Depth cameras
+
+## How to start
+
+First run cmake to create a Makefile
+```bash
+cmake .
+```
+
+Then run make to build the project
+```bash
+make
+```
+
+Execute the built file
+```bash
+./3d-scanner
+```

BIN
test.ply