使用Cygwin上的CMake编译OpenCV项目,为Windows安装OpenCV [英] Compiling an OpenCV project using CMake on Cygwin, with OpenCV installed for Windows

查看:3582
本文介绍了使用Cygwin上的CMake编译OpenCV项目,为Windows安装OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台安装了 OpenCV for Windows 的Windows 7计算机。
我的OpenCV C ++项目在Visual Studio 2010中工作良好。

I have a Windows 7 machine with OpenCV for Windows installed on it. My OpenCV C++ projects work fine with Visual Studio 2010.

我想运行我现有的OpenCV C ++项目,在Raspberry Pi和其他Linux机器上运行。

I want to run my existing OpenCV C++ projects to run on Raspberry Pi and on other Linux machines.

作为第一步,我试图编译我的.cpp& .h文件,在Windows计算机上使用 Cygwin GCC 。为此,我试图使用 CMake package for Cygwin ,但 CMake 会显示找不到OpenCV包的错误。 (错误如下所示)。

As a first step, I am trying to compile my .cpp & .h files using GCC on Cygwin on my Windows Machine. For this purpose I am trying to use CMake package for Cygwin, but CMake gives error that it cannot find OpenCV package. (error is listed below).



  1. 是否可以使用我现有的 OpenCV for Win 来使用CMake?

  2. 需要设置哪些环境变量?

    (目前只有一个变量OPENCV_DIR设置为C:/ opencv / build)

  1. Do i need to install OpenCV package for Cygwin separately for CMake to work ?
  2. Is there a way to using my existing OpenCV for Win to work with CMake ?
  3. What environment variables need to be set ?
    (Currently only a variable OPENCV_DIR is set to 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".


推荐答案

使用Cygwin端口的Cygwin的OpenCV包。 (没有任何src或需要任何构建,只是简单的安装)。

有一点调整我的 CMakeLists.txt 一点,但编译好。

As @berak, stated in the comment, I installed OpenCV Package for Cygwin using Cygwin Ports. (Without any src or requiring any build, simple install only).
Had to tweak my CMakeLists.txt a little but it compiled well.

##### CMakeLists.txt ########
cmake_minimum_required(VERSION 2.8.4) 
PROJECT (test)
find_package(OpenCV REQUIRED )

set( NAME_SRC
    src/main.cpp    
    src/mytest.cpp    
)

set( NAME_HEADERS       
    include/mytest.hpp
)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( test ${NAME_SRC} ${NAME_HEADERS} )
include_directories(/usr/include /usr/include/opencv2 /usr/include/opencv ${CMAKE_CURRENT_SOURCE_DIR}/include)
link_directories(/usr/lib ${CMAKE_BINARY_DIR}/bin)
target_link_libraries(test opencv_core opencv_highgui opencv_imgproc)

我有完全不同的运行时错误的麻烦: Gtk-WARNING **:无法打开显示,但它的另一个故事没有XServer Cygwin)

(Now, I have totally different trouble of runtime error : Gtk-WARNING **: cannot open display, but its another story of not having XServer on Cygwin)

这篇关于使用Cygwin上的CMake编译OpenCV项目,为Windows安装OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