From 4936fcc1c8e0d2bffbe55a4efc4569b0c585416b Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Thu, 25 Jul 2013 17:01:47 -0400 Subject: [PATCH] Added ManualTransform for specifying eye locations --- 3rdparty/stasm4.0.0/stasm/MOD_1/facedet.cpp | 2 ++ 3rdparty/stasm4.0.0/stasm/print.cpp | 3 +++ 3rdparty/stasm4.0.0/stasm/stasm_lib.cpp | 13 +++++++++++++ openbr/plugins/gui.cpp | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- openbr/plugins/regions.cpp | 13 +++++++------ 5 files changed, 172 insertions(+), 33 deletions(-) diff --git a/3rdparty/stasm4.0.0/stasm/MOD_1/facedet.cpp b/3rdparty/stasm4.0.0/stasm/MOD_1/facedet.cpp index bbf0096..6e5d196 100755 --- a/3rdparty/stasm4.0.0/stasm/MOD_1/facedet.cpp +++ b/3rdparty/stasm4.0.0/stasm/MOD_1/facedet.cpp @@ -19,6 +19,7 @@ void FaceDet::OpenFaceDetector_( // called by stasm_init, init face det from XML const char* datadir, // in: directory of face detector files void*) // in: unused (func signature compatibility) { + (void) datadir; //OpenDetector(facedet_g, "haarcascade_frontalface_alt2.xml", datadir); } @@ -145,6 +146,7 @@ static void TraceFaces( // write image showing detected face rects const Image& img, // in const char* filename) // in { + (void) detpars, img, filename; #if TRACE_IMAGES // will be 0 unless debugging (defined in stasm.h) CImage cimg; cvtColor(img, cimg, CV_GRAY2BGR); // color image diff --git a/3rdparty/stasm4.0.0/stasm/print.cpp b/3rdparty/stasm4.0.0/stasm/print.cpp index 0c4f15d..4c02497 100755 --- a/3rdparty/stasm4.0.0/stasm/print.cpp +++ b/3rdparty/stasm4.0.0/stasm/print.cpp @@ -40,6 +40,7 @@ void OpenLogFile(void) // also inits the global variable logfile_g void lprintf(const char* format, ...) // args like printf { + (void) format; /* if (print_g) { @@ -57,6 +58,7 @@ void lprintf(const char* format, ...) // args like printf void logprintf(const char* format, ...) // args like printf { + (void) format; /* if (logfile_g) { @@ -76,6 +78,7 @@ void logprintf(const char* format, ...) // args like printf void lputs(const char* s) { + (void) s; /* printf("%s", s); fflush(stdout); // flush so if there is a crash we can see what happened diff --git a/3rdparty/stasm4.0.0/stasm/stasm_lib.cpp b/3rdparty/stasm4.0.0/stasm/stasm_lib.cpp index 879f157..fa4b26c 100755 --- a/3rdparty/stasm4.0.0/stasm/stasm_lib.cpp +++ b/3rdparty/stasm4.0.0/stasm/stasm_lib.cpp @@ -63,6 +63,8 @@ int stasm_init_ext( // extended version of stasm_init int trace, // in: 0 normal use, 1 trace to stdout and stasm.log void* detparams) // in: NULL or face detector parameters { + (void) detparams; + int returnval = 1; // assume success CatchOpenCvErrs(); try @@ -111,6 +113,12 @@ int stasm_open_image_ext( // extended version of stasm_open_image int minwidth, // in: min face width as percentage of img width void* user) // in: NULL or pointer to user abort func { + (void) img; + (void) width; + (void) height; + (void) imgpath; + (void) user; + int returnval = 1; // assume success CatchOpenCvErrs(); try @@ -241,6 +249,11 @@ int stasm_search_pinned( // call after the user has pinned some points int height, // in: image height const char* imgpath) // in: image path, used only for err msgs and debug { + (void) img; + (void) width; + (void) height; + (void) imgpath; + int returnval = 1; // assume success CatchOpenCvErrs(); try diff --git a/openbr/plugins/gui.cpp b/openbr/plugins/gui.cpp index 46e40f6..ad1cacf 100644 --- a/openbr/plugins/gui.cpp +++ b/openbr/plugins/gui.cpp @@ -3,6 +3,9 @@ #include #include #include +#include +#include + #include #include "openbr_internal.h" @@ -61,27 +64,31 @@ class GUIProxy : public QObject public: + QLabel *window; + QPixmap pixmap; + + GUIProxy() + { + window = NULL; + } + bool eventFilter(QObject * obj, QEvent * event) { if (event->type() == QEvent::KeyPress) { + event->accept(); + wait.wakeAll(); + return true; + } else { + return QObject::eventFilter(obj, event); } - else if (event->type() == QEvent::MouseButtonPress) - { - qDebug() << "hey there"; - } - return QObject::eventFilter(obj, event); } - QLabel * window; - GUIProxy() + virtual void waitForKey(Template &dst) { - window = NULL; - } + (void) dst; - void waitForKey() - { QMutexLocker locker(&lock); wait.wait(&lock); } @@ -90,8 +97,10 @@ public slots: void showImage(const QPixmap & input) { + pixmap = input; + window->show(); - window->setPixmap(input); + window->setPixmap(pixmap); window->setFixedSize(input.size()); } @@ -109,6 +118,56 @@ public slots: flags = flags & ~Qt::WindowCloseButtonHint; window->setWindowFlags(flags); } + +}; + +class EyeProxy : public GUIProxy +{ + Q_OBJECT + +public: + + bool eventFilter(QObject *obj, QEvent *event) + { + if (event->type() == QEvent::MouseButtonPress) + { + event->accept(); + + QMouseEvent *mouseEvent = (QMouseEvent*)event; + + if (mouseEvent->button() == Qt::LeftButton) leftEye = mouseEvent->pos(); + else if (mouseEvent->button() == Qt::RightButton) rightEye = mouseEvent->pos(); + + QPixmap pixmapBuffer = pixmap; + + QPainter painter(&pixmapBuffer); + painter.setBrush(Qt::black); + + painter.drawEllipse(leftEye, 4, 4); + painter.drawEllipse(rightEye, 4, 4); + + window->setPixmap(pixmapBuffer); + + return true; + } else { + return GUIProxy::eventFilter(obj, event); + } + } + + void waitForKey(Template &dst) + { + leftEye = rightEye = QPointF(); + + GUIProxy::waitForKey(dst); + + dst.file.set("leftEye", leftEye); + dst.file.set("rightEye", rightEye); + } + +private: + + QPointF leftEye; + QPointF rightEye; }; /*! @@ -131,17 +190,6 @@ public: { gui = NULL; displayBuffer = NULL; - if (!Globals->useGui) - return; - displayBuffer = new QPixmap(); - // 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))); } ~ShowTransform() @@ -181,14 +229,16 @@ public: qImageBuffer = toQImage(m); displayBuffer->convertFromImage(qImageBuffer); - // Emit an explicit copy of our pixmap so that the pixmap used + // Emit an explicit copy of our pixmap so that the pixmap used // by the main thread isn't damaged when we update displayBuffer // later. emit updateImage(displayBuffer->copy(displayBuffer->rect())); // Blocking wait for a key-press - if (this->waitInput) - gui->waitForKey(); + if (this->waitInput) { + Template blank; + gui->waitForKey(blank); + } } } @@ -205,6 +255,18 @@ public: if (!Globals->useGui) return; + displayBuffer = new QPixmap(); + + // 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))); + emit needWindow(); connect(this, SIGNAL(changeTitle(QString)), gui->window, SLOT(setWindowTitle(QString))); connect(this, SIGNAL(hideWindow()), gui->window, SLOT(hide())); @@ -221,9 +283,67 @@ signals: void changeTitle(const QString & input); void hideWindow(); }; - BR_REGISTER(Transform, ShowTransform) +/*! + * \ingroup transforms + * \brief Displays templates in a GUI pop-up window using QT. + * \author Charles Otto \cite caotto + * Can be used with parallelism enabled, although it is considered TimeVarying. + */ +class ManualTransform : public ShowTransform +{ + Q_OBJECT + + // Specify key + +public: + void projectUpdate(const TemplateList &src, TemplateList &dst) + { + dst = src; + + if (src.empty() || !Globals->useGui) + return; + + for (int i = 0; i < dst.size(); i++) { + qImageBuffer = toQImage(dst[i].m()); + displayBuffer->convertFromImage(qImageBuffer); + + emit updateImage(displayBuffer->copy(displayBuffer->rect())); + + // Blocking wait for a key-press + if (this->waitInput) { + gui->waitForKey(dst[i]); + qDebug() << dst[i].file.get("leftEye"); + qDebug() << dst[i].file.get("rightEye"); + } + } + } + + void init() + { + if (!Globals->useGui) + return; + + displayBuffer = new QPixmap(); + + // Create our GUI proxy + gui = new EyeProxy(); + + // 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))); + emit needWindow(); + connect(this, SIGNAL(hideWindow()), gui->window, SLOT(hide())); + } +}; + +BR_REGISTER(Transform, ManualTransform) + class FPSLimit : public TimeVaryingTransform { Q_OBJECT diff --git a/openbr/plugins/regions.cpp b/openbr/plugins/regions.cpp index 0a20202..5ccc96b 100644 --- a/openbr/plugins/regions.cpp +++ b/openbr/plugins/regions.cpp @@ -15,7 +15,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include - +#include "openbr/core/qtutils.h" #include "openbr_internal.h" #include "openbr/core/opencvutils.h" @@ -239,6 +239,7 @@ BR_REGISTER(Transform, ExpandRectTransform) * \ingroup transforms * \brief Crops the width and height of a template's rects by input width and height factors. * \author Scott Klum \cite sklum + * \todo Error checking */ class CropRectTransform : public UntrainableTransform { @@ -257,12 +258,12 @@ class CropRectTransform : public UntrainableTransform QRectF rect = rects[i]; // Do a bit of error checking - rect.x += rect.width * QtUtils::toPoint(widthCrop).x(); - rect.y += rect.height * QtUtils::toPoint(heightCrop).x(); - rect.width *= 1-QtUtils::toPoint(widthCrop).y(); - rect.height *= 1-QtUtils::toPoint(heightCrop).y(); + rect.setX(rect.x() + rect.width() * QtUtils::toPoint(widthCrop).x()); + rect.setY(rect.y() + rect.height() * QtUtils::toPoint(heightCrop).x()); + rect.setWidth(rect.width() * (1-QtUtils::toPoint(widthCrop).y())); + rect.setHeight(rect.height() * (1-QtUtils::toPoint(heightCrop).y())); - dst.m() = Mat(dst.m(), rect); + dst.m() = Mat(dst.m(), OpenCVUtils::toRect(rect)); } dst.file.setRects(rects); } -- libgit2 0.21.4