1. 程式人生 > >影象腐蝕-ubnutu16.04系統下

影象腐蝕-ubnutu16.04系統下

  • 檔案結構
[email protected]:~/opencv_test/1$ tree -L 1
.
├── build
├── CMakeLists.txt
├── main.cpp
└── ubuntu.png
  • main.cpp檔案
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv; int main( int argc,char** argv) { Mat image = cv::imread( argv[1] ); Mat element = getStructuringElement(MORPH_RECT,Size(15,15)); Mat dstImage; erode(image,dstImage,element); //corrode imshow("fushi",dstImage); waitKey(0); return 0; }
  • CMakeLists.txt檔案
cmake_minimum_required( VERSION 2.8 )
project( imageBasics )

# 新增c++ 11標準支援
set( CMAKE_CXX_FLAGS "-std=c++11" )

# 尋找OpenCV庫
find_package( OpenCV REQUIRED )
 # 新增標頭檔案
include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable( corrode main.cpp )
# 連結OpenCV庫
target_link_libraries( corrode ${OpenCV_LIBS} )
  • 編譯執行
[email protected]:~/opencv_test/1$ mkdir build
[email protected]:~/opencv_test/1$ cd build
[email protected]:~/opencv_test/1/build$ cmake ..
[email protected]:~/opencv_test/1/build$ make
[email protected]:~/opencv_test/1/build$ cd ..
[email protected]:~/opencv_test/1$ ./build/corrode ubuntu.png 
  • 執行結果
    在這裡插入圖片描述

  • 參考資料
    《Opencv 3變成入門》 毛星雲 電子工業出版社
    《視覺SLAM十四講》 高翔 電子工業出版社