#include <stdio.h> #include <opencv2/opencv.hpp> using namespace cv; int main(int argc, char **argv ) { if ( !argc[2] ) { printf("usage: DisplayImage <Image_Path>\n"); return -1; } Mat image; image = imread( argv[1], 1 ); if ( !image.data ) { printf("No image data \n"); return -1; } namedWindow("DisplayImage", WINDOW_AUTOSIZE ); imshow("DisplayImage", image); waitKey(0); return 0; }
2.編寫一個 CMakeLists.txt 檔,程式碼如下:
cmake_minimum_required(VERSION 2.8) project( DisplayImage ) find_package( OpenCV REQUIRED ) add_executable( DisplayImage DisplayImage.cpp ) target_link_libraries( DisplayImage ${OpenCV_LIBS} )
3.將1、2點的檔案和任意圖檔(XXX.png)放在同一個目錄 displayimage 底下,執行 cmake .,之後執行 make :
$ cmake .
$ make
執行最後會顯示下列訊息:
...
-- Build files have been written to: /home/<username>/.../DisplayImage
4.會出現一個叫 DisplayImage 的可執行檔,並執行下列指令:
$ ./DisplayImage XXX.png
即可用opencV 顯示圖片
參考資料:
www.google.com
http://www.bogotobogo.com/OpenCV/opencv_3_tutorial_ubuntu14_install_cmake.php
http://blog.csdn.net/poem_qianmo/article/details/20537737
沒有留言:
張貼留言