0

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} )
mahmood
  • 23,197
  • 49
  • 147
  • 242
  • How have you installed OpenCV on your machine? and also attach the contents of your `CMakeLists.txt` – ZdaR Jun 04 '17 at 14:59
  • I followed the instructions. http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html – mahmood Jun 04 '17 at 15:17
  • Try with this [link](http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/) – ZdaR Jun 04 '17 at 15:28
  • I don't think my problem is related to python. I just want to know how can I apply the suggestions made by cmake. – mahmood Jun 04 '17 at 15:52
  • The link contained installs OpeCV from source and the python part can be simply ignored. – ZdaR Jun 04 '17 at 16:08

1 Answers1

1

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:

  1. 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/<...>
    
  2. 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.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153