Home:ALL Converter>Compiling an OpenCV project using CMake on Cygwin, with OpenCV installed for Windows

Compiling an OpenCV project using CMake on Cygwin, with OpenCV installed for Windows

Ask Time:2015-11-17T12:32:35         Author:kernelman

Json Formatter

Situation:

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

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

Trouble

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).

Question:

  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 error

$ 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".

Author:kernelman,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33749216/compiling-an-opencv-project-using-cmake-on-cygwin-with-opencv-installed-for-win
kernelman :

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).\nHad to tweak my CMakeLists.txt a little but it compiled well. \n\n##### CMakeLists.txt ########\ncmake_minimum_required(VERSION 2.8.4) \nPROJECT (test)\nfind_package(OpenCV REQUIRED )\n\nset( NAME_SRC\n src/main.cpp \n src/mytest.cpp \n)\n\nset( NAME_HEADERS \n include/mytest.hpp\n)\n\nset(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)\nadd_executable( test ${NAME_SRC} ${NAME_HEADERS} )\ninclude_directories(/usr/include /usr/include/opencv2 /usr/include/opencv ${CMAKE_CURRENT_SOURCE_DIR}/include)\nlink_directories(/usr/lib ${CMAKE_BINARY_DIR}/bin)\ntarget_link_libraries(test opencv_core opencv_highgui opencv_imgproc)\n\n\n(Now, I have totally different trouble of runtime error : Gtk-WARNING **: cannot open display, but its another story of not having XServer on Cygwin)",
2015-11-22T08:50:58
usr1234567 :

The variable should be called OpenCV_DIR, it must have the same capitalization as in find_package(OpenCV REQUIRED).",
2015-11-17T06:10:39
yy