From aa066bdd4622d4f6824fee864f6be6806813f04d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 30 Oct 2015 07:37:41 +0100 Subject: move to subdirectory-based build system Closes #224 --- ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 225 -------------------------------- ftnoir_tracker_ht/ftnoir_tracker_ht.h | 90 ------------- ftnoir_tracker_ht/headtracker-ftnoir.h | 24 ---- ftnoir_tracker_ht/ht-api.h | 51 -------- ftnoir_tracker_ht/ht-tracker.qrc | 5 - ftnoir_tracker_ht/ht-trackercontrols.ui | 157 ---------------------- ftnoir_tracker_ht/ht_video_widget.cpp | 53 -------- ftnoir_tracker_ht/ht_video_widget.h | 39 ------ ftnoir_tracker_ht/images/ht.png | Bin 2010 -> 0 bytes 9 files changed, 644 deletions(-) delete mode 100644 ftnoir_tracker_ht/ftnoir_tracker_ht.cpp delete mode 100644 ftnoir_tracker_ht/ftnoir_tracker_ht.h delete mode 100644 ftnoir_tracker_ht/headtracker-ftnoir.h delete mode 100644 ftnoir_tracker_ht/ht-api.h delete mode 100644 ftnoir_tracker_ht/ht-tracker.qrc delete mode 100644 ftnoir_tracker_ht/ht-trackercontrols.ui delete mode 100644 ftnoir_tracker_ht/ht_video_widget.cpp delete mode 100644 ftnoir_tracker_ht/ht_video_widget.h delete mode 100644 ftnoir_tracker_ht/images/ht.png (limited to 'ftnoir_tracker_ht') diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp deleted file mode 100644 index cc9d2ba1..00000000 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#include "headtracker-ftnoir.h" -#include "ftnoir_tracker_ht.h" -#include "ui_ht-trackercontrols.h" -#include "opentrack/plugin-api.hpp" -#include -#include "opentrack/camera-names.hpp" -#include "opentrack-compat/sleep.hpp" - -typedef struct { - int width; - int height; -} resolution_tuple; - -static resolution_tuple resolution_choices[] = { - { 640, 480 }, - { 320, 240 }, - { 320, 200 }, - { 0, 0 } -}; - -void Tracker::load_settings(ht_config_t* config) -{ - int nframes = 0; - switch (static_cast(s.fps)) - { - default: - case 0: - nframes = 0; - break; - case 1: - nframes = 30; - break; - case 2: - nframes = 60; - break; - case 3: - nframes = 120; - break; - case 4: - nframes = 180; - break; - } - - config->classification_delay = 500; - config->field_of_view = s.fov; - config->max_keypoints = 150; - config->keypoint_distance = 3.5; - config->force_fps = nframes; - config->camera_index = camera_name_to_index(s.camera_name); - - config->ransac_max_reprojection_error = 25; - config->ransac_max_inlier_error = config->ransac_max_reprojection_error; - - config->pyrlk_pyramids = 0; - config->pyrlk_win_size_w = config->pyrlk_win_size_h = 21; - - config->ransac_max_mean_error = 999; - config->ransac_abs_max_mean_error = 999; - - config->debug = 1; - config->ransac_min_features = 0.95; - config->ransac_num_iters = 300; - - int res = s.resolution; - if (res < 0 || res >= (int)(sizeof(resolution_choices) / sizeof(resolution_tuple))) - res = 0; - resolution_tuple r = resolution_choices[res]; - config->force_width = r.width; - config->force_height = r.height; - config->flandmark_delay = 50; - for (int i = 0; i < 5; i++) - config->dist_coeffs[i] = 0; -} - -Tracker::Tracker() : - ht(nullptr), - ypr {0,0,0, 0,0,0}, - videoWidget(nullptr), - layout(nullptr), - should_stop(false) -{ -} - -Tracker::~Tracker() -{ - should_stop = true; - wait(); - ht_free_context(ht); - if (layout) - delete layout; - if (videoWidget) - delete videoWidget; -} - -void Tracker::start_tracker(QFrame* videoframe) -{ - videoframe->show(); - videoWidget = new HTVideoWidget(videoframe); - QHBoxLayout* layout = new QHBoxLayout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(videoWidget); - if (videoframe->layout()) - delete videoframe->layout(); - videoframe->setLayout(layout); - videoWidget->show(); - this->layout = layout; - - load_settings(&conf); - ht = ht_make_context(&conf, nullptr); - start(); -} - -void Tracker::run() -{ - while (!should_stop) - { - ht_result_t euler; - euler.filled = false; - { - QMutexLocker l(&camera_mtx); - - if (!ht_cycle(ht, &euler)) - break; - } - if (euler.filled) - { - QMutexLocker l(&ypr_mtx); - ypr[TX] = euler.tx; - ypr[TY] = euler.ty; - ypr[TZ] = euler.tz; - ypr[Yaw] = euler.rotx; - ypr[Pitch] = euler.roty; - ypr[Roll] = euler.rotz; - } - { - const cv::Mat frame_ = ht_get_bgr_frame(ht); - if (frame_.cols <= HT_MAX_VIDEO_WIDTH && frame_.rows <= HT_MAX_VIDEO_HEIGHT && frame_.channels() <= HT_MAX_VIDEO_CHANNELS) - { - QMutexLocker l(&frame_mtx); - - const int cols = frame_.cols; - const int rows = frame_.rows; - const int pitch = cols * 3; - for (int y = 0; y < rows; y++) - { - for (int x = 0; x < cols; x++) - { - unsigned char* dest = &frame.frame[y * pitch + 3 * x]; - const cv::Vec3b& elt = frame_.at(y, x); - const cv::Scalar elt2 = static_cast(elt); - dest[0] = elt2.val[0]; - dest[1] = elt2.val[1]; - dest[2] = elt2.val[2]; - } - } - frame.channels = frame_.channels(); - frame.width = frame_.cols; - frame.height = frame_.rows; - } - } - } - // give opencv time to exit camera threads, etc. - portable::sleep(500); -} - -void Tracker::data(double* data) -{ - { - QMutexLocker l(&frame_mtx); - - if (frame.width > 0) - { - videoWidget->update_image(frame.frame, frame.width, frame.height); - frame.width = 0; - } - } - - { - QMutexLocker l(&ypr_mtx); - - for (int i = 0; i < 6; i++) - data[i] = ypr[i]; - } -} - -TrackerControls::TrackerControls() : tracker(nullptr) -{ - ui.setupUi(this); - ui.cameraName->clear(); - QList names = get_camera_names(); - names.prepend("Any available"); - ui.cameraName->addItems(names); - tie_setting(s.camera_name, ui.cameraName); - tie_setting(s.fps, ui.cameraFPS); - tie_setting(s.fov, ui.cameraFOV); - tie_setting(s.resolution, ui.resolution); - connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); - connect(ui.camera_settings, SIGNAL(pressed()), this, SLOT(camera_settings())); -} - -void TrackerControls::doOK() -{ - s.b->save(); - this->close(); -} - -void TrackerControls::doCancel() -{ - s.b->reload(); - this->close(); -} - -void TrackerControls::camera_settings() -{ - if (tracker) - { - cv::VideoCapture* cap = ht_capture(tracker->ht); - open_camera_settings(cap, s.camera_name, &tracker->camera_mtx); - } - else - open_camera_settings(nullptr, s.camera_name, nullptr); -} - -OPENTRACK_DECLARE_TRACKER(Tracker, TrackerControls, TrackerDll) diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.h b/ftnoir_tracker_ht/ftnoir_tracker_ht.h deleted file mode 100644 index 1e364456..00000000 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.h +++ /dev/null @@ -1,90 +0,0 @@ -/* Copyright (c) 2013 Stanislaw Halik - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#pragma once - -#include "headtracker-ftnoir.h" -#include "ui_ht-trackercontrols.h" -#include "ht_video_widget.h" -#include "opentrack-compat/shm.h" -#include -#include "opentrack/options.hpp" -#include "opentrack/plugin-api.hpp" -#include "opentrack/opencv-camera-dialog.hpp" - -#include -#include -#include -#include -#include - -using namespace options; - -struct settings : opts { - value fov; - value camera_name; - value fps, resolution; - settings() : - opts("HT-Tracker"), - fov(b, "fov", 56), - camera_name(b, "camera-name", ""), - fps(b, "fps", 0), - resolution(b, "resolution", 0) - {} -}; - -class Tracker : public QThread, public ITracker -{ - Q_OBJECT -public: - Tracker(); - ~Tracker() override; - void run() override; - void start_tracker(QFrame* frame) override; - void data(double *data) override; - void load_settings(ht_config_t* config); - headtracker_t* ht; - QMutex camera_mtx; -private: - double ypr[6]; - settings s; - ht_config_t conf; - HTVideoWidget* videoWidget; - QHBoxLayout* layout; - QMutex ypr_mtx, frame_mtx; - ht_video_t frame; - volatile bool should_stop; -}; - -class TrackerControls : public ITrackerDialog, protected camera_dialog -{ - Q_OBJECT -public: - TrackerControls(); - void register_tracker(ITracker * t) override - { - tracker = static_cast(t); - } - void unregister_tracker() override - { - tracker = nullptr; - } -private: - Ui::Form ui; - settings s; - Tracker* tracker; -private slots: - void doOK(); - void doCancel(); - void camera_settings(); -}; - -class TrackerDll : public Metadata -{ - QString name() { return QString("ht -- face tracker"); } - QIcon icon() { return QIcon(":/images/ht.png"); } -}; diff --git a/ftnoir_tracker_ht/headtracker-ftnoir.h b/ftnoir_tracker_ht/headtracker-ftnoir.h deleted file mode 100644 index 9a343bae..00000000 --- a/ftnoir_tracker_ht/headtracker-ftnoir.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include -#include -#include "ht-api.h" - -#define HT_SHM_NAME "ftnoir-tracker-ht-shm" -#define HT_MUTEX_NAME "ftnoir-tracker-ht-mutex" - -#define HT_MAX_VIDEO_WIDTH 640 -#define HT_MAX_VIDEO_HEIGHT 480 -#define HT_MAX_VIDEO_CHANNELS 3 - -typedef struct { - int width, height, channels; - unsigned char frame[HT_MAX_VIDEO_WIDTH * HT_MAX_VIDEO_HEIGHT * HT_MAX_VIDEO_CHANNELS]; -} ht_video_t; - -typedef struct { - ht_video_t frame; - ht_config_t config; - ht_result_t result; - volatile int timer; - volatile bool pause, terminate, running; -} ht_shm_t; diff --git a/ftnoir_tracker_ht/ht-api.h b/ftnoir_tracker_ht/ht-api.h deleted file mode 100644 index 4629a00b..00000000 --- a/ftnoir_tracker_ht/ht-api.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once -#ifndef HT_API -# if defined(_WIN32) && !defined(MINGW) -# define HT_API(t) __declspec(dllexport) t __stdcall -# else -# define HT_API(t) t -# endif -#endif -#if !defined(_WIN32) && !defined(_isnan) -# define _isnan isnan -#endif -#include -#include -struct ht_context; -typedef struct ht_context headtracker_t; - -typedef struct ht_config { - float field_of_view; - float classification_delay; - int pyrlk_pyramids; - int pyrlk_win_size_w; - int pyrlk_win_size_h; - float ransac_max_inlier_error; - float ransac_max_reprojection_error; - int max_keypoints; - float keypoint_distance; - int force_width; - int force_height; - int force_fps; - int camera_index; - bool debug; - int ransac_num_iters; - float ransac_min_features; - float ransac_max_mean_error; - float ransac_abs_max_mean_error; - float flandmark_delay; - double dist_coeffs[5]; -} ht_config_t; - -typedef struct { - double rotx, roty, rotz; - double tx, ty, tz; - bool filled; -} ht_result_t; - -HT_API(headtracker_t*) ht_make_context(const ht_config_t* config, const char* filename); -HT_API(void) ht_free_context(headtracker_t* ctx); -HT_API(const cv::Mat) ht_get_bgr_frame(headtracker_t* ctx); -HT_API(bool) ht_cycle(headtracker_t* ctx, ht_result_t* euler); -HT_API(void) ht_reset(headtracker_t* ctx); -HT_API(cv::VideoCapture*) ht_capture(headtracker_t* ctx); diff --git a/ftnoir_tracker_ht/ht-tracker.qrc b/ftnoir_tracker_ht/ht-tracker.qrc deleted file mode 100644 index b6af7a18..00000000 --- a/ftnoir_tracker_ht/ht-tracker.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - images/ht.png - - diff --git a/ftnoir_tracker_ht/ht-trackercontrols.ui b/ftnoir_tracker_ht/ht-trackercontrols.ui deleted file mode 100644 index 29b80c8d..00000000 --- a/ftnoir_tracker_ht/ht-trackercontrols.ui +++ /dev/null @@ -1,157 +0,0 @@ - - - Form - - - Qt::NonModal - - - - 0 - 0 - 354 - 179 - - - - - 0 - 0 - - - - - 750 - 280 - - - - HT tracker settings - - - - - - Frames per second - - - - - - - - - - 35.000000000000000 - - - 180.000000000000000 - - - 52.000000000000000 - - - - - - - Diagonal FOV - - - - - - - - Default - - - - - 30 - - - - - 60 - - - - - 120 - - - - - 180 - - - - - - - - - - - - 640x480 - - - - - 320x240 - - - - - 320x200 - - - - - Default (not recommended!) - - - - - - - - Resolution - - - - - - - Camera name - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - Camera settings - - - - - - - Open - - - - - - - - diff --git a/ftnoir_tracker_ht/ht_video_widget.cpp b/ftnoir_tracker_ht/ht_video_widget.cpp deleted file mode 100644 index 02fe71d1..00000000 --- a/ftnoir_tracker_ht/ht_video_widget.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (c) 2014 Stanislaw Halik - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ - -#include "ht_video_widget.h" - -void HTVideoWidget::update_image(unsigned char *frame, int width, int height) -{ - QMutexLocker foo(&mtx); - if (!fresh) - { - memcpy(fb, frame, width * height * 3); - this->width = width; - this->height = height; - fresh = true; - } -} - -void HTVideoWidget::update_and_repaint() -{ - QImage qframe; - { - QMutexLocker foo(&mtx); - if (width*height <= 0 || !fresh) - return; - fresh = false; - qframe = QImage(width, height, QImage::Format_RGB888); - uchar* data = qframe.bits(); - const int pitch = qframe.bytesPerLine(); - for (int y = 0; y < height; y++) - { - const int part = y*width; - for (int x = 0; x < width; x++) - { - const int pos = 3 * (part + x); - const int x_ = x * 3; - data[x_ + 0] = fb[pos + 2]; - data[x_ + 1] = fb[pos + 1]; - data[x_ + 2] = fb[pos + 0]; - } - data += pitch; - } - } - qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); - { - QMutexLocker foo(&mtx); - texture = qframe; - } - update(); -} diff --git a/ftnoir_tracker_ht/ht_video_widget.h b/ftnoir_tracker_ht/ht_video_widget.h deleted file mode 100644 index 054b2cf4..00000000 --- a/ftnoir_tracker_ht/ht_video_widget.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (c) 2014 Stanislaw Halik - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ -#pragma once - -#include -#include -#include -#include -#include -#include - -class HTVideoWidget : public QWidget -{ - Q_OBJECT -public: - HTVideoWidget(QWidget *parent) : QWidget(parent), fb(), width(0), height(0), fresh(false) { - connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); - timer.start(60); - } - void update_image(unsigned char* frame, int width, int height); -protected slots: - void paintEvent( QPaintEvent* e ) { - QMutexLocker foo(&mtx); - QPainter painter(this); - painter.drawImage(e->rect(), texture); - } - void update_and_repaint(); -private: - QMutex mtx; - QImage texture; - QTimer timer; - unsigned char fb[2048*2048*3]; - int width,height; - bool fresh; -}; diff --git a/ftnoir_tracker_ht/images/ht.png b/ftnoir_tracker_ht/images/ht.png deleted file mode 100644 index 19c73d21..00000000 Binary files a/ftnoir_tracker_ht/images/ht.png and /dev/null differ -- cgit v1.2.3