Use OpenCV/CMake with Clion - opencv

I wish to use CLion for my course so I follow this topic.
I updated my PATH by adding these values :
C:\Program Files\CMake\bin
C:\tools\opencv\build\install\x64\mingw\bin
(I use chocolatey)
And I added this FindOpenCV.cmake to my project and in the folder C:\Program Files\JetBrains\CLion 2020.2.1\bin\cmake\win\share\cmake-3.17\Modules.
When I try to reload my project in CLion I have :
Found OpenCV Windows Pack but it has no binaries compatible with your configuration. You should manually point CMake variable OpenCV_DIR to your build of OpenCV library.
How can I solve that ? Thanks in advance.

Related

Why doesn't CLion link my project with OpenCV for Windows?

I'm attempting to use OpenCV for Windows as supplied by opencv.org in a project I'm building with JetBrains' CLion IDE. I've installed the opencv library and configured CLion (set(OpenCV_DIR) to reference the build directory under it, but CMake issues the warning:
Found OpenCV Windows Pack but it has no binaries compatible with your configuration.
You should manually point CMake variable OpenCV_DIR to your build of OpenCV library.
I've tried some of the older distributions from opencv.org with the same results. It appears CMake is locating the OpenCV libraries, but doesn't want to use them. Why, and how do I get the OpenCV libraries to work under CLion?
The short answer is, you will probably need to build OpenCV from source in order to use it with CLion. But given the number and range of partially answered and unanswered questions here* and elsewhere on using JetBrains' CLion IDE with the OpenCV library, I think an overview is needed (my notes are from CLion 2016.3 and OpenCV 3.1, YMMV):
Though not produced by JetBrains, CMake is very central to CLion's operation. Understanding CMake therefore helps greatly in diagnosing CLion build problems. In particular CMake maintains a disk "cache" of settings which you may need to clear to incorporate changes to your environment (Tools->CMake->Reset Cache and Reload Project).
To make use of OpenCV in your build you must specify it in your project's CMakeLists.txt file. You request that CMake locate your OpenCV location and link it to your TARGET. An example of a sequence of commands from CMakeLists.txt for an executable named mushroom follows:
add_executable(mushroom ${SOURCE_FILES})
FIND_PACKAGE(OpenCV REQUIRED)
TARGET_LINK_LIBRARIES(mushroom ${OpenCV_LIBS})
(For more on FIND_PACKAGE, see CMake:How To Find Libraries.)
FIND_PACKAGE for package XXX works either by way of FindXXX.cmake files located at CMake's Modules directory, or by consulting environment variable XXXX_DIR. On my system, no FindOpenCV.cmake file was present, so I relied on the OpenCV_DIR environment variable instead. This must be set, not to the root of your OpenCV installation, but to the build folder beneath it. I used an entry in CMakeLists.txt to set this variable, e.g.:
set(OpenCV_DIR C:/Users/myacct/AppData/Local/opencv-3.0.0/build)
To link with OpenCV, CMake uses either FindOpenCV.cmake or OpenCV_DIR (see previous point above) to locate a file named OpenCVConfig.cmake. This file is generated by and ships with a particular build of OpenCV in order to document what components are present and where they are located.
Problems may occur when variable names used by OpenCVConfig.cmake conflict with those CLion has stored in its environment. In particular, if your OpenCV was built by Microsoft Visual C (MSVC), as is the Windows distribution from opencv.org, it won't work with CLion.
Because CLion's build toolchain (ControlAltS-toolchain) uses either MinGW or Cygwin, OpenCVConfig.cmake will search for OpenCV binaries under a subdirectory named mingw or cygwin and will find none because the binaries were built with MSVC (it will look in a directory like vc11 or vc12 instead). This probably means you will need to build OpenCV from source in order to use it with CLion.
Would reconfiguring OpenCVConfig.cmake to point to the MSVC binaries make this work? you may ask. Unfortunately the answer is still no, because libraries built with one compiler typically cannot be linked with another one.
OpenCVConfig.cmake or FindOpenCV.cmake likely contain diagnostic messages, but when CLion executes CMake for you, message(STATUS) calls are not displayed. To make them display, change them to message(WARNING) or message(FATAL_ERROR). But CLion 2016.3 EAP relieves this problem; see https://stackoverflow.com/a/39398373/5025060.
CLion does not indicate which .cmake script issued which diagnostics; don't assume they all come from the same script.
Hopefully this provides some general guidance on resolving CLion / CMake / OpenCV compatibility problems. Note that this does not cover compiler or linker issues; these will not appear until CMake completes its initial makefile build. Compiler or linker issues occur at a later stage and are controlled by include*(), link*() and other commands in CMakeLists.txt.
*Some related SO questions:
OpenCV Windows setup with CLion
OpenCV CLion (Cmake) linking issue - cmake reports a strange error
use OpenCV with Clion IDE on Windows
Compiling OpenCV on Windows with MinGW
Could not find module FindOpenCV.cmake ( Error in configuration process)
CMake: Of what use is find_package() if you need to specify CMAKE_MODULE_PATH anyway?

ros can't find OpenCV , the path /usr/local/

I am working with ros and OpenCV. I installed OpenCV in the default path /usr/local, but when I build programs with catkin_make in my workstation, it shows Project cv_bridge specifies /usr/include/opencv as an include dir, which is not found.
Can you show me what can I do to solve the problem? Thank you.
I recommend you use the opencv2_catkin package that automatically finds and links your package to OpenCV. As per the Readme, just add the following dependency to your own package:
<build_depend>opencv2_catkin</build_depend>
You would also need to download catkin_simple to use opencv2_catkin.
I found you said you use catkin_make, so in new version of ROS, opencv and pcl are no longer integrate in ROS, so you need find you opencv yourself. For example, in your workspace, the CMakeLists.txt file, you should add something like find_package(OpenCV REQUIRED), and add include dir and libs to your project. If you also have problems, please paste your details of errors.

Building OpenCV using CMake problems

For using CUDA, I need to compile OpenCV. I'm using CMake and OpenCV 3 sources. I do not get any errors when clicking und "Generate" in CMake. Then I compile the OpenCV.sln solution for Win64 using Visual Studio (I selected the right visual studio version). I do not get any errors when compiling.
But I do know what to include; normally, there is "opencv" and "opencv2" in the include folder. But this does not exist.
My opencv folder after compiling:
My include folder:
Includes located in sources folder, not in build folder (if you did not Build INSTALL project).

OpenCV 3.0 x64 VS2013 error LNK1104

read already some other threads about these..tried so far everything...
nothing worked. double checked everything.
using x64 system, VS13(x32) and x64 as target system (though i tried using x32 before and had
the same error)
anyways here are my links:
Debug x64
VC++ exec directory: K:\A_A_Programmierung\opencv\build\x64\vc12\bin;$(ExecutablePath)
VC++ lib: K:\A_A_Programmierung\opencv\build\x64\vc12\lib;$(LibraryPath)
C/C++: K:\A_A_Programmierung\opencv\build\include;%(AdditionalIncludeDirectories)
Linker: Target Computer: MachineX64 (/MACHINE:X64)
additional dependencies:
opencv_calib3d300d.lib;opencv_core300d.lib;opencv_features2d300d.lib;opencv_flann300d.lib;opencv_highgui300d.lib;opencv_imgcodecs300d.lib;opencv_imgproc300d.lib;opencv_ml300d.lib;opencv_objdetect300d.lib;opencv_photo300d.lib;opencv_shape300d.lib;opencv_stitching300d.lib;opencv_superres300d.lib;opencv_ts300d.lib;opencv_video300d.lib;opencv_videoio300d.lib;opencv_videostab300d.lib;%(AdditionalDependencies)
Additional lib. directory:
K:\A_A_Programmierung\opencv\build\x64\vc12\lib;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib;%(AdditionalLibraryDirectories)
also checked some other settings mentioned in other threads!
and did set the enviroment variable as mentioned in a tut and also ran VS13 as admin
any help?
ok fixed it myself...
you have to add the files of opencv 3.0 under opencv\build\x86\vc12\lib
for the linker input. (see additional dependencies) which isnt the whole list anymore...
list on the official tutorial is not up to date!
Try using $(OPENCV_DIR)\staticlib instead of $(OPENCV_DIR)\lib.

CONFLICT WITH INSTALLING OPENCV 2.4.2

I downloaded OpenCV-2.4.2 and I couldn't find any exe(auto run) file there.How ever I extracted that in to my C:\ directory and followed the following process in this video>>
https://www.youtube.com/watch?v=cgo0UitHfp8&feature=plcp
I have VS 2008 version. According to the video first I Added OpenCV to system variables and next build Visual Studio project. Added all the libraries and completed according to the video.
But When I debug my project it says>>
The application has failed to start because tbb_debug.dll was not found.
So;
1)Are there any wrong in my installation or this video?
2)Did I completed the installation process correct?
I must be thankful to u if u reply this soon.
Thank U
You are missing tbb_debug.dll (or it's not in your path)
If you built (or downloaded) opencv with TBB enabled then you need to install tbb and then put tbb.dll and tbb_debug.dll on the path (eg. copy to the opencv bin folder)

Resources