ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

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



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:



and the following CMakeLists.txt file:

    cmake_minimum_required(VERSION 2.8.3)

    ## 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

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

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

      ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}

     add_executable(kinect_vision_node src/kinect_vision_node.cpp)

       ${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,


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

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


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

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,


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

Question Tools

1 follower


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

Seen: 5,477 times

Last updated: Oct 06 '16