QT Console
#include <opencv2/opencv.hpp> //#include <opencv2/highgui/highgui.hpp> int main(int argc, char *argv[]) { cv::Mat image = cv::imread("img.jpg"); cv::namedWindow("My Image"); cv::imshow("My Image", image); cv::waitKey(5000); return 1; }
pro file
#------------------------------------------------- # # Project created by QtCreator 2013-06-17T14:15:10 # #------------------------------------------------- QT += core QT -= gui TARGET = myQTConsoleProject CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp INCLUDEPATH += ~/opencv/opencv-2.4.5/include/ LIBS += -L/usr/local/lib \ -lopencv_core \ -lopencv_highgui \ -lopencv_imgproc \ -lopencv_features2d \ -lopencv_calib3d
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFileDialog> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), ".", tr("Image Files (*.png *.jpg *.jpeg *.bmp)")); image= cv::imread(fileName.toLatin1().data()); cv::namedWindow("Original Image"); cv::imshow("Original Image", image); } void MainWindow::on_pushButton_2_clicked() { cv::flip(image,image,1); cv::namedWindow("Output Image"); cv::imshow("Output Image", image); }