Ask Your Question
0

Opencv in ROS: fatal error: opencv3/opencv.hpp: No such file or directory compilation terminated.

asked 2016-10-05 07:31:58 -0600

patrchri gravatar image

updated 2016-10-05 11:15:05 -0600

EDITED:

Hello,

I just started using opencv with ROS and I am trying to to write a program using the default opencv3, which comes with ROS Kinetic. I have the following inclusions in my .cpp file:

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv3/opencv.hpp>
#include <opencv3/imgproc/imgproc.hpp>
#include <opencv3/highgui/highgui.hpp>

the following package.xml:

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>sensor_msgs</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>cv_bridge</build_depend>
  <build_depend>image_transport</build_depend>
  <build_depend>image_geometry</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>opencv3</build_depend>
  <run_depend>sensor_msgs</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>cv_bridge</run_depend>
  <run_depend>image_transport</run_depend>
  <run_depend>image_geometry</run_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>opencv3</run_depend>

and the following CMakeLists.txt file:

    cmake_minimum_required(VERSION 2.8.3)
    project(kinect_vision)

    ## Find catkin macros and libraries
    ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
    ## is used, also find other catkin packages
    find_package(catkin REQUIRED COMPONENTS
      sensor_msgs
      std_msgs
      cv_bridge
      image_transport
      image_geometry
      roscpp
    )

   find_package(OpenCV REQUIRED) ##I also tried it without REQUIRED

    catkin_package(
      INCLUDE_DIRS include
    #  LIBRARIES kinect_vision
      CATKIN_DEPENDS cv_bridge image_transport image_geometry roscpp
      DEPENDS OpenCV
    )

    include_directories(
      ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}
    )


     add_executable(kinect_vision_node src/kinect_vision_node.cpp)


     target_link_libraries(kinect_vision_node
       ${OpenCV_LIBRARIES} ${catkin_LIBRARIES}
     )

I get the following errors while trying to catkin_make my workspace:

/home/legged/vision_ws/src/kinect_vision/src/kinect_vision_node.cpp:5:30: fatal error: opencv3/opencv.hpp: No such file or directory
compilation terminated.
kinect_vision/CMakeFiles/kinect_vision_node.dir/build.make:62: recipe for target 'kinect_vision/CMakeFiles/kinect_vision_node.dir/src/kinect_vision_node.cpp.o' failed
make[2]: *** [kinect_vision/CMakeFiles/kinect_vision_node.dir/src/kinect_vision_node.cpp.o] Error 1
CMakeFiles/Makefile2:385: recipe for target 'kinect_vision/CMakeFiles/kinect_vision_node.dir/all' failed
make[1]: *** [kinect_vision/CMakeFiles/kinect_vision_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed

Any ideas how can I fix this?

Thanks for your answers and for your time in advance,

Chris

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-10-05 08:43:41 -0600

rbbg gravatar image

updated 2016-10-06 23:44:19 -0600

Hi Chris,

As the error indications, your compiler cannot find OpenCV. You are probably missing some things in your CMakeLists.txt, do you require openCV?

find_package(OpenCV REQUIRED)

There is some information on how to use OpenCV3 on the wiki located here it links to the transition guide that can be found here, which explains that the layout of the header files has changed a little but in any case they are still under opencv2 for backwards compatibility. Update the headers to opencv2 and check if it affects the modules in your include and update those as well.

Good luck!

edit flag offensive delete link more

Comments

I edited my question after your suggestion according to the example's package.xml and CMakeLists.txt. The issue still remains.

patrchri gravatar image patrchri  ( 2016-10-05 09:05:48 -0600 )edit
1

Reading the OpenCV transition guide it seems that the header locations are under opencv2 instead of opencv3 for backwards compatibility. If you update the includes to the right location the compiler should be able to find them.

rbbg gravatar image rbbg  ( 2016-10-05 14:31:35 -0600 )edit

I will test it tomorrow at the lab's computer. Thank you for the suggestion again, I hope it will work.

patrchri gravatar image patrchri  ( 2016-10-05 15:02:54 -0600 )edit

Thanks a lot rbbg. Your comment made the error disappear and a sample code, I used, worked. Try to edit your answer so I can accept it :)

Thanks again,

Chris

patrchri gravatar image patrchri  ( 2016-10-06 17:04:10 -0600 )edit

@patrchri, can you post the header code and CMakeLists.txt that you eventually got to work?

matwilso gravatar image matwilso  ( 2017-06-19 09:06:07 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-10-05 07:31:58 -0600

Seen: 4,643 times

Last updated: Oct 06 '16