Use Cmake with PCL and OpenCV
Asked Answered
J

2

0

I am new to Computer Vision. On Cmake, i am trying to use PCL and OpenCV with a 2D Lidar sensor.

I saw this tutorial: [http://unanancyowen.com/en/pcl18/#Download1

And to configure PCL on CmakeLists.txt the following code is used:

cmake_minimum_required( VERSION 2.8 )
# Create Project
project( solution )
add_executable( project main.cpp )
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "project" )

# Find Packages
find_package( PCL 1.8 REQUIRED )

if( PCL_FOUND )
  # Additional Include Directories
  # [C/C++]>[General]>[Additional Include Directories]
  include_directories( ${PCL_INCLUDE_DIRS} )

  # Preprocessor Definitions
  # [C/C++]>[Preprocessor]>[Preprocessor Definitions]
  add_definitions( ${PCL_DEFINITIONS} )
  #add_definitions( -DPCL_NO_PRECOMPILE )

  # Additional Library Directories
  # [Linker]>[General]>[Additional Library Directories]
  link_directories( ${PCL_LIBRARY_DIRS} )

  # Additional Dependencies
  # [Linker]>[Input]>[Additional Dependencies]
  target_link_libraries( project ${PCL_LIBRARIES} )
endif()

And to configure CmakeLists.txt for OpenCV, the following code:

cmake_minimum_required( VERSION 3.6 )

# Create Project
project( solution )
add_executable( project main.cpp )
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "project" )

# Find OpenCV
set( OpenCV_DIR "C:/Program Files/opencv/build" )
find_package( OpenCV REQUIRED )

# Project Settings for OpenCV
if( OpenCV_FOUND )
  # Additional Include Directories
  # [C/C++]>[General]>[Additional Include Directories]
  include_directories( ${OpenCV_INCLUDE_DIRS} )

  # Additional Library Directories
  # [Linker]>[General]>[Additional Library Directories]
  link_directories( ${OpenCV_LIB_DIR} )

  # Additional Dependencies
  # [Linker]>[Input]>[Additional Dependencies]
  target_link_libraries( project ${OpenCV_LIBS} )
endif()

How do i make a CmakeLists.txt to use with both? PCL and OpenCV.

Jasminejason answered 10/5, 2017 at 20:26 Comment(0)
J
1

Found the answer asking on the website that i got those files: http://unanancyowen.com/en/pcl18/#comment-1221

This is the code to pull OpenCV and PCL:

cmake_minimum_required( VERSION 2.8 )
# Create Project
project( solution )
add_executable( project main.cpp )

# Set StartUp Project (Option)
# (This setting is able to enable by using CMake 3.6.0 RC1 or later.)
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "project" )

# Find Packages
# Find PCL
find_package( PCL 1.8 REQUIRED )

# Find OpenCV
set( OpenCV_DIR "C:/Program Files/opencv/build" )
find_package( OpenCV REQUIRED )

if( PCL_FOUND AND OpenCV_FOUND )
  # [C/C++]>[General]>[Additional Include Directories]
  include_directories( ${PCL_INCLUDE_DIRS} )
  include_directories( ${OpenCV_INCLUDE_DIRS} )

  # [C/C++]>[Preprocessor]>[Preprocessor Definitions]
  add_definitions( ${PCL_DEFINITIONS} )

  # For Use Not PreCompiled Features 
  #add_definitions( -DPCL_NO_PRECOMPILE )

  # [Linker]>[General]>[Additional Library Directories]
  link_directories( ${PCL_LIBRARY_DIRS} )
  link_directories( ${OpenCV_LIB_DIR} )

  # [Linker]>[Input]>[Additional Dependencies]
  target_link_libraries( project ${PCL_LIBRARIES} )
  target_link_libraries( project ${OpenCV_LIBS} )
endif()

And on this link there is an old explanation and here my question on the OpenCV here.

Jasminejason answered 11/5, 2017 at 17:3 Comment(1)
Did you choose “Visual Studio 14 2015 Win64”? The latest (3.2.0) pre-built OpenCV package includes only libraries for Visual Studio 2015 x64. Therefore, If you want to use only pre-built packages of PCL and OpenCV, You should be use Visual Studio 2015 and x64 target for development environment. If you want to more information, I recommended that you post to User Q&A forum of OpenCV.Jasminejason
K
0

To use PCL and OpenCV simultaneously in the same project,You can write CMakeLists.txt file in minimum line as below:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(project_name)

find_package(PCL 1.4 REQUIRED)
find_package(OpenCV REQUIRED)

include_directories(${PCL_INCLUDE_DIRS} )
link_directories(${PCL_LIBRARY_DIRS} )
add_definitions(${PCL_DEFINITIONS} )

add_executable (project_executable main.cpp)
target_link_libraries (project_executable ${PCL_LIBRARIES} ${OpenCV_LIBS})

Kevin answered 22/7, 2019 at 6:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.