OpenCV 腐蚀与膨胀

OpenCV 腐蚀与膨胀,第1张

OpenCV 腐蚀膨胀(Eroding and Dilating)
 #include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "highgui.h"
#include <stdlib.h>
#include <stdio.h> using namespace cv; /// 全局变量
Mat src, erosion_dst, dilation_dst; int erosion_elem = ;
int erosion_size = ;
int dilation_elem = ;
int dilation_size = ;
int const max_elem = ;
int const max_kernel_size = ; /** Function Headers */
void Erosion( int, void* );
void Dilation( int, void* ); /** @function main */
int main( int argc, char** argv )
{
/// Load 图像
src = imread( argv[] ); if( !src.data )
{ return -; } /// 创建显示窗口
namedWindow( "Erosion Demo", CV_WINDOW_AUTOSIZE );
namedWindow( "Dilation Demo", CV_WINDOW_AUTOSIZE );
cvMoveWindow( "Dilation Demo", src.cols, ); /// 创建腐蚀 Trackbar
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Erosion Demo",
&erosion_elem, max_elem,
Erosion ); createTrackbar( "Kernel size:\n 2n +1", "Erosion Demo",
&erosion_size, max_kernel_size,
Erosion ); /// 创建膨胀 Trackbar
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Dilation Demo",
&dilation_elem, max_elem,
Dilation ); createTrackbar( "Kernel size:\n 2n +1", "Dilation Demo",
&dilation_size, max_kernel_size,
Dilation ); /// Default start
Erosion( , );
Dilation( , ); waitKey();
return ;
} /** @function Erosion */
void Erosion( int, void* )
{
int erosion_type;
if( erosion_elem == ){ erosion_type = MORPH_RECT; }
else if( erosion_elem == ){ erosion_type = MORPH_CROSS; }
else if( erosion_elem == ) { erosion_type = MORPH_ELLIPSE; } Mat element = getStructuringElement( erosion_type,
Size( *erosion_size + , *erosion_size+ ),
Point( erosion_size, erosion_size ) ); /// 腐蚀 *** 作
erode( src, erosion_dst, element );
imshow( "Erosion Demo", erosion_dst );
} /** @function Dilation */
void Dilation( int, void* )
{
int dilation_type;
if( dilation_elem == ){ dilation_type = MORPH_RECT; }
else if( dilation_elem == ){ dilation_type = MORPH_CROSS; }
else if( dilation_elem == ) { dilation_type = MORPH_ELLIPSE; } Mat element = getStructuringElement( dilation_type,
Size( *dilation_size + , *dilation_size+ ),
Point( dilation_size, dilation_size ) );
///膨胀 *** 作
dilate( src, dilation_dst, element );
imshow( "Dilation Demo", dilation_dst );
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/588606.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存