OPENCV入门教程十一:dilate图像膨胀
一、目標(biāo)
學(xué)習(xí)如何使用opencv中的函數(shù),學(xué)習(xí)對(duì)圖像的膨脹操作,學(xué)習(xí)dilate()函數(shù)的使用
二、函數(shù)說(shuō)明
函數(shù)原型:
dilate(InputArray src,OutputArray dst,InputArray kernel,Point anchor=Point(-1,-1),int iterations=1,int borderType=BORDER_CONSTANT,const Scalar& borderValue=morphologyDefaultBorderValue() );參數(shù)詳解:
src:源圖像
dst:目標(biāo)圖像。
kernel:膨脹操作的核。若為NULL時(shí),表示的是使用參考點(diǎn)位于中心3x3的核。
我們一般使用函數(shù) getStructuringElement配合這個(gè)參數(shù)的使用。getStructuringElement函數(shù)會(huì)返回指定形狀和尺寸的結(jié)構(gòu)元素(內(nèi)核矩陣)。
anchor:錨的位置,其有默認(rèn)值(-1,-1),表示錨位于中心。
iterations:迭代使用erode()函數(shù)的次數(shù),默認(rèn)值為1。
borderType:用于推斷圖像外部像素的某種邊界模式。
borderValue:當(dāng)邊界為常數(shù)時(shí)的邊界值
使用erode函數(shù),一般我們只需要填前面的三個(gè)參數(shù),后面的四個(gè)參數(shù)都有默認(rèn)值。而且往往結(jié)合getStructuringElement一起使用。
三、程序代碼
#include "cv.h" // OpenCV 文件頭 #include "highgui.h" #include "opencv2/opencv.hpp" #include "opencv2/imgproc.hpp" #include <iostream> #include <string>using namespace cv; using namespace std;int main(int argc, char *argv[]) {Mat m_SrcImg;m_SrcImg = imread("C:\\Users\\lidabao\\Desktop\\Lena.bmp");namedWindow("原圖像", 1);imshow("原圖像", m_SrcImg);//獲取自定義核Mat element = getStructuringElement(MORPH_RECT, Size(10, 10));Mat m_ResImg;//進(jìn)行膨脹操作dilate(m_SrcImg, m_ResImg, element);namedWindow("膨脹后圖像", 1);imshow("膨脹后圖像", m_ResImg);waitKey(0); }四、結(jié)果
程序運(yùn)行如下圖:
五、注意
正確的配置opencv
正確使用dilate()函數(shù)
總結(jié)
以上是生活随笔為你收集整理的OPENCV入门教程十一:dilate图像膨胀的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。