一 识别场景
二 项目配置 QT mingw+opencv
3 源文件
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv2/opencv.hpp>
#include <QFileDialog>
#include <vector>
#include <string>
#include <QImage>
using namespace cv;
using namespace std;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QImage MatToQImage(Mat MatImg);
Mat Oimg;//保存碎片的变量
Mat img_src; //保存原始招聘的变量
void detection(Mat DstImg,Mat RefImgs);
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_pushButton_3_clicked();
//获取而分化值
double GetThreshValOtsu(const cv::Mat& Matsrc);
//计算白边圆膜
Mat BordStrel(int iRadius);
//计算角度
double CalLineAngle(vector<vector<Point> > conLeft,
vector<Vec4i> hierLeft,
vector<vector<Point> > conRight,
vector<Vec4i> hierRight,
int index);
private:
Ui::MainWindow *ui;
int m_x,m_y,m_w,m_h; //设置识别区域的变量
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
const double PI=3.1415926;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_x = 180;
m_y = 150;
m_w = 350;
m_h = 300;
}
MainWindow::~MainWindow()
{
delete ui;
}
//图像缓缓转成bgr的图像
QImage MainWindow::MatToQImage(Mat MatImg){
Mat cvRgbImg;
cvtColor(MatImg, cvRgbImg, CV_BGR2RGB);
QImage dstImage((const uchar *)cvRgbImg.data, cvRgbImg.cols, cvRgbImg.rows, cvRgbImg.step, QImage::Format_RGB888);
dstImage.bits();
return dstImage;
}
// Image 添加大图
void MainWindow::on_pushButton_3_clicked() //设置按钮
{
QString filename = QFileDialog::getOpenFileName(this,tr("open image"),".",tr("Image Files(*.png)"));
img_src = imread(filename.toStdString());//读取图像
QImage temp