I wrote a CMakeLists.txt
for a project in C++, which uses OpenCV libraries. When I try to create the project using cmake, I get the next configuration problem:
CMake Error at CMakeLists.txt:15 (find_package):
Could not find module FindOpenCV.cmake or a configuration file for package
OpenCV.
Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
directory containing a CMake configuration file for OpenCV. The file will
have one of the following names:
OpenCVConfig.cmake
opencv-config.cmake
The fact is that I have an environment variable for the path which I use in Visual Studio with no problems. If I don't include OpenCV, then I can configure and generate with no problem, but I need to solve the problem. I don't understand why cmake cannot find the OpenCV path or how to fix it.
I also used the recommendations mentioned in this link: FindOpenCV.cmake
Does anybody had this problem too?
find / -name "OpenCVConfig.cmake"
export OpenCV_DIR=/path/found/above
#include #include
not original cv.h
The error you're seeing is that CMake cannot find a FindOpenCV.cmake file, because cmake doesn't include one out of the box. Therefore you need to find one and put it where cmake can find it:
You can find a good start here. If you're feeling adventurous you can also write your own.
Then add it somewhere in your project and adjust CMAKE_MODULE_PATH so that cmake can find it.
e.g., if you have
Then you should do a
In your CMakeLists.txt file before you do a find_package(OpenCV)
I faced the same error. In my case this "OpenCVConfig.cmake" file is located in /usr/local/share/OpenCV. In CMakeLists.txt add the line
set(OpenCV_DIR /usr/local/share/OpenCV)
as suggested by the error message.
Another possibility is to denote where you can find
OpenCV_DIR
in the CMakeLists.txt file. For example, the following cmake scripts work for me:Just to remind that you should set
OpenCV_STATIC
andOpenCV_CUDA
as well before you invokeOpenCVConfig.cmake
. In my case the built library is static library that does not use CUDA.I had the same error, I use windows. I add "C:\opencv\build" (opencv folder) to path at the control pannel. So, That's Ok!!