情况:
我有一台装有 Windows 版 OpenCV 的 Windows 7 机器。 我的 OpenCV C++ 项目在 Visual Studio 2010 中运行良好。
我想运行我现有的 OpenCV C++ 项目以在 Raspberry Pi 和其他 Linux 机器上运行。
麻烦
作为第一步,我尝试在我的 Windows 机器上的 Cygwin 上使用 GCC 编译我的 .cpp 和 .h 文件。为此,我尝试使用 Cygwin 的 CMake 包,但是 CMake 给出了找不到 OpenCV 包的错误。 (错误在下面列出)。
问题:
- 我是否需要单独为 Cygwin 安装 OpenCV 包 CMake 才能工作?
- 有没有办法使用我现有的 OpenCV for Win 与 CMake 一起工作?
- 需要设置哪些环境变量?
(目前只有一个变量OPENCV_DIR设置为C:/opencv/build)
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.4)
PROJECT (testProj)
find_package(OpenCV REQUIRED )
set( NAME_SRC
src/main.cpp
src/imgProcess.cpp
)
set( NAME_HEADERS
include/imgProcess.h
)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )
link_directories( ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( testProj ${NAME_SRC} ${NAME_HEADERS} )
target_link_libraries( test ${OpenCV_LIBS} )
cmake 错误
$ cmake .
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- 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++.exe
-- Check for working CXX compiler: /usr/bin/c++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
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.
-- Configuring incomplete, errors occurred!
See also "/cygdrive/c/Work/Project/cmaketest/CMakeFiles/CMakeOutput.log".
最佳答案
变量应该被称为OpenCV_DIR
,它的大小写必须与find_package(OpenCV REQUIRED)
中的大小写相同。
关于c++ - 在 Cygwin 上使用 CMake 编译 OpenCV 项目,为 Windows 安装 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33749216/