From b24e6ee805e8b84125d5d2e7475e0e91a86612c3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 10 Jan 2018 07:13:23 +0100 Subject: tracker/ht: remove --- tracker-ht/CMakeLists.txt | 12 --- tracker-ht/ftnoir_tracker_ht.cpp | 224 --------------------------------------- tracker-ht/ftnoir_tracker_ht.h | 90 ---------------- tracker-ht/headtracker-ftnoir.h | 24 ----- tracker-ht/ht-api.h | 51 --------- tracker-ht/ht-tracker.qrc | 5 - tracker-ht/ht-trackercontrols.ui | 157 --------------------------- tracker-ht/ht_video_widget.cpp | 53 --------- tracker-ht/ht_video_widget.h | 39 ------- tracker-ht/images/ht.png | Bin 2010 -> 0 bytes 10 files changed, 655 deletions(-) delete mode 100644 tracker-ht/CMakeLists.txt delete mode 100644 tracker-ht/ftnoir_tracker_ht.cpp delete mode 100644 tracker-ht/ftnoir_tracker_ht.h delete mode 100644 tracker-ht/headtracker-ftnoir.h delete mode 100644 tracker-ht/ht-api.h delete mode 100644 tracker-ht/ht-tracker.qrc delete mode 100644 tracker-ht/ht-trackercontrols.ui delete mode 100644 tracker-ht/ht_video_widget.cpp delete mode 100644 tracker-ht/ht_video_widget.h delete mode 100644 tracker-ht/images/ht.png (limited to 'tracker-ht') diff --git a/tracker-ht/CMakeLists.txt b/tracker-ht/CMakeLists.txt deleted file mode 100644 index 86684799..00000000 --- a/tracker-ht/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -if(FALSE) -set(SDK_HT "" CACHE FILEPATH "Path to headtracker library") -set(SDK_HT_FLANDMARK "" CACHE FILEPATH "Path to flandmark library for headtracker") -find_package(OpenCV 3.0 QUIET COMPONENTS ${opencv-modules}) -if(OpenCV_FOUND) - if(SDK_HT AND SDK_HT_FLANDMARK) - otr_module(tracker-ht) - target_link_libraries(opentrack-tracker-ht ${SDK_HT} ${SDK_HT_FLANDMARK} ${OpenCV_LIBS}) - target_include_directories(opentrack-tracker-ht SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS}) - endif() -endif() -endif() diff --git a/tracker-ht/ftnoir_tracker_ht.cpp b/tracker-ht/ftnoir_tracker_ht.cpp deleted file mode 100644 index 045d05f8..00000000 --- a/tracker-ht/ftnoir_tracker_ht.cpp +++ /dev/null @@ -1,224 +0,0 @@ -#include "headtracker-ftnoir.h" -#include "ftnoir_tracker_ht.h" -#include "ui_ht-trackercontrols.h" -#include "api/plugin-api.hpp" -#include -#include "api/camera-names.hpp" -#include "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(); - 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(); - close(); -} - -void TrackerControls::doCancel() -{ - 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/tracker-ht/ftnoir_tracker_ht.h b/tracker-ht/ftnoir_tracker_ht.h deleted file mode 100644 index a29b3f20..00000000 --- a/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 "compat/shm.h" -#include -#include "options/options.hpp" -#include "api/plugin-api.hpp" -#include "api/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/tracker-ht/headtracker-ftnoir.h b/tracker-ht/headtracker-ftnoir.h deleted file mode 100644 index 9a343bae..00000000 --- a/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/tracker-ht/ht-api.h b/tracker-ht/ht-api.h deleted file mode 100644 index 4629a00b..00000000 --- a/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/tracker-ht/ht-tracker.qrc b/tracker-ht/ht-tracker.qrc deleted file mode 100644 index b6af7a18..00000000 --- a/tracker-ht/ht-tracker.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - images/ht.png - - diff --git a/tracker-ht/ht-trackercontrols.ui b/tracker-ht/ht-trackercontrols.ui deleted file mode 100644 index 29b80c8d..00000000 --- a/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/tracker-ht/ht_video_widget.cpp b/tracker-ht/ht_video_widget.cpp deleted file mode 100644 index b62b9892..00000000 --- a/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) - { - width = width_; - height = height_; - fresh = true; - memcpy(fb, frame, width_ * height_ * 3); - } -} - -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/tracker-ht/ht_video_widget.h b/tracker-ht/ht_video_widget.h deleted file mode 100644 index 054b2cf4..00000000 --- a/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/tracker-ht/images/ht.png b/tracker-ht/images/ht.png deleted file mode 100644 index 19c73d21..00000000 Binary files a/tracker-ht/images/ht.png and /dev/null differ -- cgit v1.2.3