• 文件结构
[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 
  • 运行结果
    图像腐蚀-ubnutu16.04系统下

  • 参考资料
    《Opencv 3变成入门》 毛星云 电子工业出版社
    《视觉SLAM十四讲》 高翔 电子工业出版社

相关文章: