From d8923cc42b9d5f05d227d735021904eecc6c4f7d Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Sat, 16 Mar 2013 17:45:20 -0400 Subject: [PATCH] fixed embedded builds --- sdk/openbr_export.cpp | 16 +++------------- sdk/plugins/format.cpp | 7 ++++--- sdk/plugins/gui.cmake | 3 +++ sdk/plugins/gui.cpp | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sdk/plugins/misc.cpp | 155 ----------------------------------------------------------------------------------------------------------------------------------------------------------- 5 files changed, 168 insertions(+), 171 deletions(-) create mode 100644 sdk/plugins/gui.cmake create mode 100644 sdk/plugins/gui.cpp diff --git a/sdk/openbr_export.cpp b/sdk/openbr_export.cpp index 13c9821..b6f3b01 100644 --- a/sdk/openbr_export.cpp +++ b/sdk/openbr_export.cpp @@ -82,6 +82,7 @@ $ br -help * -# Consider the free open source program WinCDEmu if you need a program to mount ISO images. * -# You will have to register with Microsoft after installation, but it's free. * -# Grab any available Visual Studio Updates. + * -# Download and install Windows 8 SDK. * -# Download CMake 2.8.10.2 and install. * -# During installation setup select "add CMake to PATH". * -# Download OpenCV 2.4.4. @@ -100,19 +101,8 @@ $ br -help * $ nmake install * $ nmake clean * \endcode - * -# Download Qt 5.0.1 and unzip. - * -# Install Perl/Python/Ruby dependencies as explained in the "Windows" section of "README". Make sure they are added to "path" when given the option during installation. + * -# Download Qt 5.0.1 and install. * -# Download Direct X Software Developement Kit and install. - * -# From the VS2012 x64 Cross Tools Command Prompt: - * \code - * $ cd qt-everywhere-opensource-src-5.0.1 - * $ configure -prefix C:\Qt\5.0.1\msvc2012 -opensource -confirm-license -nomake examples -nomake tests - * $ nmake - * $ nmake install - * $ cd .. - * $ rmdir /Q /S qt-everywhere-opensource-src-5.0.1 - * \endcode - * -# nmake will take several hours to finish. * -# Create a GitHub account and follow their instructions for setting up Git. * -# Launch "Git Bash" from the Desktop and clone OpenBR: * \code @@ -128,7 +118,7 @@ $ br -help * $ cd C:\openbr * $ mkdir build-msvc2012 * $ cd build-msvc2012 - * $ cmake -G "CodeBlocks - NMake Makefiles" -DCMAKE_PREFIX_PATH="C:/OpenCV-2.4.4/build-msvc2012/install;C:/Qt/5.0.1/msvc2012" -DCMAKE_INSTALL_PREFIX="./install" -DBR_INSTALL_DEPENDENCIES=ON -DCMAKE_BUILD_TYPE=Release .. + * $ cmake -G "CodeBlocks - NMake Makefiles" -DCMAKE_PREFIX_PATH="C:/OpenCV-2.4.4/build-msvc2012/install;C:/Qt/Qt5.0.1/5.0.1/msvc2012_64" -DCMAKE_INSTALL_PREFIX="./install" -DBR_INSTALL_DEPENDENCIES=ON -DCMAKE_BUILD_TYPE=Release .. * $ nmake * $ nmake install * \endcode diff --git a/sdk/plugins/format.cpp b/sdk/plugins/format.cpp index 680c452..5e86e05 100644 --- a/sdk/plugins/format.cpp +++ b/sdk/plugins/format.cpp @@ -565,7 +565,6 @@ class webcamFormat : public Format BR_REGISTER(Format, webcamFormat) -#ifndef BR_EMBEDDED /*! * \ingroup formats * \brief Decodes images from Base64 xml @@ -578,13 +577,15 @@ class xmlFormat : public Format Template read() const { + Template t; + +#ifndef BR_EMBEDDED QDomDocument doc(file); QFile f(file); if (!f.open(QIODevice::ReadOnly)) qFatal("Unable to open %s for reading.", qPrintable(file.flat())); if (!doc.setContent(&f)) qFatal("Unable to parse %s.", qPrintable(file.flat())); f.close(); - Template t; QDomElement docElem = doc.documentElement(); QDomNode subject = docElem.firstChild(); while (!subject.isNull()) { @@ -620,6 +621,7 @@ class xmlFormat : public Format if (current.month() < dob.month()) age--; t.file.set("Age", age); } +#endif // BR_EMBEDDED return t; } @@ -632,7 +634,6 @@ class xmlFormat : public Format }; BR_REGISTER(Format, xmlFormat) -#endif // BR_EMBEDDED } // namespace br diff --git a/sdk/plugins/gui.cmake b/sdk/plugins/gui.cmake new file mode 100644 index 0000000..af09d1b --- /dev/null +++ b/sdk/plugins/gui.cmake @@ -0,0 +1,3 @@ +if(NOT ${BR_EMBEDDED}) + set(BR_THIRDPARTY_SRC ${BR_THIRDPARTY_SRC} plugins/gui.cpp) +endif() diff --git a/sdk/plugins/gui.cpp b/sdk/plugins/gui.cpp new file mode 100644 index 0000000..5564684 --- /dev/null +++ b/sdk/plugins/gui.cpp @@ -0,0 +1,158 @@ +#include +#include +#include +#include + +using namespace cv; + +namespace br +{ + +QImage toQImage(const Mat &mat) +{ + // Convert to 8U depth + Mat mat8u; + if (mat.depth() != CV_8U) { + double globalMin = std::numeric_limits::max(); + double globalMax = -std::numeric_limits::max(); + + std::vector mv; + split(mat, mv); + for (size_t i=0; i= globalMin); + + double range = globalMax - globalMin; + if (range != 0) { + double scale = 255 / range; + convertScaleAbs(mat, mat8u, scale, -(globalMin * scale)); + } else { + // Monochromatic + mat8u = Mat(mat.size(), CV_8UC1, Scalar((globalMin+globalMax)/2)); + } + } else { + mat8u = mat; + } + + // Convert to 3 channels + Mat mat8uc3; + if (mat8u.channels() == 4) cvtColor(mat8u, mat8uc3, CV_BGRA2RGB); + else if (mat8u.channels() == 3) cvtColor(mat8u, mat8uc3, CV_BGR2RGB); + else if (mat8u.channels() == 1) cvtColor(mat8u, mat8uc3, CV_GRAY2RGB); + + return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); +} + +// Provides slots for manipulating a QLabel, but does not inherit from QWidget. +// Therefore, it can be moved to the main thread if not created there initially +// since god forbid you create a QWidget subclass in not the main thread. +class GUIProxy : public QObject +{ + Q_OBJECT + + QLabel * window; + +public: + GUIProxy() + { + window =NULL; + } + +public slots: + void showImage(QPixmap pixmap) + { + window->show(); + window->setPixmap(pixmap); + window->setFixedSize(pixmap.size()); + window->update(); + } + + void createWindow() + { + delete window; + window = NULL; + window = new QLabel(); + } +}; + +/*! + * \ingroup transforms + * \brief Displays templates in a GUI pop-up window using QT. + * \author Charles Otto \cite caotto + * Unlike ShowTransform, this can be used with parallelism enabled, although it + * is considered TimeVarying. + */ +class Show2Transform : public TimeVaryingTransform +{ + Q_OBJECT +public: + Show2Transform() : TimeVaryingTransform(false, false) + { + // Create our GUI proxy + gui = new GUIProxy(); + // Move it to the main thread, this means signals we send to it will + // be run in the main thread, which is hopefully in an event loop + gui->moveToThread(QApplication::instance()->thread()); + // Connect our signals to the proxy's slots + connect(this, SIGNAL(needWindow()), gui, SLOT(createWindow()), Qt::BlockingQueuedConnection); + connect(this, SIGNAL(updateImage(QPixmap)), gui, SLOT(showImage(QPixmap))); + } + + ~Show2Transform() + { + delete gui; + } + + void train(const TemplateList &data) { (void) data; } + + void project(const TemplateList &src, TemplateList &dst) const + { + Transform * non_const = (Show2Transform *) this; + non_const->projectUpdate(src,dst); + } + + void projectUpdate(const TemplateList &src, TemplateList &dst) + { + dst = src; + + if (src.empty()) + return; + + foreach (const Template & t, src) { + foreach(const cv::Mat & m, t) { + QImage qImageBuffer = toQImage(m); + displayBuffer.convertFromImage(qImageBuffer); + emit updateImage(displayBuffer); + } + } + } + + void finalize(TemplateList & output) + { + (void) output; + // todo: hide ui? + } + + void init() + { + emit needWindow(); + } + +protected: + GUIProxy * gui; + QPixmap displayBuffer; + +signals: + void needWindow(); + void updateImage(QPixmap input); +}; + +BR_REGISTER(Transform, Show2Transform) + +} // namespace br + +#include "gui.moc" diff --git a/sdk/plugins/misc.cpp b/sdk/plugins/misc.cpp index 3a99ce2..90081b3 100644 --- a/sdk/plugins/misc.cpp +++ b/sdk/plugins/misc.cpp @@ -19,13 +19,6 @@ #include "core/opencvutils.h" -#ifndef BR_EMBEDDED -#include -#include -#include -#endif - - using namespace cv; namespace br @@ -97,154 +90,6 @@ int ShowTransform::counter = 0; BR_REGISTER(Transform, ShowTransform) -#ifndef BR_EMBEDDED - -QImage toQImage(const Mat &mat) -{ - // Convert to 8U depth - Mat mat8u; - if (mat.depth() != CV_8U) { - double globalMin = std::numeric_limits::max(); - double globalMax = -std::numeric_limits::max(); - - std::vector mv; - split(mat, mv); - for (size_t i=0; i= globalMin); - - double range = globalMax - globalMin; - if (range != 0) { - double scale = 255 / range; - convertScaleAbs(mat, mat8u, scale, -(globalMin * scale)); - } else { - // Monochromatic - mat8u = Mat(mat.size(), CV_8UC1, Scalar((globalMin+globalMax)/2)); - } - } else { - mat8u = mat; - } - - // Convert to 3 channels - Mat mat8uc3; - if (mat8u.channels() == 4) cvtColor(mat8u, mat8uc3, CV_BGRA2RGB); - else if (mat8u.channels() == 3) cvtColor(mat8u, mat8uc3, CV_BGR2RGB); - else if (mat8u.channels() == 1) cvtColor(mat8u, mat8uc3, CV_GRAY2RGB); - - return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); -} - -// Provides slots for manipulating a QLabel, but does not inherit from QWidget. -// Therefore, it can be moved to the main thread if not created there initially -// since god forbid you create a QWidget subclass in not the main thread. -class GUIProxy : public QObject -{ - Q_OBJECT - - QLabel * window; - -public: - GUIProxy() - { - window =NULL; - } - -public slots: - void showImage(QPixmap pixmap) - { - window->show(); - window->setPixmap(pixmap); - window->setFixedSize(pixmap.size()); - window->update(); - } - - void createWindow() - { - delete window; - window = NULL; - window = new QLabel(); - } -}; - -/*! - * \ingroup transforms - * \brief Displays templates in a GUI pop-up window using QT. - * \author Charles Otto \cite caotto - * Unlike ShowTransform, this can be used with parallelism enabled, although it - * is considered TimeVarying. - */ -class Show2Transform : public TimeVaryingTransform -{ - Q_OBJECT -public: - Show2Transform() : TimeVaryingTransform(false, false) - { - // Create our GUI proxy - gui = new GUIProxy(); - // Move it to the main thread, this means signals we send to it will - // be run in the main thread, which is hopefully in an event loop - gui->moveToThread(QApplication::instance()->thread()); - // Connect our signals to the proxy's slots - connect(this, SIGNAL(needWindow()), gui, SLOT(createWindow()), Qt::BlockingQueuedConnection); - connect(this, SIGNAL(updateImage(QPixmap)), gui, SLOT(showImage(QPixmap))); - } - - ~Show2Transform() - { - delete gui; - } - - void train(const TemplateList &data) { (void) data; } - - void project(const TemplateList &src, TemplateList &dst) const - { - Transform * non_const = (Show2Transform *) this; - non_const->projectUpdate(src,dst); - } - - void projectUpdate(const TemplateList &src, TemplateList &dst) - { - dst = src; - - if (src.empty()) - return; - - foreach (const Template & t, src) { - foreach(const cv::Mat & m, t) { - QImage qImageBuffer = toQImage(m); - displayBuffer.convertFromImage(qImageBuffer); - emit updateImage(displayBuffer); - } - } - } - - void finalize(TemplateList & output) - { - (void) output; - // todo: hide ui? - } - - void init() - { - emit needWindow(); - } - -protected: - GUIProxy * gui; - QPixmap displayBuffer; - -signals: - void needWindow(); - void updateImage(QPixmap input); -}; - -BR_REGISTER(Transform, Show2Transform) -#endif - /*! * \ingroup transforms * \brief Prints the template's file to stdout or stderr. -- libgit2 0.21.4