Cmake searches for opencv library - opencv

I have installed Opencv-3.2 and I can see the bin and lib files
$ ls /share/apps/computer/opencv-3.2.0/built/bin/opencv_
opencv_annotation opencv_createsamples opencv_traincascade opencv_version opencv_visualisation
$ ls /share/apps/computer/opencv-3.2.0/built/lib/
libopencv_calib3d.so libopencv_imgcodecs.so.3.2.0 libopencv_stitching.so.3.2
libopencv_calib3d.so.3.2 libopencv_imgproc.so libopencv_stitching.so.3.2.0
libopencv_calib3d.so.3.2.0 libopencv_imgproc.so.3.2 libopencv_superres.so
libopencv_core.so libopencv_imgproc.so.3.2.0 libopencv_superres.so.3.2
libopencv_core.so.3.2 libopencv_ml.so libopencv_superres.so.3.2.0
libopencv_core.so.3.2.0 libopencv_ml.so.3.2 libopencv_videoio.so
libopencv_features2d.so libopencv_ml.so.3.2.0 libopencv_videoio.so.3.2
libopencv_features2d.so.3.2 libopencv_objdetect.so libopencv_videoio.so.3.2.0
libopencv_features2d.so.3.2.0 libopencv_objdetect.so.3.2 libopencv_video.so
libopencv_flann.so libopencv_objdetect.so.3.2.0 libopencv_video.so.3.2
libopencv_flann.so.3.2 libopencv_photo.so libopencv_video.so.3.2.0
libopencv_flann.so.3.2.0 libopencv_photo.so.3.2 libopencv_videostab.so
libopencv_highgui.so libopencv_photo.so.3.2.0 libopencv_videostab.so.3.2
libopencv_highgui.so.3.2 libopencv_shape.so libopencv_videostab.so.3.2.0
libopencv_highgui.so.3.2.0 libopencv_shape.so.3.2 pkgconfig/
libopencv_imgcodecs.so libopencv_shape.so.3.2.0
libopencv_imgcodecs.so.3.2 libopencv_stitching.so
Now, according to the tutorial, I wrote a simple program. Problem is that, cmake gets some errors and seems that it is not able to find the library.
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
I don't know how to set CMAKE_PREFIX_PATH or OpenCV_DIR. How can I fix that?
The content of CMakeLists.txt is
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

It depends whether you have OpenCVConfig.cmake script, which comes with your installation of OpenCV (that is, under install directory /share/apps/computer/opencv-3.2.0/built/).
If your installation of OpenCV lacks of OpenCVConfig.cmake script, you need to ship your project with script FindOpenCV.cmake (find and copy it from the net, almost any of them is suitable), and add directory with this script to CMAKE_MODULE_PATH variable:
list(APPEND CMAKE_MODULE_PATH <directory-with-find-script>)
Possible ways to hint CMake about your installation of OpenCV:
If you have OpenCVConfig.cmake script, set OpenCV_DIR variable to directory contained this script:
cmake -DOpenCV_DIR=/share/apps/computer/opencv-3.2.0/built/<...>
Set CMAKE_PREFIX_PATH variable to installation prefix of OpenCV:
cmake -DCMAKE_PREFIX_PATH=/share/apps/computer/opencv-3.2.0/built
This works both with OpenCVConfig.cmake and with FindOpenCV.cmake scripts. See also that question: Hinting Find<name>.cmake Files with a custom directory.

Related

using vcpkg+cmake+opencv generate a project, but encounter fatal error: “opencv2/core/core.hpp”: No such file or directory

I download OpencV using VCPKG:
./vcpkg install opencv2:x64-windows
Computing installation plan...
The following packages are already installed:
opencv2[core,eigen,jpeg,png,tiff]:x64-windows -> 2.4.13.7#5
Package opencv2:x64-windows is already installed
Total elapsed time: 2.225 ms
The package opencv2:x64-windows provides CMake targets:
find_package(OpenCV CONFIG REQUIRED)
# Note: 15 target(s) were omitted.
target_link_libraries(main PRIVATE opencv_ml opencv_ts opencv_gpu opencv_ocl)
and write cmakelists like this:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_TOOLCHAIN_FILE E:/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
# set the project name
project(QRCODE)
# add the executable
add_executable(qrcode main.cpp)
find_package(OpenCV COMPONENTS REQUIRED)
# Additional Include Directories
include_directories( ${OpenCV_INCLUDE_DIRS} )
# Additional Library Directories
link_directories( ${OpenCV_LIB_DIR} )
# Additional Dependencies
target_link_libraries(qrcode ${OpenCV_LIBS})
message("${OpenCV_DIR}")
message("${OpenCV_INCLUDE_DIRS}")
and what puzzles me is that cmake output looks like this:
E:/vcpkg/installed/x64-windows/share/opencv
/include/opencv;/include
it seems like opencv was not installed successfully, or cmake couldn't find opencv install path.
When I built the project using cmake tool, encountered with fatal error: “opencv2/core/core.hpp”: No such file or directory.

