See this post if you want to convert the image in gray.
1. Create a new Qt GUI Application project.
2. Add a new Label and Push Button in the form.
3. Do the rest with writing the program:
main.cpp:
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv/cv.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/highgui.h>
#include <QFileDialog>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
QString FileOpName; //declare FileOpName as IplImage
IplImage* imagerd; //declare imagerd as IplImage
private slots:
void on_pushButton_clicked();
void openImage(); //add a new openImage function to the project
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv/cv.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/highgui.h>
#include <QFileDialog>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
QString FileOpName; //declare FileOpName as IplImage
IplImage* imagerd; //declare imagerd as IplImage
private slots:
void on_pushButton_clicked();
void openImage(); //add a new openImage function to the project
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
---------------------------------------OR-------------------------------------------------
DOWNLOAD THE PROJECT (.zip)
Thanks - this was the first sample code to compile on OS/X and Ubuntu (after a few minor hurdles that had to do with configuration issues).
ReplyDeleteYou are welcome, happy coding by the way..
ReplyDeletehi,
ReplyDeletei am in need of some help from you. can you help me out?
thanx.
It depends on your problem, I'm not an expert by the way.
ReplyDeleteI will do my best.
thanx for your reply..i need to implement as you did but i need to add another push button, in which i have to convert image to grayscale if the button is pressed. Can you help me out in this? because i am getting an error alwayz.
ReplyDeletethanx
hei, I've made a new post that might relate to your problem. Check it out: http://hxr99.blogspot.com/2013/01/qt-opencv-displaying-images-and-convert.html
Deletemaybe this link would help you out:
ReplyDeletehttp://qt-project.org/faq/answer/how_can_i_convert_a_colored_qpixmap_into_a_grayscaled_qpixmap
I still have an exam, after the exam I will post another tutorial with Opencv and Qt.
Hi in pro file u have written `pkg-config opencv --libs --cflags` for configuring libs file rit is it for Linux . if it is for Linux how abt windows bec i am always keep on copy and pasting the libs file and include file can u please let me now
ReplyDelete