I\'m actually looking for a way to create apps with OpenCV with Clion from JetBrains.
I\'ve installed OpenCV with Choco, so I have all the stuff in C:\\opencv
<First of all, you need CMake.
Then you need a compiler of your choise (MinGW, Visual Studio, ...).
C:\opencv
(or a folder of your choice)CMake
and select source (directory of 2.) and build for example C:\opencv\mingw-build
or C:\opencv\vs-x64-build
. Choose one accoring your configuration.Configure
and select the generator according to you compiler. MinGW Makefiles
in case of MingGW or Visual Studio ...
if you are using Visual Studio and so on ...Configure
again. When everything is white click Generate
else edit the red fields.cmd
and dir to build directory of 3.mingw32-make
(or mingw64-make
) or build the BUILD_ALL
project from the generated solution in Visual Studio if your choosen compiler is MSVC.mingw32-make install
(or mingw64-make install
). If you've choosen Visual Studio you need to build the INSTALL
project.PATH
add C:\opencv\mingw-build\install\x86\mingw\bin
project-root/cmake/
.CMakeLists.txt:
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Where to find CMake modules and OpenCV
set(OpenCV_DIR "C:\\opencv\\mingw-build\\install")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test_cv main.cpp)
# add libs you need
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
# linking
target_link_libraries(test_cv ${OpenCV_LIBS})
main.cpp:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main(int argc, char** argv)
{
if(argc != 2)
{
std::cout << "Usage: display_image ImageToLoadAndDisplay" << std::endl;
return -1;
}
cv::Mat frame;
frame = cv::imread(argv[1], IMREAD_COLOR); // Read the file
if(!frame) // Check for invalid input
{
std::cout << "Could not open or find the frame" << std::endl;
return -1;
}
cv::namedWindow("Window", WINDOW_AUTOSIZE); // Create a window for display.
cv::imshow("Window", frame); // Show our image inside it.
cv::waitKey(0); // Wait for a keystroke in the window
return 0;
}
Build and run main.cpp
.
All Paths depend on the setup you make in 2. and 3. You can change them if you like.
UPDATE 1: I updated the post for using a compiler of you choice.
SUGGESTION: Using a package manager like Conan makes life much easier.
I just want to add one more thing in the answer of daB0bby. Few Min-GW Compilers do not support C++ Version 11 or later. This version is required for thread in OpenCV. So I will suggest using TDM-GCC Compiler instead of MinGW Compiler. Install this compiler and set path C:\TDM-GCC-64\bin to the system's environmental variable.