1

I made the ~/.compile_opencv.sh as given https://help.ubuntu.com/community/OpenCV on this website and then I made this file opencvtest.cpp with the following contents . The image path is a valid path .

#include <opencv2/highgui/highgui.hpp>
using namespace cv;

int main() {
  Mat img = imread("/home/AbKDs/Desktop/friends.jpg",CV_LOAD_IMAGE_COLOR);
  imshow("opencvtest",img);
  waitKey(0);

  return 0;
}

I have created the alias opencv="~/.compile_opencv.sh". But when I run it shows the following error .

bash: /home/AbKDs/.compile_opencv.sh: Permission denied

Instead of this I tried the whole command but even then it shows fatal error .

opencvtest.cpp:1:39: fatal error: opencv2/highgui/highgui.hpp: No such file or directory
 #include <opencv2/highgui/highgui.hpp>
                                       ^
compilation terminated.

Please help . Thanks in advance

abkds
  • 595
  • 2
  • 6
  • 10

1 Answers1

7

Well, the error message is pretty clear, right?

fatal error: opencv2/highgui/highgui.hpp: No such file or directory

You'll have to install the development package of opencv-highgui (libopencv-highgui-dev) in order to install the required opencv2/highgui/highgui.hpp header file.

Rather than providing you fish, here's teaching you how to fish (similar to https://askubuntu.com/a/219539/88802).

  1. Determine the missing file. In this case: highgui.hpp

  2. Search for what package provides the file, e.g. via http://packages.ubuntu.com or using apt-file.

    In this case: http://packages.ubuntu.com/search?searchon=contents&keywords=highgui.hpp&mode=exactfilename&suite=trusty&arch=any

  3. Install the package providing the file. In this case:

    sudo apt-get install libopencv-highgui-dev
    
  4. Recompile.

gertvdijk
  • 67,947
  • Shouldn't the libraries be installed when I installed opencv – abkds Aug 27 '14 at 09:47
  • so in this case whenever I encounter such errors I will have to repeat this process for that lib ? – abkds Aug 27 '14 at 09:50
  • 2
    By installing opencv, you install runtime libraries, but not the header files for development. In reglar use of OpenCV (by applications) you don't compile anything so you don't need to access any header files. You're developing with OpenCV (linking against) and then you need it. When built and distributed as a binary you don't need header files on the target system. And this holds for all general libraries for which you can use this 'recipe'. – gertvdijk Aug 27 '14 at 10:32