diff options
Diffstat (limited to 'opencv-qt-integration-2')
| -rw-r--r-- | opencv-qt-integration-2/ImageApp.cpp | 92 | ||||
| -rw-r--r-- | opencv-qt-integration-2/ImageApp.h | 39 | ||||
| -rw-r--r-- | opencv-qt-integration-2/ImageApp.pro | 7 | ||||
| -rw-r--r-- | opencv-qt-integration-2/README.md | 41 | ||||
| -rw-r--r-- | opencv-qt-integration-2/main.cpp | 10 | ||||
| -rw-r--r-- | opencv-qt-integration-2/python/ImageApp.py | 82 | 
6 files changed, 0 insertions, 271 deletions
| diff --git a/opencv-qt-integration-2/ImageApp.cpp b/opencv-qt-integration-2/ImageApp.cpp deleted file mode 100644 index 5833bd8..0000000 --- a/opencv-qt-integration-2/ImageApp.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include <opencv2/imgproc/imgproc.hpp> -#include <opencv2/highgui/highgui.hpp> -#include <QtWidgets> -#include "ImageApp.h" - -ImageApp::ImageApp() -{ -	originalImage = cv::imread("../assets/The_Chapter_House.jpg"); -	if (originalImage.data) { -		cv::cvtColor(originalImage, originalImage, cv::COLOR_BGR2RGB); -	} -	setupUi(); -	showImage(originalImage); -} - -/** - * Setup the widgets - */ -void ImageApp::setupUi() -{ -	imageLabel = new QLabel(); - -	originalButton = new QPushButton("Original");	 -	connect(originalButton, SIGNAL(clicked()), this, SLOT(showOriginalImage())); - -	blurButton = new QPushButton("Gaussian Blur"); -	connect(blurButton, SIGNAL(clicked()), this, SLOT(doGaussianBlur())); - -	cannyButton = new QPushButton("Canny"); -	connect(cannyButton, SIGNAL(clicked()), this, SLOT(doCanny())); - -	quitButton = new QPushButton("Quit"); -	connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); - -	buttonsLayout = new QVBoxLayout(); -	buttonsLayout->addWidget(originalButton); -	buttonsLayout->addWidget(blurButton); -	buttonsLayout->addWidget(cannyButton); -	buttonsLayout->addStretch(); -	buttonsLayout->addWidget(quitButton); - -	mainLayout = new QHBoxLayout(); -	mainLayout->addWidget(imageLabel); - -	if (originalImage.data) { -		mainLayout->addLayout(buttonsLayout); -	} -	setLayout(mainLayout); -	setWindowTitle("Image Processing with Qt and OpenCV"); -} - -/** - * Redraw original image - */ -void ImageApp::showOriginalImage() -{ -	showImage(originalImage); -} - -/** - * Perform Canny edge detection on original image and display the result - */ -void ImageApp::doCanny() -{ -	cv::Mat gray; -	cv::cvtColor(originalImage, gray, cv::COLOR_RGB2GRAY); -	cv::Canny(gray, processedImage, 150, 150); -	cv::cvtColor(processedImage, processedImage, cv::COLOR_GRAY2RGB); -	showImage(processedImage); -} - -/** - * Perform Gaussian blurring on original image and display the result - */ -void ImageApp::doGaussianBlur() -{ -	cv::GaussianBlur(originalImage, processedImage, cv::Size(15, 15), 0, 0); -	showImage(processedImage); -} - -/** - * Draw OpenCV matrix using QLabel - */ -void ImageApp::showImage(cv::Mat img) -{ -	if (img.data) { -		QImage _img(img.data, img.cols, img.rows, QImage::Format_RGB888); -		imageLabel->setPixmap(QPixmap::fromImage(_img)); -	} else { -		imageLabel->setText("Cannot load the input image!"); -	} -} diff --git a/opencv-qt-integration-2/ImageApp.h b/opencv-qt-integration-2/ImageApp.h deleted file mode 100644 index bdedb9b..0000000 --- a/opencv-qt-integration-2/ImageApp.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef IMAGEAPP_H -#define IMAGEAPP_H - -#include <opencv2/core/core.hpp> -#include <QWidget> - -class QLabel; -class QVBoxLayout; -class QHBoxLayout; -class QPushButton; - -class ImageApp : public QWidget -{ -	Q_OBJECT - -public: -	ImageApp(); - -private slots: -	void showOriginalImage(); -	void doCanny(); -	void doGaussianBlur(); - -private: -	void setupUi(); -	void showImage(cv::Mat); - -	cv::Mat originalImage; -	cv::Mat processedImage; -	QLabel *imageLabel; -	QPushButton *originalButton; -	QPushButton *blurButton; -	QPushButton *cannyButton; -	QPushButton *quitButton; -	QVBoxLayout *buttonsLayout; -	QHBoxLayout *mainLayout; -}; - -#endif diff --git a/opencv-qt-integration-2/ImageApp.pro b/opencv-qt-integration-2/ImageApp.pro deleted file mode 100644 index 8a9bb7d..0000000 --- a/opencv-qt-integration-2/ImageApp.pro +++ /dev/null @@ -1,7 +0,0 @@ -TEMPLATE = app -TARGET = ImageApp -QT += core widgets -HEADERS += ImageApp.h -SOURCES += ImageApp.cpp main.cpp -INCLUDEPATH += . /usr/local/include -LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs diff --git a/opencv-qt-integration-2/README.md b/opencv-qt-integration-2/README.md deleted file mode 100644 index 7c1725b..0000000 --- a/opencv-qt-integration-2/README.md +++ /dev/null @@ -1,41 +0,0 @@ -OpenCV - Qt Integration -======================= - -This code sample shows you how to do basic image manipulation to an image and display the result using the `QLabel` widget. The code loads `The_Chapter_House.jpg` from the `assets/` directory and provides two buttons to perform some basic manipulation. - - - -The same program written in Python is available in the `python/` directory. - -To compile and run the code, you need to have Qt 5 installed on your computer. The code is successfully tested on the following environment: - - - Mac OS X Mavericks - - Qt 5.3.0 - - OpenCV 3.0.0 - - Python 3.4.1 - -Compiling ---------- - -Open `ImageApp.pro` and modify the variables to match with your system. For example, you might need to modify the paths for the includes and libraries especially if you're on Windows. - -    INCLUDEPATH += /usr/local/include -    LIBS += -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs - -Change your working directory and compile the code by typing: - -    qmake -    make - -If everything is ok, it will produce an executable: `ImageApp` (Linux), `ImageApp.exe` (Windows), or `ImageApp.app` (Mac). Run the executable and you will see the GUI like the screenshot above. - -Known Issues ------------- - -In `ImageApp.cpp`, the code using relative path to locate the input image: - -    img = cv::imread("../assets/The_Chapter_House.jpg"); - -If the program cannot display the image and shows the "Cannot load the input image!" warning, try to use absolute path instead. For example: - -    img = cv::imread("/full/path/to/The_Chapter_House.jpg"); diff --git a/opencv-qt-integration-2/main.cpp b/opencv-qt-integration-2/main.cpp deleted file mode 100644 index 208f75c..0000000 --- a/opencv-qt-integration-2/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include <QApplication> -#include "ImageApp.h" - -int main(int argc, char** argv) -{ -	QApplication app(argc, argv); -	ImageApp imageApp; -	imageApp.show(); -	app.exec(); -} diff --git a/opencv-qt-integration-2/python/ImageApp.py b/opencv-qt-integration-2/python/ImageApp.py deleted file mode 100644 index afa00b1..0000000 --- a/opencv-qt-integration-2/python/ImageApp.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -import os -import sys - -try: -    from PyQt5.QtCore import * -    from PyQt5.QtGui import * -    from PyQt5.QtWidgets import * -    import cv2 -except ImportError: -    print("Please install the required modules.") -    sys.exit() - - -class ImageApp(QWidget): - -    def __init__(self): -        QWidget.__init__(self) -        self.original_img = cv2.imread("../../assets/The_Chapter_House.jpg") -        if self.original_img is not None: -            self.original_img = cv2.cvtColor(self.original_img, cv2.COLOR_BGR2RGB) -        self.setup_ui() -        self.show_image(self.original_img) - -    def setup_ui(self): -        """Setup the UI widgets.""" -        self.image_label = QLabel() -        # Setup buttons -        self.original_btn = QPushButton("Original") -        self.original_btn.clicked.connect(self.show_original_image) -        self.blur_btn = QPushButton("Gaussian Blur") -        self.blur_btn.clicked.connect(self.do_gaussian_blur) -        self.canny_btn = QPushButton("Canny") -        self.canny_btn.clicked.connect(self.do_canny) -        self.quit_btn = QPushButton("Quit") -        self.quit_btn.clicked.connect(self.close) -        # Setup layout for buttons -        self.buttons_layout = QVBoxLayout() -        self.buttons_layout.addWidget(self.original_btn) -        self.buttons_layout.addWidget(self.blur_btn) -        self.buttons_layout.addWidget(self.canny_btn) -        self.buttons_layout.addStretch() -        self.buttons_layout.addWidget(self.quit_btn) -        # Setup main layout -        self.main_layout = QHBoxLayout() -        self.main_layout.addWidget(self.image_label) -        if self.original_img is not None: -            self.main_layout.addLayout(self.buttons_layout) -        self.setLayout(self.main_layout) -        self.setWindowTitle("Image Processing with Qt and OpenCV") - -    def show_original_image(self): -        """Redraw original image.""" -        self.show_image(self.original_img) - -    def do_gaussian_blur(self): -        """Perform Canny edge detection on original image and display the result.""" -        img = cv2.GaussianBlur(self.original_img, (15, 15), 0, 0) -        self.show_image(img) - -    def do_canny(self): -        """Perform Gaussian blurring on original image and display the result.""" -        img = cv2.cvtColor(self.original_img, cv2.COLOR_RGB2GRAY) -        img = cv2.Canny(img, 150, 150) -        img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) -        self.show_image(img) - -    def show_image(self, img): -        if img is not None: -            img_ = QImage(img.data, img.shape[1], img.shape[0], QImage.Format_RGB888) -            self.image_label.setPixmap(QPixmap.fromImage(img_)) -        else: -            self.image_label.setText("Cannot load the input image!") - - -if __name__ == "__main__": -    app = QApplication(sys.argv) -    image_app = ImageApp() -    image_app.show() -    app.exec_() | 
