OpenCV 腐蚀与膨胀(Eroding and Dilating)
2024-09-06 04:35:53
#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 );
}
最新文章
- 转载 CSS3 经典教程系列:CSS3 盒阴影(box-shadow)详解
- django TEMPLATES
- step by step 之餐饮管理系统六(数据库访问模块)
- 移植DNS服务bind
- 418. Sentence Screen Fitting
- phpStorm 配置关联php手册
- 十步完全理解SQL(转)
- Spring Boot启动过程(六):内嵌Tomcat中StandardHost与StandardContext的启动
- Google Chrome 默认非安全端口列表
- Lettuce_webdriver 自动化测试
- 错误 0xc0202049: 数据流任务 1: 无法在只读列“ID”中插入数据
- JavaScript:在JS中截取字符串的方法
- 【BZOJ1026】【SCOI2009】windy数
- mvc 路由配置
- 使用sqlyog或者navicat连接mysql提示1862错误解决
- java web 乱码终结
- Jmeter调用 Json接口测试之关键点申明Content-Type类型
- python技巧 switch case语句
- C语言 位移 速度 时间 Demo
- centos自带的dvd中的官方base源,丢失了可以复制下面的内容