1 Star 3 Fork 0

邮箱猫/qtForOpencv

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
houghdialog.cpp 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
#include "houghdialog.h"
#include "ui_houghdialog.h"
HoughDialog::HoughDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::HoughDialog)
{
ui->setupUi(this);
}
HoughDialog::~HoughDialog()
{
delete ui;
}
void HoughDialog::on_pushButton_clicked()
{
flush();
}
void HoughDialog::receiveImage(Mat in){
src=in.clone();
flush();
}
void HoughDialog::flush(){
Mat gray_src;
dst=src.clone();
cvtColor(src,gray_src,CV_BGR2GRAY);//转化为灰度图
int lowThreshold = ui->CannyLE->text().toInt();
int houghThreshold = ui->HoughLE->text().toInt();
int minLength = ui->lengthLE->text().toInt();
int maxDistanse = ui->disLE->text().toInt();
Canny(gray_src, gray_src, lowThreshold, lowThreshold*3, 3);//cannny区域分割
vector<Vec4f> lines;
HoughLinesP(gray_src,lines,1,CV_PI/180,houghThreshold,minLength,maxDistanse);//霍夫变换
for (size_t i = 0; i < lines.size(); i++)//将检测到的直线进行绘制
{
Vec4f point1 = lines[i];
line(dst, Point(point1[0], point1[1]), Point(point1[2], point1[3]), Scalar(255, 255, 0), 2, LINE_AA);
}
Mat dstShow=dst.clone();
cvtColor(dstShow,dstShow,CV_BGR2RGB);
QImage img = QImage((const unsigned char*)(dstShow.data),dstShow.cols,dstShow.rows,dstShow.step,QImage::Format_RGB888);
ui->graphicsView->resize(img.width(), img.height());
QGraphicsScene *scene = new QGraphicsScene;
//scene->setSceneRect(0,0,img.width(),img.height());
scene->addPixmap(QPixmap::fromImage(img));
ui->graphicsView->setScene(scene);
ui->graphicsView->adjustSize();
ui->graphicsView->show();
}
void HoughDialog::on_buttonBox_accepted()
{
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

搜索帮助