代码拉取完成,页面将自动刷新
#include "morphologydialog.h"
#include "ui_morphologydialog.h"
MorphologyDialog::MorphologyDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::MorphologyDialog)
{
ui->setupUi(this);
}
MorphologyDialog::~MorphologyDialog()
{
delete ui;
}
void MorphologyDialog::receiveImage(Mat src){
image=src;
}
void MorphologyDialog::on_heightSlider_valueChanged(int value)
{
ui->label_height->setNum(value);
}
void MorphologyDialog::on_widthSlider_valueChanged(int value)
{
ui->label_width->setNum(value);
}
void MorphologyDialog::on_buttonBox_accepted()
{
int width=ui->widthSlider->value();
int height=ui->heightSlider->value();
int px=ui->XlineEdit->text().toInt();
int py=ui->YlineEdit->text().toInt();
int structType=0;
if(ui->structcB->currentIndex()==0){
structType=MORPH_RECT;
}else if(ui->structcB->currentIndex()==1){
structType=MORPH_ELLIPSE;
}else if(ui->structcB->currentIndex()==2){
structType=MORPH_CROSS;
}
Mat structureElement = getStructuringElement(structType, Size(width, height), Point(px, py));
Mat dst;
if(ui->typecB->currentIndex()==0){
//膨胀
dilate(image, dst, structureElement);
}else if(ui->typecB->currentIndex()==1){
//腐蚀
erode(image, dst, structureElement);
}else if(ui->typecB->currentIndex()==2){
//开运算
erode(image, dst, structureElement);
dilate(dst, dst, structureElement);
}else if(ui->typecB->currentIndex()==3){
//闭运算
dilate(image, dst, structureElement);
erode(dst, dst, structureElement);
}else if(ui->typecB->currentIndex()==4){
//边界提取
Mat temp;
erode(image, temp, structureElement);
dst=image-temp;
}else if(ui->typecB->currentIndex()==5){
//边界点检测
Mat structList[4];
//初始化结构元素
Mat center=getStructuringElement(MORPH_CROSS,Size(3,3));
center.at<uchar>(0,1)=0;
center.at<uchar>(1,0)=0;
center.at<uchar>(2,1)=0;
center.at<uchar>(1,2)=0;
Mat border=getStructuringElement(MORPH_RECT,Size(3,3));
border.at<uchar>(1,1)=0;
structList[0]=border.clone();
structList[0].at<uchar>(0,0)=0;
structList[0].at<uchar>(0,1)=0;
structList[0].at<uchar>(0,2)=0;
structList[1]=border.clone();
structList[1].at<uchar>(0,0)=0;
structList[1].at<uchar>(1,0)=0;
structList[1].at<uchar>(2,0)=0;
structList[2]=border.clone();
structList[2].at<uchar>(0,2)=0;
structList[2].at<uchar>(1,2)=0;
structList[2].at<uchar>(2,2)=0;
structList[3]=border.clone();
structList[3].at<uchar>(2,0)=0;
structList[3].at<uchar>(2,1)=0;
structList[3].at<uchar>(2,2)=0;
dst=image.clone();
Mat src=image.clone();
cvtColor(src,src,CV_BGR2GRAY);
//图像二值化
threshold(src,src,0,255,THRESH_OTSU);
Mat temp=src.clone();
erode(temp, temp, center);
for(int t=0;t<4;++t){
Mat temp_not=src.clone();
//获取相补的图像
bitwise_not(temp_not,temp_not);
Mat core=structList[t];
erode(temp_not, temp_not, core);
Mat temp_res=temp&temp_not;
for(int i=0;i<temp_res.rows;++i){
for(int j=0;j<temp_res.cols;++j){
if(temp_res.at<uchar>(i,j)==255){
//边界点位置用红圈标记
circle(dst,Point(j,i),3,Scalar(0, 0, 255));
}
}
}
}
}else{
dst=image.clone();
}
emit sendImage(dst);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。