1

I have installed OpenCV in windows (from source)

Now I want to try a test so I have the following CMakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(opencvGPUtest_youtube VERSION 0.1.0)

include(CTest)
enable_testing()

find_package(OpenCV REQUIRED )
include_directories(( ${OpenCV_INCLUDE_DIRS}))

add_executable(opencvGPUtest_youtube main.cpp)

target_link_libraries(opencvGPUtest_youtube ${OpenCV_LIBS})

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

However when I do cmake.. from a build folder I got

CMake Error at CMakeLists.txt:13 (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.

I have tried editing the CMakeLists.txt file to include the directory of Opencv as in

find_package(OpenCV REQUIRED PATH C:/Users/theuser/Path/To/MyOpenCVInstallation/build/install/x64/vc16/lib

or

find_package(OpenCV REQUIRED PATH C:/Users/theuser/Path/To/MyOpenCVInstallation/build/win-install/x64/vc16/lib

but still it cannot find OpenCV

I have also tried the -DOpenCV_DIR option, with no result

How can I make it recognize OpenCV?


EDIT:

When I specify OpenCV_DIR to MyOpenCVInstallation/build/install/x64/vc16/lib the error changes to

CMake Error at C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenCV (missing: PATH
  C:/Users/user/Path/To/MyOpenCVInstallation/build/install/) (found
  version "4.5.2")
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  C:/Users/user/path/to/MyOpenCVInstallation/build/install/x64/vc16/lib/OpenCVConfig.cmake:410 (find_package_handle_standard_args)
  CMakeLists.txt:13 (find_package)

EDIT2:

Turns out that I had to use

find_package(OpenCV REQUIRED PATHS C:/Users/theuser/Path/To/MyOpenCVInstallation/build/install/x64/vc16/lib

With this it seems that the cmake goes ok.

However usually at this point (in ubuntu) I run make but in windows I am supposed to use CtrlF5 from VSCode

now I got the output

-------------------------------------------------------------------
You may only use the C/C++ Extension for Visual Studio Code
with Visual Studio Code, Visual Studio or Visual Studio for Mac
software to help you develop and test your applications.
-------------------------------------------------------------------
Loaded 'C:\Users\aliag\DiskD\MyStudy\MyOpenCVInstallation\opencvgpu_test_youtube\build\Debug\opencvGPUtest_youtube.exe'. Symbols loaded.
Loaded 'C:\Windows\System32\ntdll.dll'. 
Loaded 'C:\Windows\System32\kernel32.dll'. 
Loaded 'C:\Windows\System32\KernelBase.dll'. 
Loaded 'C:\Windows\System32\apphelp.dll'. 
Loaded 'C:\Windows\System32\vcruntime140_1d.dll'. 
Loaded 'C:\Windows\System32\vcruntime140d.dll'. 
Loaded 'C:\Windows\System32\msvcp140d.dll'. 
The program '[1112] opencvGPUtest_youtube.exe' has exited with code -1073741515 (0xc0000135).

So I suppose that is matter of a different question?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • 1
    So what exact path to the file `OpenCVConfig.cmake` under your OpenCV installation? Use directory with that file as a value for `OpenCV_DIR` variable. – Tsyvarev May 29 '21 at 15:02
  • I made a search for `OpenCVConfig.cmake` and I got four(4) files. The paths are: C:....\MyOpenCVInstallation\build\win-install\x64\vc16\lib, then another one with install\x64\vc16\lib and the other two are just until win-install or install . Which one should I use – KansaiRobot May 29 '21 at 15:19
  • Probably the one in the install folder however it likely will work in either case. CMake will use a package from the build folder or the install folder. I usually don't build the install target and instead use the build folder. Depending on the package there may be an advantage to the INSTALL that the headers may be combined in one folder instead of scattered. – drescherjm May 29 '21 at 15:22
  • "I have installed OpenCV in windows (from source)" - You probably used CMake for install OpenCV. In that case you have specified **build directory** and **installation prefix**. The proper `OpenCVConfig.cmake` is located somewhere under **installation prefix**. – Tsyvarev May 29 '21 at 15:24
  • Yes, I did use CMake to install OpenCV. I indeed specified a build directory. What do you mean by "installation prefix"? My command was `cmake --build "C:\Users\user\path\to\MyOpenCVInstallation\build" --target INSTALL --config Release` – KansaiRobot May 29 '21 at 15:30
  • 2
    There is no such `PATH` option for the [find_package](https://cmake.org/cmake/help/latest/command/find_package.html). You probably mean `PATHS` option. But since you have specified `OpenCV_DIR` variable, you don't need that option. – Tsyvarev May 29 '21 at 15:34
  • "installation prefix" is what you have specified in `CMAKE_INSTALL_PREFIX` variable when **configured** OpenCV. `cmake --build` runs **building** process, which occurs after after configuration. – Tsyvarev May 29 '21 at 15:36
  • If you are using msvc you will want to build the debug version as well. I assume you at some point would want to debug your own application. – drescherjm May 29 '21 at 15:37
  • 1
    The error code `0xc0000135` means that some of your dll-libraries are not listed in the `PATH` environment variable. See e.g. https://stackoverflow.com/questions/40273663/process-finished-with-exit-code-1073741515-0xc0000135-after-trying-to-run-sam – Tsyvarev May 29 '21 at 16:09

0 Answers0