首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

分享:应用Qt和OpenCV做的图像平滑器

2012-08-19 
分享:使用Qt和OpenCV做的图像平滑器这是我这学期数字图像处理课的课程设计。程序界面原始图像处理后的图像

分享:使用Qt和OpenCV做的图像平滑器
这是我这学期数字图像处理课的课程设计。
程序界面

原始图像

处理后的图像

虽然界面很简陋,但处理效果还好。
 mainwindow.h 文件

C/C++ code
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include<QFileDialog>#include<opencv.hpp>using namespace cv;namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{    Q_OBJECT    public:    explicit MainWindow(QWidget *parent = 0);    ~MainWindow();    private:    Ui::MainWindow *ui;    Mat image;    //载入的原始图片    Mat result;    //处理后的图片private slots:    void liulan();    //载入图片    void chuli();    //对图片进行低通滤波    void baocun();    //保存图片};#endif // MAINWINDOW_H

mainwindow.cpp文件
C/C++ code
#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :    QMainWindow(parent),    ui(new Ui::MainWindow){    ui->setupUi(this);    connect(ui->liulanButton,SIGNAL(clicked()),this,SLOT(liulan()));    connect(ui->xianshiButton,SIGNAL(clicked()),this,SLOT(chuli()));    connect(ui->baocunButton,SIGNAL(clicked()),this,SLOT(baocun()));}MainWindow::~MainWindow(){    delete ui;}void MainWindow::liulan()  {    QString imageName=QFileDialog::getOpenFileName(this,"Open file");    image=imread(imageName.toAscii().data());}void MainWindow::chuli()  {    cv::blur(image,result,cv::Size(5,5));    imshow("result",result);    imshow("image",image);}void MainWindow::baocun()  {    QString fileName= QFileDialog::getSaveFileName(this,"Save file");    imwrite(fileName.toAscii().data(),result);

mainwindow.ui文件
XML code
<?xml version="1.0" encoding="UTF-8"?><ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow">  <property name="geometry">   <rect>    <x>0</x>    <y>0</y>    <width>400</width>    <height>300</height>   </rect>  </property>  <property name="windowTitle">   <string>MainWindow</string>  </property>  <widget class="QWidget" name="centralWidget">   <widget class="QPushButton" name="liulanButton">    <property name="geometry">     <rect>      <x>150</x>      <y>40</y>      <width>75</width>      <height>23</height>     </rect>    </property>    <property name="text">     <string>浏览</string>    </property>   </widget>   <widget class="QPushButton" name="xianshiButton">    <property name="geometry">     <rect>      <x>150</x>      <y>130</y>      <width>75</width>      <height>23</height>     </rect>    </property>    <property name="text">     <string>处理</string>    </property>   </widget>   <widget class="QPushButton" name="baocunButton">    <property name="geometry">     <rect>      <x>150</x>      <y>200</y>      <width>75</width>      <height>23</height>     </rect>    </property>    <property name="text">     <string>保存文件</string>    </property>   </widget>  </widget>  <widget class="QMenuBar" name="menuBar">   <property name="geometry">    <rect>     <x>0</x>     <y>0</y>     <width>400</width>     <height>23</height>    </rect>   </property>  </widget>  <widget class="QToolBar" name="mainToolBar">   <attribute name="toolBarArea">    <enum>TopToolBarArea</enum>   </attribute>   <attribute name="toolBarBreak">    <bool>false</bool>   </attribute>  </widget>  <widget class="QStatusBar" name="statusBar"/> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/></ui> 


 main.cpp文件
C/C++ code
#include <QtGui/QApplication>#include "mainwindow.h"int main(int argc, char *argv[]){    QApplication a(argc, argv);    MainWindow w;    w.show();        return a.exec();}

 opencv_and_qt.pro文件
C/C++ code
#-------------------------------------------------## Project created by QtCreator 2012-05-19T20:58:04##-------------------------------------------------QT       += core guiTARGET = opencv_and_qtTEMPLATE = appSOURCES += main.cpp\        mainwindow.cppHEADERS  += mainwindow.hFORMS    += mainwindow.uiINCLUDEPATH +=D:\OpenCV\opencv\build\include\opencv2 \D:\OpenCV\opencv\build\include\opencv \D:\OpenCV\opencv\build\includeCONFIG(release,debug|release){    LIBS += D:\OpenCV\opencv\build\x86\vc10\lib\opencv_calib3d231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_contrib231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_core231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_features2d231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_flann231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_gpu231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_highgui231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_imgproc231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_legacy231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_ml231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_objdetect231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_ts231.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_video231.lib}CONFIG(debug,debug|release){    LIBS +=D:\OpenCV\opencv\build\x86\vc10\lib\opencv_calib3d231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_contrib231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_core231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_features2d231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_flann231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_gpu231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_highgui231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_imgproc231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_legacy231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_ml231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_objdetect231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_ts231d.lib \D:\OpenCV\opencv\build\x86\vc10\lib\opencv_video231d.lib}RESOURCES += \    resource.qrc


[解决办法]
支持

open CV 的库 
是Static编译的,还是 share 编译的?
[解决办法]
小case

热点排行