Advertisemen
For this tutorial, I will be using Clion because it is cross-platform so whatever I am doing would be same in all the platforms(Windows, Mac and Linux).
Go ahead, download Opencv and install or use homebrew to install it using - brew install opencv
Now create new project in Clion
In the beginning, your project looks like this:
- debug folder
- cmake file
- main.cpp
Ok now, drag and drop one image into debug folder and type followings in your cmake file. Make sure to match the highlighted codes with your project and save.
cmake_minimum_required(VERSION 3.6)Go to main.cpp file and import some opencv libraries.
project(opencvTutorial)
set(CMAKE_CXX_STANDARD 11)
#set(SOURCE_FILES main.cpp)
set(SOURCE_FILES main.cpp)
find_package( OpenCV 3.1 REQUIRED )
# add opencv include directories to the project
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(OpencvTutorial ${SOURCE_FILES})
# link libraries
target_link_libraries(OpencvTutorial ${OpenCV_LIBS})
- opencv2/core/core.hpp
- opencv2/highgui/highgui.hpp
Inside main() function, delete everything and add following :
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main()
{
cv::Mat image; // 1
image = cv::imread("binary.jpg"); // 2
cv::namedWindow("Aarlangdi Original Image"); //3
cv::imshow("Aarlangdi Original Image", image); // 4
cv::waitKey(0); //5
}
I hope you can see commented out number on each line.
1 - Creating variable
2 - Loading image that we dropped on debug folder
3 - Naming the window
4 - Using window with the name to display image
5 - This keeps the window open until user cancels it.
And make sure to change to build to your project.
Now if you hit build, you should see the image with window you named it.
Advertisemen
Tidak ada komentar:
Posting Komentar