Could not find module FindOpenCV.cmake ( Error in

2020-01-27 02:33发布

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?

标签: opencv cmake
12条回答
Deceive 欺骗
2楼-- · 2020-01-27 02:45

find / -name "OpenCVConfig.cmake"

export OpenCV_DIR=/path/found/above

查看更多
孤傲高冷的网名
3楼-- · 2020-01-27 02:48
  1. apt-get install libopencv-dev
  2. export OpenCV_DIR=/usr/share/OpenCV
  3. the header of cpp file should contain: #include #include "opencv2/highgui/highgui.hpp"

#include #include

not original cv.h

查看更多
来,给爷笑一个
4楼-- · 2020-01-27 02:49

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

CMakeLists.txt
cmake-modules/FindOpenCV.cmake

Then you should do a

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)

In your CMakeLists.txt file before you do a find_package(OpenCV)

查看更多
Summer. ? 凉城
5楼-- · 2020-01-27 02:51

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.

查看更多
We Are One
6楼-- · 2020-01-27 02:54

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:

cmake_minimum_required(VERSION 2.8)

project(performance_test)

set(OpenCV_STATIC ON)
set(OpenCV_CUDA OFF)
set(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../install")

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

link_directories(${OpenCV_LIB_DIR})

file(GLOB my_source_files ./src/*)

add_executable( performance_test ${my_source_files})

target_link_libraries(performance_test ${OpenCV_LIBS})

Just to remind that you should set OpenCV_STATIC and OpenCV_CUDA as well before you invoke OpenCVConfig.cmake. In my case the built library is static library that does not use CUDA.

查看更多
混吃等死
7楼-- · 2020-01-27 03:00

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

查看更多
登录 后发表回答