7

ROS Fuerte I installed on my machine uses opencv 2.2. I would like to use 2.4.9 version just installed. Its location is /home/polar/soft/lib/opencv/opencv-2.4.9/build/lib.

How to do that with CMake, please? From my search, it seems that find_library would solve the issue, but was not able to make it work.

===== I include opencv in my cpp codes like this

  #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/opencv.hpp>
    #include "opencv2/imgproc/imgproc.hpp"

=========== HERE MY CMAKE

cmake_minimum_required(VERSION 2.8)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init()
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

rosbuild_genmsg()
rosbuild_gensrv()


# GSL
find_package( PkgConfig REQUIRED)
pkg_check_modules( gsl REQUIRED gsl )

SET(corners_opencv_flag ok)

#*******************************************************************
#*******************************************************************

#******                CORNERS OPENCV

#*******************************************************************
#*******************************************************************
if(corners_opencv_flag)

  #---
  SET(execFiles_corner_opencv
    corner_v1

    )

  #---
  foreach(file_ros ${execFiles_corner_opencv})
    rosbuild_add_executable(${file_ros} computer-vision/corners/${file_ros}.cpp ) 
  endforeach(file_ros)

  #---
endif(corners_opencv_flag)


#-------------------
# STACK 
#--------------------

SET(FILES_TO_RUN
  ${execFiles_corner_opencv} 
  )


#=======================================================
#
#     CUSTOM LIBRARIES
#
#
#=======================================================
PROJECT(VOLCANO)
SET(SRC ${VOLCANO_SOURCE_DIR}/src)


#******* boost
find_package( Boost REQUIRED COMPONENTS program_options regex )
include_directories( ${Boost_INCLUDE_DIRS} )

if(Boost_FOUND)
  message("\n\n Boost found \n\n")
endif()

find_package(OpenCV REQUIRED PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)


#===== Calculus
include_directories(${SRC}/calculus)
include_directories(${SRC}/calculus/matrix)
SET(MY_LIB
  ${MY_LIB}
 Calculus
 CholeskyDecompose
 )


#-------------------------------------------
# Linking the executables against the

#-------------------------------------------

foreach(file2link ${FILES_TO_RUN})

  target_link_libraries(${file2link} 
    ${MY_LIB} 
    ${MY_LIB} 
    ${gsl_LIBRARIES}
    ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_REGEX_LIBRARY}
    ${OpenCV_LIB}
   )

endforeach(file2link)  


#--- sources folders
ADD_SUBDIRECTORY(src)
Courier
  • 920
  • 2
  • 11
  • 36
  • Have you tried `find_package( OpenCV 2.9 ... )`? – DevSolar Feb 16 '15 at 11:07
  • `find_package(OpenCV 2.4.9 PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)` does not work. Compilation error. – Courier Feb 16 '15 at 11:28
  • 1) You said you want to use version 2.9...? 2) "Compilation error"? – DevSolar Feb 16 '15 at 11:56
  • Sorry, I need 2.4.9. – Courier Feb 16 '15 at 11:58
  • "Compilation error"? Come on. You must *realize* that the information you're giving is in no way sufficient to give you any kind of assistance... – DevSolar Feb 16 '15 at 12:16
  • I get undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)`. The same error message related to the opencv functions am using. – Courier Feb 16 '15 at 13:14
  • That is a **linker** error, not a compilation error. I see you have `${OpenCV_LIB}` in there... but you only ever set that for `corner_v1`, and only `if ( corners_opencv_flag )` -- which you set to `ok`. But `if ( condition )` is true "*if the constant is 1, ON, YES, TRUE, Y, or a non-zero number*" -- note the absence of `ok`. And I'd check if `${OpenCV_LIB}` is set as expected in the first place... – DevSolar Feb 16 '15 at 13:26
  • the flag ok is only for the executables not the libraries. I suspect `OpenCV_LIB` – Courier Feb 16 '15 at 13:40
  • Voting to close as "unclear what you're asking". Pal, my crystal ball is failing to make sense of the little tidbits you're willing to share. Either you accept that something **is** broken in your setup, and cooperate with people willing to invest *their* time into helping you (including double-checking your assumptions on what's working and what isn't), or you'll have to figure it out yourself. – DevSolar Feb 16 '15 at 13:41
  • @devSolar I followed this link to install opencv [http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/] I will try to reinstall it from a different link and see what happen. – Courier Feb 16 '15 at 13:54
  • P.S. am using ubmuntu 12.04 LTS. – Courier Feb 16 '15 at 14:02
  • How is that supposed to help with your CMakeLists.txt apparently not adding the OpenCV libraries to whatever target you are trying to compile? If it hadn't **found** OpenCV, it would have failed at config stage due to the `REQUIRED` in `find_package`. Stop hunting what you *think* might be the error and go for *proof*. *Check your assumptions.* Or start actually answering the questions asked, instead of continuing an unrelated monologue. – DevSolar Feb 16 '15 at 14:02

3 Answers3

7

Add this to your CMakeLists.txt replacing the previous find_package(OpenCV) line:

find_package(OpenCV REQUIRED PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)

There should be a cmake directory in your opencv installation.

texasflood
  • 1,571
  • 1
  • 13
  • 22
2

So, as I suspected, target_link_libraries(${file2link} .... ${OpenCV_LIB}) was the problem: OpenCV_LIB seems like allocated.

Now, am linking opencv in this way and it works:

find_package(OpenCVV 2.4.9 PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)
...
target_link_libraries(${file2link}  .... ${OpenCVV_LIB})

In fact I just used another name but OpenCV.

@texasflood, thanks for your help.

Courier
  • 920
  • 2
  • 11
  • 36
1

There is lot of confusion here and No Proper Code to solidify the suggestions.

cmake_minimum_required(VERSION 3.1)

project( DisplayImage )

# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

# For OpenCV 4
SET(OpenCV_DIR <current-path>/Learning/opencv-installation/installation/OpenCV-master/lib/cmake/opencv4)

# For OpenCV 3
# SET(OpenCV_DIR "<current-path>/opencv3.4.8/installation/OpenCV-3.4.8/share/OpenCV/")

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage main.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

Thank you.