Loading an image for processing in Opencv - C++

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)
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})
Go to main.cpp file and import some opencv libraries.
- 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

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D