1 Star 3 Fork 0

邮箱猫/qtForOpencv

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
convolution.cpp 4.46 KB
一键复制 编辑 原始数据 按行查看 历史
#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;
}
马建仓 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

搜索帮助