1 Star 3 Fork 0

邮箱猫/qtForOpencv

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
morphologydialog.cpp 3.67 KB
一键复制 编辑 原始数据 按行查看 历史
邮箱猫 提交于 2021-12-02 19:09 . 添加特征实验代码
#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);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/yuka_kitten/qt-for-opencv.git
git@gitee.com:yuka_kitten/qt-for-opencv.git
yuka_kitten
qt-for-opencv
qtForOpencv
master

搜索帮助