1
votes

To start off, I know this question has too many duplicates, but none of them work in my case.

I have installed OpenCV 2.4.13.2 on my Ubuntu 16.04 system. I followed the installation instructions outlined here: http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/. As per step#6 mentioned therein, I could confirm that OpenCV was installed successfully.

However, when I try to run cmake .. while building this project: https://github.com/andrewssobral/vehicle_detection_haarcascades/, I get an error saying:

Found OpenCV Windows Pack but it has not binaries compatible with your configuration.

You should manually point CMake variable OpenCV_DIR to your build of OpenCV library. Call Stack (most recent call first): CMakeLists.txt:5 (find_package)

CMake Error at CMakeLists.txt:5 (find_package): Found package configuration file:

/home/abhishek/opencv-2.4.13.2/cmake/OpenCVConfig.cmake

but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be NOT FOUND.

-- Configuring incomplete, errors occurred! See also "/home/abhishek/opencv-2.4.13.2/vehicle_detection_haarcascades/build/CMakeFiles/CMakeOutput.log".

As mentioned in other SO answers, I tried deleting the cache files, reinstalling, reinstalling in a different directory, etc., but none of them works. So, how can I overcome this error? I am going to use this vehicle detection project (developed majorly in C++) in an academic setting and I would greatly appreciate your help!

4
You need to run cmake .. with other params like CMAKE_BUILD_TYPE, CMAKE_INSTALL_PREFIX - ZdaR
Have you tried to do what cmake tells you to do? You should manually point CMake variable OpenCV_DIR to your build of OpenCV library. - nega
If you had this problem when working with Android projects, take care of your minSdkVersion. - Summer Sun

4 Answers

3
votes

Some background information on when and how OpenCV_FOUND is set to TRUE or FALSE.

Note: The code of OpenCVConfig.cmake does vary through the OpenCV versions but the general functionality more or less kept the same. I've reviewed version 3.2.0 and crosschecked against version 2.4.10 for this answer:

  1. Those things are handled in the find_package_handle_standard_args() call in OpenCVConfig.cmake

    find_package_handle_standard_args(OpenCV REQUIRED_VARS OpenCV_INSTALL_PATH
                                      VERSION_VAR OpenCV_VERSION ${_OpenCV_FPHSA_ARGS})
    

    If one of the REQUIRED_VARS could not be determined (is not set) or the version given in VERSION_VAR does not match, then OpenCV_FOUND is set to FALSE.

  2. The OpenCV_INSTALL_PATH is directly put in the CMake config during the build:

    get_filename_component(OpenCV_INSTALL_PATH "${OpenCV_CONFIG_PATH}/@OpenCV_INSTALL_PATH_RELATIVE_CONFIGCMAKE@" REALPATH) 
    

    So this is unlikely to fail, if the config script itself was found.

    But be aware that absolute paths could be in the resulting config file. So don't move it around or manually install it. So you should check /home/abhishek/opencv-2.4.13.2/cmake/OpenCVConfig.cmake for invalid/not matching paths.

  3. The OpenCV_VERSION is checked against whatever is given in the project's find_package(OpenCV [version] ...) call as version.

    But vehicle_detection_haarcascades/CMakeLists.txt doesn`t specify a specific version:

    find_package(OpenCV REQUIRED)
    
  4. The ${_OpenCV_FPHSA_ARGS} will put a HANDLE_COMPONENTS there for CMake version >= 2.8.8. This would additionally check the COMPONENTS given in a find_package(OpenCV COMPONENTS ...) call.

    But that's also not applicable here (see above).

  5. Last the find_package() call itself can set OpenCV_FOUND to FALSE if it didn't find the necessary configuration files.

    But this seems not to be the case here since your error names the path where it did find the config script.

References

3
votes

After wasting hours on this problem several times, I've decided to post what solved my problem for future reference, in case I forget again 3 months later.

Suppose the OpenCV installation is correct, I didn't need to manually set $OpenCV_FOUND, I didn't need to touch any files in the OpenCV installation folder (/home/.../opencv-3.1.0/{build,cmake}/), the only things I needed to do were:

  1. set $OpenCV_DIR in my 'CMakeLists.txt' by
    set(OpenCV_DIR "/usr/local/share/OpenCV/") or
    set(OpenCV_DIR "/home/.../opencv-3.1.0/build/")
  2. Delete the 'build' folder in the application that I was developing, create a new 'build' folder, and run cmake .. etc. inside it.

    This problem usually happens when I've messed around with the "CMakeLists.txt" that contains the FIND_PACKAGE( OpenCV REQUIRED ) statement.
1
votes

Since you're using Ubuntu 16.04, have you tried the packaged OpenCV? I don't have 16.04 handy, but detection works fine with 15.10.

[zinc:~/q] lsb_release -sa
No LSB modules are available.
Ubuntu
Ubuntu 15.10
15.10
wily
[zinc:~/q] dpkg --get-selections cmake libopencv-dev
cmake                       install
libopencv-dev                   install
[zinc:~/q] cat CMakeLists.txt 
cmake_minimum_required(VERSION 3.7)

include(CMakePrintHelpers)
find_package(OpenCV REQUIRED)
cmake_print_variables(OpenCV_LIBS)
[zinc:~/q] cmake .
-- The C compiler identification is GNU 5.2.1
-- The CXX compiler identification is GNU 5.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- OpenCV_LIBS="opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_ocl;opencv_objdetect;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d"
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nega/q
[zinc:~/q] 
1
votes

If everything goes well until step 6 with no errors, i think the problem that might be causing this error to show is the fact that you are not working on the virtual environment so I think this should help : open terminal -> type: workon cv -> the execute the cmake