代码拉取完成,页面将自动刷新
#include "convolution.h"
#include "ui_convolution.h"
Convolution::Convolution(QWidget *parent) :
QDialog(parent),
ui(new Ui::Convolution)
{
ui->setupUi(this);
}
Convolution::~Convolution()
{
delete ui;
}
void Convolution::on_rBperset_toggled(bool checked)
{
ui->gBpreset->setEnabled(checked);
}
void Convolution::on_rBset_toggled(bool checked)
{
ui->gBset->setEnabled(checked);
}
void Convolution::on_buttonBox_accepted()
{
Mat dst;
if(ui->rBperset->isChecked()){
int s = ui->lEperset->text().toInt();
Size size = Size(s,s);
if(choosed==0){
blur(image,dst,size,Point(-1,-1));
}else if(choosed==1){
GaussianBlur(image,dst,size,0,0);
}else if(choosed==2){
if(s%2==0) s=s+1;//判断是否为奇数
medianBlur(image,dst,s);
}else if(choosed==3){
Mat roberts_a = (Mat_<char>(2,2)<< 0,-1,1,0);//两个方向的卷积核
Mat roberts_b = (Mat_<char>(2,2)<< -1,0,0,1);
Mat a,b;
filter2D(image,a,-1,roberts_a,Point(0,0),0);//进行卷积操作
filter2D(image,b,-1,roberts_b,Point(0,0),0);
convertScaleAbs(a,a);//对卷积后的图像值进行规范化
convertScaleAbs(b,b);
addWeighted(a,0.5,b,0.5,0,dst);//将两个卷积的结果叠加
}else if(choosed==4){
Mat prewitt_a = (Mat_<char>(3,3) << -1,0,1,-1,0,1,-1,0,1);//两个方向的卷积核
Mat prewitt_b = (Mat_<char>(3,3) << -1,-1,-1,0,0,0,1,1,1);
Mat a,b;
filter2D(image,a,-1,prewitt_a,Point(-1,-1),0);//进行卷积操作
filter2D(image,b,-1,prewitt_b,Point(-1,-1),0);
convertScaleAbs(a,a);//对卷积后的图像值进行规范化
convertScaleAbs(b,b);
addWeighted(a,0.5,b,0.5,0,dst);//将两个卷积的结果叠加
}else if(choosed==5){
// Mat sobel_a = (Mat_<char>(3,3) << -1,0,1,-2,0,2,-1,0,1);//两个方向的卷积核
// Mat sobel_b = (Mat_<char>(3,3) << -1,-2,-1,0,0,0,1,2,1);
Mat a,b;
Sobel(image,a,-1,1,0,3);
Sobel(image,b,-1,0,1,3);
// filter2D(image,a,-1,sobel_a,Point(-1,-1),0);//进行卷积操作
// filter2D(image,b,-1,sobel_b,Point(-1,-1),0);
convertScaleAbs(a,a);//对卷积后的图像值进行规范化
convertScaleAbs(b,b);
addWeighted(a,0.5,b,0.5,0,dst);//将两个卷积的结果叠加
}else if(choosed==6){
// Mat laplace = (Mat_<char>(3,3) << 1,-2,1,-2,4,-2,1,-2,1);
cvtColor(image,dst,CV_BGR2GRAY);
Laplacian(dst,dst,-1,3,1,0);
// filter2D(image,dst,-1,laplace,Point(-1,-1),0);
convertScaleAbs(dst,dst);
cvtColor(dst,dst,CV_GRAY2BGR);
}else if(choosed==7){
cvtColor(image,dst,CV_BGR2GRAY);
int lowThreshold = 100;
Canny(dst,dst,lowThreshold,lowThreshold*3,3);
cvtColor(dst,dst,CV_GRAY2BGR);
}
}else if(ui->rBset->isChecked()){
int x = ui->lEsetx->text().toInt();
int y = ui->lEsety->text().toInt();
Mat c_mat = Mat::zeros(x,y,CV_32FC1);
Point p = Point(-1,-1);
float sum = 0;
for(int i=0;i<x;++i){
for(int j=0;j<y;++j){
QString str = ui->tWset->item(i,j)->text();
if(str.at(0) == '*'){
str.remove(0,1);
c_mat.at<float>(i,j)=str.toInt();
sum+=str.toInt();
p = Point(i,j);
}else{
c_mat.at<float>(i,j)=str.toInt();
sum+=str.toInt();
}
}
}
cout<<c_mat<<endl;
if(sum!=0)
for(int i=0;i<x;++i){
for(int j=0;j<y;++j){
c_mat.at<float>(i,j)=c_mat.at<float>(i,j)/sum;
}
}
filter2D(image,dst,-1,c_mat,p,0);
convertScaleAbs(dst,dst);
}else{
}
emit sendImage(dst);
}
void Convolution::on_cBperset_activated(int index)
{
this->choosed = index;
// cout<<index<<endl;
}
void Convolution::receiveImage(Mat oldimage){
this->image = oldimage;
}
void Convolution::on_lEsetx_textChanged(const QString &arg)
{
ui->tWset->setColumnCount(arg.toInt());
}
void Convolution::on_lEsety_textChanged(const QString &arg)
{
ui->tWset->setRowCount(arg.toInt());
}
void Convolution::on_buttonBox_rejected()
{
delete this;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。