Steward
分享是一種喜悅、更是一種幸福
程式語言 - OpenCV - Image Processing - Gray Color
參考資訊:
https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <stdio.h> #include <opencv2/opencv.hpp> using namespace cv ; int main ( int argc, char **argv) { Mat original, gray; original = imread ( "main.png" , 1); if (!original. data ) { printf ( "failed to load image\n" ); return -1; } cvtColor (original, gray, COLOR_BGR2GRAY ); namedWindow ( "show original" , WINDOW_AUTOSIZE ); imshow ( "show original" , original); namedWindow ( "show gray" , WINDOW_AUTOSIZE ); imshow ( "show gray" , gray); waitKey (0); return 0; } |
CMakeLists.txt
cmake_minimum_required(VERSION 2.8) project(main) find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) add_executable(main main.cpp) target_link_libraries(main ${OpenCV_LIBS})
編譯並且執行
$ cmake . $ make $ ./main
完成