Could not find module FindOpenCV.cmake in ROS Build

when i want build my package in ros this error show my:
CMake Error at image_view/CMakeLists.txt:6 (find_package):
Could not find a package configuration file provided by "OpenCV" (requested
version 3.4.9) with any of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/beny/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/beny/catkin_ws/build/CMakeFiles/CMakeError.log".
make: *** [Makefile:2490: cmake_check_build_system] Error 1

Ros catkin_make fail with Qt

I'm getting this error when I catkin_make my workspace:
[100%] Linking CXX executable /home/ankilp/test_ws/devel/lib/lidar_depth/lidar_depth
/usr/bin/ld: cannot find -lQt5::Widgets
This is my CMakeList file:
cmake_minimum_required(VERSION 2.8.3)
project(lidar_depth)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
genmsg
)
find_package( PCL REQUIRED)
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
include(${QT_USE_FILE})
add_definitions(-DQT_NO_KEYWORDS)
catkin_package(
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
${catkin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
)
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(${PROJECT_NAME} src/LidarDepth.cpp src/Projection_matrices.hpp)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${QT_LIBRARIES}
)
I don't explicitly use anything related to Qt. I installed Qt5 separately but the problem persists. Is there a separate process to link Qt to my system?
It looks like you're using at least ROS Kinetic (based on the comment where you add compile options). Most things in Kinetic depend on Qt5 instead of Qt4. Try making the following changes to your CMakeLists.txt file:
Replace this line
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
with these lines
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
set(QT_LIBRARIES Qt5::Widgets)
If this doesn't work for you, leave a comment as I have a working CMakeLists.txt file for Qt5 in Kinetic and can probably determine what else needs changed, but I think that is the minimal change to make.
If you have installed Qt seperately, you have to tell CMAKE where it can find you installation. This can be done by specifying the CMAKE_PREFIX_PATH inside the CMakeLists.txt file or in the terminal before executing cmake (ref). E.g.:
$ export CMAKE_PREFIX_PATH=/location/to/you/installation

Cannot specify link libraries for target "cv_bridge-utest" ROS compilation error

I'm trying to compile a ROS project involving catkin_make. The project involves - amongst others- a tool to convert opencv matrices to ros matrices called cv_bridge. However, when trying to compile my catkin_ws I'm getting the following error:
CMake Error at cv_bridge/test/CMakeLists.txt:7 (target_link_libraries):
Cannot specify link libraries for target "cv_bridge-utest" which is not
built by this project.
Does anyone know this error? I'm quite new to ROS, so I'm not sure how to tell ROS to compile the entire catkin_ws/src directory. In that latter folder all necessary folders should be present. There is also catkin_ws/src/cv_bridge but maybe it tries to compile the folder in the wrong order ...
I don't know what you have written in your CMakeLists. Supposing that the error lays there, you can use a CMakeLists.txt like this:
cmake_minimum_required(VERSION 2.8.3)
project(your_project)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
cv_bridge
)
find_package(OpenCV REQUIRED)
###########
## Build ##
###########
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
include
)
add_executable(executable src/your_file.cpp)
target_link_libraries(executable ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
In your package.xml add these lines:
<build_depend>opencv2</build_depend>
<build_depend>cv_bridge</build_depend>
<run_depend>opencv2</run_depend>
<run_depend>cv_bridge</run_depend>
To compile the folder you just have to go to your catkin directory and type: catkin_make
If you have built your workspace in the right way, it should compile without error.

How to include OpenCV libraries in CMake Makefile

I hope you can help me.
I have a simple CMakeLists.txt in order to build my project on Leopard 10.5.8.
I'm using CMake 2.8.1 and at the moment this is the code:
cmake_minimum_required(VERSION 2.8)
MESSAGE(STATUS "./src: Going into utils folder")
ADD_SUBDIRECTORY(utils)
MESSAGE(STATUS "./src: utils folder processed")
include_directories(${DIR}/headers)
link_directories (${DIR}/src/utils)
ADD_EXECUTABLE(sample sample.cpp)
TARGET_LINK_LIBRARIES(sample libSample ${EXTERNAL_LIBS})
INSTALL(TARGETS sample DESTINATION "./src")
MESSAGE(STATUS "./src: exiting src folder")
I need to add OpenCV libraries on my project.
When I use Eclipse I set the include path to /opt/local/include
and the libraries path to: /opt/local/lib and then I specify the libraries name such as_ opencv_core, opencv_imgproc, opencv_video.
Can you tell me how to add these information in the CMakeLists.txt file, please?
I've read some information in the official cmake FAQ but i wasn't able to solve my problem.
Please, help me.
Thanks a lot.
You need to add the library names in the TARGET_LINK_LIBRARIES command, but you need to add them without the lib prefix. For example:
include_directories(${DIR}/headers /opt/local/include)
link_directories (${DIR}/src/utils /opt/local/lib)
ADD_EXECUTABLE(sample sample.cpp)
TARGET_LINK_LIBRARIES(sample opencv_core opencv_imgproc opencv_video ${EXTERNAL_LIBS})

Resources