From bef7aff31e5ea073f0f160ca6a2f1e56b7dd881a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 15 Sep 2013 12:39:32 +0200 Subject: Initial PT 1.1 import Codebase broken at this stage --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 1856 +++++++++++++++++++++++++++++++ 1 file changed, 1856 insertions(+) create mode 100644 FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui new file mode 100644 index 00000000..7bb7eb50 --- /dev/null +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -0,0 +1,1856 @@ + + + UICPTClientControls + + + Qt::ApplicationModal + + + + 0 + 0 + 395 + 552 + + + + + 0 + 0 + + + + PointTracker Settings + + + + :/Resources/icon.ico:/Resources/icon.ico + + + Qt::LeftToRight + + + false + + + + QLayout::SetFixedSize + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + 0 + + + + General + + + + + + Tracker Thread + + + + + + + + + + + Dynamic Pose Resolution + + + + + + + Sleep time + + + sleep_spin + + + + + + + + + Time the tracker thread sleeps after each processed frame + + + + + + 9999 + + + + + + + ms + + + + + + + + + Auto-reset time + + + reset_spin + + + + + + + + + Time until automatic reset of tracker's internal state when no valid tracking result is found + + + 9999 + + + + + + + ms + + + + + + + + + Whether to update the content of the VideoWidget + + + Show VideoWidget + + + + + + + Qt::Horizontal + + + + 30 + 20 + + + + + + + + Qt::Horizontal + + + + 30 + 20 + + + + + + + + false + + + Reset the tracker's internal state + + + Reset + + + + + + + + + + + + + 0 + 85 + + + + Enable Axis + + + + + + + + Roll: + + + chkEnableRoll + + + + + + + Pitch: + + + chkEnablePitch + + + + + + + Yaw: + + + chkEnableYaw + + + + + + + + 20 + 16777215 + + + + Qt::LeftToRight + + + + + + + + + + + + + + 20 + 16777215 + + + + Qt::LeftToRight + + + + + + + + + + + 20 + 16777215 + + + + Qt::LeftToRight + + + + + + + + + + X: + + + chkEnableX + + + + + + + + 20 + 16777215 + + + + Qt::LeftToRight + + + + + + + + + + Y: + + + chkEnableY + + + + + + + + 20 + 16777215 + + + + Qt::LeftToRight + + + + + + + + + + Z: + + + chkEnableZ + + + + + + + + 20 + 16777215 + + + + Qt::LeftToRight + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + Camera + + + + + + The camera device used as input + + + Camera Settings + + + + + + + + + 55 + 0 + + + + Device + + + camdevice_combo + + + + + + + + 0 + 0 + + + + Camera device used as input + + + + + + + + + + + + + + 55 + 0 + + + + Resolution + + + + + + + FPS + + + fps_spin + + + + + + + + 0 + 0 + + + + Desired capture framerate + + + 999 + + + + + + + x + + + + + + + + 0 + 0 + + + + Desired capture width + + + 2000 + + + 10 + + + + + + + Desired capture height + + + 2000 + + + 10 + + + + + + + F/W + + + f_dspin + + + + + + + The camera's focal length devided by its sensor width + + + 2 + + + 0.100000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + + + false + + + + 130 + 0 + + + + + + + VideoWidget + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + + Camera Orientation + + + + + + + + + + Pitch + + + campitch_spin + + + + + + + Qt::DefaultContextMenu + + + The angle the camera is facing upwards + + + -99 + + + + + + + Yaw + + + camyaw_spin + + + + + + + Qt::DefaultContextMenu + + + The angle the camera is facing leftwards + + + -99 + + + + + + + deg (positve = leftwards) + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Rotation of the camera image + + + + + + + deg (positive = upwards) + + + + + + + deg + + + + + + + Roll + + + camroll_combo + + + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + Point Extraction + + + + + + + + Threshold + + + threshold_slider + + + + + + + Intensity threshold for point extraction + + + 255 + + + 127 + + + Qt::Horizontal + + + + + + + + + + + Min Diameter + + + mindiam_spin + + + + + + + Minimum point diameter + + + + + + + px + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Max Diameter + + + maxdiam_spin + + + + + + + Maximum point diameter + + + + + + + px + + + + + + + + + + + + + Model + + + + + + QTabWidget::Rounded + + + 2 + + + false + + + false + + + false + + + + Clip + + + + + + Model Dimensions (mm) + + + + + + + 0 + 0 + + + + + 150 + 160 + + + + + + 30 + 30 + 71 + 111 + + + + + + + :/Resources/clip_side.png + + + + + + 100 + 50 + 46 + 22 + + + + 999 + + + + + + 60 + 10 + 46 + 22 + + + + 999 + + + + + + 100 + 90 + 46 + 22 + + + + 999 + + + + + + 10 + 10 + 46 + 13 + + + + Side + + + + + + 40 + 140 + 46 + 22 + + + + 999 + + + + + + 70 + 70 + 16 + 16 + + + + R + + + + + + + + + 0 + 0 + + + + + 100 + 140 + + + + + + 10 + 10 + 46 + 13 + + + + Front + + + + + + 40 + 30 + 21 + 111 + + + + + + + :/Resources/clip_front.png + + + + + + 60 + 70 + 16 + 16 + + + + R + + + + + + + + + + + + Cap + + + + + + Model Dimensions (mm) + + + + + + + 140 + 130 + + + + + + 20 + 50 + 111 + 81 + + + + + + + :/Resources/cap_side.png + + + + + + 30 + 80 + 46 + 22 + + + + 999 + + + + + + 130 + 50 + 16 + 16 + + + + R + + + + + + 10 + 10 + 46 + 13 + + + + Side + + + + + + 50 + 40 + 46 + 22 + + + + 999 + + + + + + + + + 0 + 0 + + + + + 100 + 130 + + + + + + 10 + 10 + 46 + 13 + + + + Front + + + + + + 30 + 50 + 16 + 16 + + + + R + + + + + + 10 + 50 + 81 + 81 + + + + + + + :/Resources/cap_front.png + + + + + + 50 + 30 + 46 + 22 + + + + 999 + + + + + + + + + + + + Custom + + + + + + Model Dimensions (mm) + + + + + + <html><head/><body><p>Location of the two remaining model points<br/>with respect to the reference point in default pose</p></body></html> + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + + Qt::Horizontal + + + + 10 + 20 + + + + + + + + + + -999 + + + 999 + + + + + + + y: + + + + + + + -999 + + + 999 + + + + + + + z: + + + + + + + M1: + + + + + + + -999 + + + 999 + + + + + + + x: + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + + -999 + + + 999 + + + + + + + x: + + + + + + + z: + + + + + + + -999 + + + 999 + + + + + + + y: + + + + + + + M2: + + + + + + + + + + -999 + + + 999 + + + + + + + + + Qt::Horizontal + + + + 10 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + + + + + + + Model Position (mm) + + + + + + <html><head/><body><p>Translation from head center to model reference point<br/> in default pose</p></body></html> + + + + + + + + + Qt::Horizontal + + + + 10 + 20 + + + + + + + + + + + + + -999 + + + 999 + + + + + + + x: + + + + + + + y: + + + + + + + z: + + + + + + + -999 + + + 999 + + + + + + + -999 + + + 999 + + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + false + + + Calibrate + + + true + + + + + + + Qt::Horizontal + + + + 10 + 20 + + + + + + + + + + + + + + About + + + + + 30 + 30 + 161 + 111 + + + + <html><head/><body><p><span style=" font-weight:600;">FTNoIR PointTracker Plugin<br/>Version 1.1</span></p><p><span style=" font-weight:600;">by Patrick Ruoff</span></p><p><a href="http://ftnoirpt.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">Manual (external)</span></a></p></body></html> + + + true + + + + + + 200 + 30 + 141 + 141 + + + + + + + :/Resources/Logo_IR.png + + + + + + + + + Status + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Camera Info: + + + + + + + + 0 + 0 + + + + + 120 + 0 + + + + + + + + + + + Extracted Points: + + + + + + + + 50 + 0 + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Ok + + + + + + + + + + Cancel + + + + + + + + + tabWidget + videowidget_check + sleep_spin + dynpose_check + reset_spin + reset_button + chkEnableRoll + chkEnablePitch + chkEnableYaw + chkEnableX + chkEnableY + chkEnableZ + camdevice_combo + res_x_spin + res_y_spin + fps_spin + f_dspin + camroll_combo + campitch_spin + camyaw_spin + threshold_slider + mindiam_spin + maxdiam_spin + model_tabs + clip_tlength_spin + clip_theight_spin + clip_bheight_spin + clip_blength_spin + cap_length_spin + cap_height_spin + cap_width_spin + m1x_spin + m1y_spin + m1z_spin + m2x_spin + m2y_spin + m2z_spin + tx_spin + ty_spin + tz_spin + tcalib_button + ok_button + cancel_button + + + + + + + dynpose_check + toggled(bool) + reset_spin + setEnabled(bool) + + + 172 + 110 + + + 351 + 112 + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + -- cgit v1.2.3 From 490f3ddb79018d13182fc17bb92943bbe427643d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 15 Sep 2013 15:00:56 +0200 Subject: New PT from Patrick Ruoff adapted to Linux --- CMakeLists.txt | 2 + FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 4 +- FTNoIR_Tracker_PT/boost-compat.h | 6 ++ FTNoIR_Tracker_PT/camera.cpp | 135 ++++++++++++++++++++----- FTNoIR_Tracker_PT/camera.h | 96 +++++++++--------- FTNoIR_Tracker_PT/frame_observer.cpp | 4 +- FTNoIR_Tracker_PT/frame_observer.h | 8 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 56 ++++++++-- FTNoIR_Tracker_PT/ftnoir_tracker_pt.h | 33 +++++- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp | 15 ++- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h | 6 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.cpp | 10 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.h | 18 +++- FTNoIR_Tracker_PT/point_extractor.cpp | 2 +- FTNoIR_Tracker_PT/point_extractor.h | 1 + FTNoIR_Tracker_PT/point_tracker.cpp | 31 +++++- FTNoIR_Tracker_PT/point_tracker.h | 6 +- FTNoIR_Tracker_PT/timer.cpp | 4 +- FTNoIR_Tracker_PT/video_widget.cpp | 58 ++++++++--- FTNoIR_Tracker_PT/video_widget.h | 47 ++++++++- facetracknoir/rotation.h | 18 ++-- facetracknoir/tracker_types.cpp | 12 +-- 22 files changed, 422 insertions(+), 150 deletions(-) create mode 100644 FTNoIR_Tracker_PT/boost-compat.h (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/CMakeLists.txt b/CMakeLists.txt index 0669fb74..6c5bed0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,8 @@ SET(CMAKE_SKIP_INSTALL_RPATH FALSE) SET(CMAKE_SKIP_RPATH FALSE) SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}") +add_definitions(-DOPENTRACK_API) + if(WIN32) SET(SDK_FACEAPI_ONLY FALSE CACHE BOOL "FaceAPI only (MSVC 2005)") endif() diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index 7bb7eb50..1495249a 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -9,8 +9,8 @@ 0 0 - 395 - 552 + 458 + 590 diff --git a/FTNoIR_Tracker_PT/boost-compat.h b/FTNoIR_Tracker_PT/boost-compat.h new file mode 100644 index 00000000..aea5e1a2 --- /dev/null +++ b/FTNoIR_Tracker_PT/boost-compat.h @@ -0,0 +1,6 @@ +#pragma once +#include +#define shared_ptr auto_ptr +namespace boost { + using std::auto_ptr; +}; diff --git a/FTNoIR_Tracker_PT/camera.cpp b/FTNoIR_Tracker_PT/camera.cpp index 21a910c1..a372373d 100644 --- a/FTNoIR_Tracker_PT/camera.cpp +++ b/FTNoIR_Tracker_PT/camera.cpp @@ -10,6 +10,69 @@ using namespace cv; +#if defined(OPENTRACK_API) && (defined(__unix) || defined(__linux)) +#include +#endif + +#ifdef OPENTRACK_API +void get_camera_device_names(std::vector& device_names) { +# if defined(_WIN32) + // Create the System Device Enumerator. + HRESULT hr; + ICreateDevEnum *pSysDevEnum = NULL; + hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum); + if (FAILED(hr)) + { + return ret; + } + // Obtain a class enumerator for the video compressor category. + IEnumMoniker *pEnumCat = NULL; + hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0); + + if (hr == S_OK) { + // Enumerate the monikers. + IMoniker *pMoniker = NULL; + ULONG cFetched; + while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) { + IPropertyBag *pPropBag; + hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); + if (SUCCEEDED(hr)) { + // To retrieve the filter's friendly name, do the following: + VARIANT varName; + VariantInit(&varName); + hr = pPropBag->Read(L"FriendlyName", &varName, 0); + if (SUCCEEDED(hr)) + { + device_names.push_back(std::string(reinterpret_cast(varName.bstrVal))); + } + VariantClear(&varName); + + ////// To create an instance of the filter, do the following: + ////IBaseFilter *pFilter; + ////hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, + //// (void**)&pFilter); + // Now add the filter to the graph. + //Remember to release pFilter later. + pPropBag->Release(); + } + pMoniker->Release(); + } + pEnumCat->Release(); + } + pSysDevEnum->Release(); +# else + for (int i = 0; i < 16; i++) { + char buf[128]; + sprintf(buf, "/dev/video%d", i); + if (access(buf, R_OK | W_OK) == 0) { + device_names.push_back(std::string(buf)); + } else { + continue; + } + } +# endif +} +#else // ---------------------------------------------------------------------------- void get_camera_device_names(std::vector& device_names) { @@ -22,6 +85,7 @@ void get_camera_device_names(std::vector& device_names) device_names.push_back(device_name); } } +#endif // ---------------------------------------------------------------------------- void Camera::set_device_index(int index) @@ -81,43 +145,49 @@ bool Camera::get_frame(float dt, cv::Mat* frame) } // ---------------------------------------------------------------------------- -/* +#ifdef OPENTRACK_API void CVCamera::start() { - cap = cvCreateCameraCapture(desired_index); + cap = new VideoCapture(desired_index); // extract camera info - if (cap) + if (cap->isOpened()) { active = true; active_index = desired_index; - cam_info.res_x = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH); - cam_info.res_y = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT); + cam_info.res_x = cap->get(CV_CAP_PROP_FRAME_WIDTH); + cam_info.res_y = cap->get(CV_CAP_PROP_FRAME_HEIGHT); } + else { + delete cap; + cap = NULL; + } } void CVCamera::stop() { - if (cap) cvReleaseCapture(&cap); + if (cap) + { + cap->release(); + delete cap; + } active = false; } bool CVCamera::_get_frame(Mat* frame) { - if (cap && cvGrabFrame(cap) != 0) + if (cap) { - // retrieve frame - IplImage* _img = cvRetrieveFrame(cap, 0); - if(_img) - { - if(_img->origin == IPL_ORIGIN_TL) - *frame = Mat(_img); - else - { - Mat temp(_img); - flip(temp, *frame, 0); - } - return true; - } + Mat img; + /* + * XXX some Windows webcams fail to decode first + * frames and then some every once in a while + * -sh + */ + while (!cap->read(img))\ + ;; + + *frame = img; + return true; } return false; } @@ -134,21 +204,30 @@ void CVCamera::_set_f() void CVCamera::_set_fps() { - if (cap) cvSetCaptureProperty(cap, CV_CAP_PROP_FPS, cam_desired.fps); + if (cap) cap->set(CV_CAP_PROP_FPS, cam_desired.fps); } void CVCamera::_set_res() { if (cap) { - cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH, cam_desired.res_x); - cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT, cam_desired.res_y); - cam_info.res_x = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH); - cam_info.res_y = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT); + cap->set(CV_CAP_PROP_FRAME_WIDTH, cam_desired.res_x); + cap->set(CV_CAP_PROP_FRAME_HEIGHT, cam_desired.res_y); + cam_info.res_x = cap->get(CV_CAP_PROP_FRAME_WIDTH); + cam_info.res_y = cap->get(CV_CAP_PROP_FRAME_HEIGHT); } } -*/ +void CVCamera::_set_device_index() +{ + if (cap) + { + cap->release(); + delete cap; + } + cap = new VideoCapture(desired_index); +} +#else // ---------------------------------------------------------------------------- VICamera::VICamera() : frame_buffer(NULL) { @@ -234,7 +313,7 @@ void VICamera::_set_res() { if (active) restart(); } - +#endif // ---------------------------------------------------------------------------- Mat FrameRotation::rotate_frame(Mat frame) @@ -260,4 +339,4 @@ Mat FrameRotation::rotate_frame(Mat frame) default: return frame; } -} \ No newline at end of file +} diff --git a/FTNoIR_Tracker_PT/camera.h b/FTNoIR_Tracker_PT/camera.h index c0876d0a..d1a8104c 100644 --- a/FTNoIR_Tracker_PT/camera.h +++ b/FTNoIR_Tracker_PT/camera.h @@ -9,8 +9,13 @@ #define CAMERA_H #include -#include "videoInput/videoInput.h" -#include +#ifndef OPENTRACK_API +# include +#else +# include "FTNoIR_Tracker_PT/boost-compat.h" +# include +# include +#endif #include // ---------------------------------------------------------------------------- @@ -33,50 +38,50 @@ struct CamInfo class Camera { public: - Camera() : dt_valid(0), dt_mean(0), desired_index(0), active_index(-1), active(false) {} - virtual ~Camera() {} + Camera() : dt_valid(0), dt_mean(0), desired_index(0), active_index(-1), active(false) {} + virtual ~Camera() {} - // start/stop capturing - virtual void start() = 0; - virtual void stop() = 0; - void restart() { stop(); start(); } + // start/stop capturing + virtual void start() = 0; + virtual void stop() = 0; + void restart() { stop(); start(); } - // calls corresponding template methods and reinitializes frame rate calculation - void set_device_index(int index); - void set_f(float f); - void set_fps(int fps); - void set_res(int x_res, int y_res); + // calls corresponding template methods and reinitializes frame rate calculation + void set_device_index(int index); + void set_f(float f); + void set_fps(int fps); + void set_res(int x_res, int y_res); - // gets a frame from the camera, dt: time since last call in seconds - bool get_frame(float dt, cv::Mat* frame); + // gets a frame from the camera, dt: time since last call in seconds + bool get_frame(float dt, cv::Mat* frame); - // WARNING: returned references are valid as long as object - const CamInfo& get_info() const { return cam_info; } - const CamInfo& get_desired() const { return cam_desired; } + // WARNING: returned references are valid as long as object + const CamInfo& get_info() const { return cam_info; } + const CamInfo& get_desired() const { return cam_desired; } protected: - // get a frame from the camera - virtual bool _get_frame(cv::Mat* frame) = 0; - - // update the camera using cam_desired, write res and f to cam_info if successful - virtual void _set_device_index() = 0; - virtual void _set_f() = 0; - virtual void _set_fps() = 0; - virtual void _set_res() = 0; - - bool active; - int desired_index; - int active_index; - CamInfo cam_info; - CamInfo cam_desired; - float dt_valid; - float dt_mean; + // get a frame from the camera + virtual bool _get_frame(cv::Mat* frame) = 0; + + // update the camera using cam_desired, write res and f to cam_info if successful + virtual void _set_device_index() = 0; + virtual void _set_f() = 0; + virtual void _set_fps() = 0; + virtual void _set_res() = 0; + + bool active; + int desired_index; + int active_index; + CamInfo cam_info; + CamInfo cam_desired; + float dt_valid; + float dt_mean; }; // ---------------------------------------------------------------------------- // camera based on OpenCV's videoCapture -/* +#ifdef OPENTRACK_API class CVCamera : public Camera { public: @@ -92,11 +97,11 @@ protected: virtual void _set_f(); virtual void _set_fps(); virtual void _set_res(); + virtual void _set_device_index(); - CvCapture* cap; + cv::VideoCapture* cap; }; -*/ - +#else // ---------------------------------------------------------------------------- // Camera based on the videoInput library class VICamera : public Camera @@ -119,19 +124,20 @@ protected: cv::Mat new_frame; unsigned char* frame_buffer; }; +#endif +enum RotationType +{ + CLOCKWISE = -1, + ZERO = 0, + COUNTER_CLOCKWISE = 1 +}; // ---------------------------------------------------------------------------- class FrameRotation { public: - typedef enum Rotation - { - CLOCKWISE = -1, - ZERO = 0, - COUNTER_CLOCKWISE = 1 - }; - Rotation rotation; + RotationType rotation; cv::Mat rotate_frame(cv::Mat frame); }; diff --git a/FTNoIR_Tracker_PT/frame_observer.cpp b/FTNoIR_Tracker_PT/frame_observer.cpp index 7e4bb3e3..281f3d57 100644 --- a/FTNoIR_Tracker_PT/frame_observer.cpp +++ b/FTNoIR_Tracker_PT/frame_observer.cpp @@ -11,8 +11,8 @@ FrameProvider::~FrameProvider() { QMutexLocker lock(&observer_mutex); - for (auto iter=frame_observers.begin(); iter!=frame_observers.end(); ++iter) + for (std::set::iterator iter=frame_observers.begin(); iter!=frame_observers.end(); ++iter) { (*iter)->on_frame_provider_destroy(); } -} \ No newline at end of file +} diff --git a/FTNoIR_Tracker_PT/frame_observer.h b/FTNoIR_Tracker_PT/frame_observer.h index 4afbd72c..585a6ee7 100644 --- a/FTNoIR_Tracker_PT/frame_observer.h +++ b/FTNoIR_Tracker_PT/frame_observer.h @@ -10,7 +10,11 @@ #include #include -#include +#ifndef OPENTRACK_API +# include +#else +# include "FTNoIR_Tracker_PT/boost-compat.h" +#endif #include //----------------------------------------------------------------------------- @@ -69,4 +73,4 @@ private: FrameObserver(const FrameObserver&); }; -#endif //FRAME_OBSERVER_H \ No newline at end of file +#endif //FRAME_OBSERVER_H diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp index 88a3fc8d..d4741101 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp @@ -12,6 +12,10 @@ #include #include +#ifdef OPENTRACK_API +# define VideoWidget VideoWidget2 +#endif + using namespace std; using namespace cv; using namespace boost; @@ -92,6 +96,9 @@ void Tracker::run() const std::vector& points = point_extractor.extract_points(frame, dt, has_observers()); tracking_valid = point_tracker.track(points, camera.get_info().f, dt); frame_count++; +#ifdef OPENTRACK_API + video_widget->update_image(frame); +#endif } #ifdef PT_PERF_LOG log_stream<<"dt: "<(settings.cam_roll); + frame_rotation.rotation = static_cast(settings.cam_roll); point_extractor.threshold_val = settings.threshold; point_extractor.min_size = settings.min_point_size; - point_extractor.max_size = settings.max_point_size; - point_tracker.point_model = boost::shared_ptr(new PointModel(settings.M01, settings.M02)); - point_tracker.dynamic_pose_resolution = settings.dyn_pose_res; + point_extractor.max_size = settings.max_point_size; +#ifdef OPENTRACK_API + point_tracker.point_model.reset(new PointModel(settings.M01, settings.M02)); +#else + point_tracker.point_model = boost::shared_ptr(new PointModel(settings.M01, settings.M02)); +#endif + point_tracker.dynamic_pose_resolution = settings.dyn_pose_res; sleep_time = settings.sleep_time; point_tracker.dt_reset = settings.reset_time / 1000.0; show_video_widget = settings.video_widget; @@ -181,7 +192,6 @@ void Tracker::update_show_video_widget() { const int VIDEO_FRAME_WIDTH = 252; const int VIDEO_FRAME_HEIGHT = 189; - video_widget = new VideoWidget(video_frame, this); QHBoxLayout* video_layout = new QHBoxLayout(); video_layout->setContentsMargins(0, 0, 0, 0); @@ -208,15 +218,28 @@ void Tracker::refreshVideo() if (video_widget) video_widget->update_frame_and_points(); } +#ifdef OPENTRACK_API +void Tracker::StartTracker(QFrame *parent_window) +#else void Tracker::StartTracker(HWND parent_window) +#endif { +#ifdef OPENTRACK_API + Initialize(parent_window); +#endif reset_command(PAUSE); } +#ifndef OPENTRACK_API void Tracker::StopTracker(bool exit) { set_command(PAUSE); } +#endif + +#ifdef OPENTRACK_API +#define THeadPoseData double +#endif bool Tracker::GiveHeadPoseData(THeadPoseData *data) { @@ -228,14 +251,20 @@ bool Tracker::GiveHeadPoseData(THeadPoseData *data) FrameTrafo X_CM = point_tracker.get_pose(); FrameTrafo X_MH(Matx33f::eye(), t_MH); FrameTrafo X_GH = R_GC * X_CM * X_MH; - Matx33f R = X_GH.R * X_GH_0.R.t(); + Matx33f R = X_GH.R * X_GH_0.R.t(); Vec3f t = X_GH.t - X_GH_0.t; +#ifndef OPENTRACK_API // get translation(s) if (bEnableX) data->x = t[0] / 10.0; // convert to cm if (bEnableY) data->y = t[1] / 10.0; if (bEnableZ) data->z = t[2] / 10.0; - +#else + // get translation(s) + if (bEnableX) data[TX] = t[0] / 10.0; // convert to cm + if (bEnableY) data[TY] = t[1] / 10.0; + if (bEnableZ) data[TZ] = t[2] / 10.0; +#endif // translate rotation matrix from opengl (G) to roll-pitch-yaw (E) frame // -z -> x, y -> z, x -> -y Matx33f R_EG( 0, 0,-1, @@ -249,17 +278,26 @@ bool Tracker::GiveHeadPoseData(THeadPoseData *data) alpha = atan2( R(1,0), R(0,0)); gamma = atan2( R(2,1), R(2,2)); +#ifndef OPENTRACK_API if (bEnableYaw) data->yaw = rad2deg * alpha; if (bEnablePitch) data->pitch = - rad2deg * beta; // FTNoIR expects a minus here if (bEnableRoll) data->roll = rad2deg * gamma; +#else + if (bEnableYaw) data[Yaw] = rad2deg * alpha; + if (bEnablePitch) data[Pitch] = - rad2deg * beta; // FTNoIR expects a minus here + if (bEnableRoll) data[Roll] = rad2deg * gamma; +#endif } return true; } //----------------------------------------------------------------------------- +#ifdef OPENTRACK_API +extern "C" FTNOIR_TRACKER_BASE_EXPORT ITracker* CALLING_CONVENTION GetConstructor() +#else #pragma comment(linker, "/export:GetTracker=_GetTracker@0") - FTNOIR_TRACKER_BASE_EXPORT ITrackerPtr __stdcall GetTracker() +#endif { return new Tracker; -} \ No newline at end of file +} diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h index 6eef945a..867378d1 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h @@ -8,7 +8,12 @@ #ifndef FTNOIR_TRACKER_PT_H #define FTNOIR_TRACKER_PT_H -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" +#ifdef OPENTRACK_API +# include "ftnoir_tracker_base/ftnoir_tracker_base.h" +# include "facetracknoir/global-settings.h" +#else +# include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" +#endif #include "ftnoir_tracker_pt_settings.h" #include "frame_observer.h" #include "camera.h" @@ -19,9 +24,14 @@ #include #include +#include #include #include -#include +#ifndef OPENTRACK_API +# include +#else +# include "FTNoIR_Tracker_PT/boost-compat.h" +#endif #include //----------------------------------------------------------------------------- @@ -34,10 +44,16 @@ public: // --- ITracker interface --- virtual void Initialize(QFrame *videoframe); +#ifdef OPENTRACK_API + virtual void StartTracker(QFrame* parent_window); + virtual void WaitForExit() {} + virtual bool GiveHeadPoseData(double* data); +#else virtual void StartTracker(HWND parent_window); - virtual void StopTracker(bool exit); - virtual bool GiveHeadPoseData(THeadPoseData *data); - virtual void refreshVideo(); + virtual void StopTracker(bool exit); + virtual bool GiveHeadPoseData(THeadPoseData *data); +#endif + virtual void refreshVideo(); void apply(const TrackerSettings& settings); void center(); @@ -66,7 +82,12 @@ protected: int sleep_time; // --- tracking chain --- +#ifdef OPENTRACK_API +#define VideoWidget VideoWidget2 + CVCamera camera; +#else VICamera camera; +#endif FrameRotation frame_rotation; PointExtractor point_extractor; PointTracker point_tracker; @@ -96,4 +117,6 @@ protected: Timer time; }; +#undef VideoWidget + #endif // FTNOIR_TRACKER_PT_H diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp index c99f4d67..fe995163 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp @@ -10,7 +10,11 @@ #include #include #include -#include +#ifndef OPENTRACK_API +# include +#else +# include "FTNoIR_Tracker_PT/boost-compat.h" +#endif #include using namespace std; @@ -39,7 +43,7 @@ TrackerDialog::TrackerDialog() vector device_names; get_camera_device_names(device_names); - for (auto iter = device_names.begin(); iter != device_names.end(); ++iter) + for (vector::iterator iter = device_names.begin(); iter != device_names.end(); ++iter) { ui.camdevice_combo->addItem(iter->c_str()); } @@ -398,9 +402,12 @@ void TrackerDialog::unRegisterTracker() } //----------------------------------------------------------------------------- +#ifdef OPENTRACK_API +extern "C" FTNOIR_TRACKER_BASE_EXPORT ITrackerDialog* CALLING_CONVENTION GetDialog( ) +#else #pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0") - FTNOIR_TRACKER_BASE_EXPORT ITrackerDialogPtr __stdcall GetTrackerDialog( ) +#endif { return new TrackerDialog; -} \ No newline at end of file +} diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h index bf0a90f2..14df7ede 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h @@ -8,7 +8,11 @@ #ifndef FTNOIR_TRACKER_PT_DIALOG_H #define FTNOIR_TRACKER_PT_DIALOG_H +#ifdef OPENTRACK_API +#include "ftnoir_tracker_base/ftnoir_tracker_base.h" +#else #include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" +#endif #include "ftnoir_tracker_pt_settings.h" #include "ftnoir_tracker_pt.h" #include "trans_calib.h" @@ -113,4 +117,4 @@ protected: Ui::UICPTClientControls ui; }; -#endif //FTNOIR_TRACKER_PT_DIALOG_H \ No newline at end of file +#endif //FTNOIR_TRACKER_PT_DIALOG_H diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.cpp index 3a73f679..be1705c0 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.cpp @@ -6,7 +6,6 @@ */ #include "ftnoir_tracker_pt_dll.h" - #include //----------------------------------------------------------------------------- @@ -31,10 +30,13 @@ void TrackerDll::getIcon(QIcon *icon) } -//----------------------------------------------------------------------------- -#pragma comment(linker, "/export:GetTrackerDll=_GetTrackerDll@0") - +#ifdef OPENTRACK_API +# include "facetracknoir/global-settings.h" +extern "C" FTNOIR_TRACKER_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata() +#else +# pragma comment(linker, "/export:GetTrackerDll=_GetTrackerDll@0") FTNOIR_TRACKER_BASE_EXPORT ITrackerDllPtr __stdcall GetTrackerDll() +#endif { return new TrackerDll; } diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.h index 15ad63aa..18283837 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.h @@ -5,15 +5,27 @@ * copyright notice and this permission notice appear in all copies. */ -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" +#if defined(OPENTRACK_API) +# include "ftnoir_tracker_base/ftnoir_tracker_base.h" +# include "facetracknoir/global-settings.h" +#else +# include "../ftnoir_tracker_base/ftnoir_tracker_base.h" +#endif //----------------------------------------------------------------------------- -class TrackerDll : public ITrackerDll +class TrackerDll : +#if defined(OPENTRACK_API) + public Metadata +#else + public ITrackerDll +#endif { // ITrackerDll interface +#ifndef OPENTRACK_API void Initialize() {} +#endif void getFullName(QString *strToBeFilled); void getShortName(QString *strToBeFilled); void getDescription(QString *strToBeFilled); void getIcon(QIcon *icon); -}; \ No newline at end of file +}; diff --git a/FTNoIR_Tracker_PT/point_extractor.cpp b/FTNoIR_Tracker_PT/point_extractor.cpp index 76a152a7..261de60f 100644 --- a/FTNoIR_Tracker_PT/point_extractor.cpp +++ b/FTNoIR_Tracker_PT/point_extractor.cpp @@ -22,7 +22,7 @@ const vector& PointExtractor::extract_points(Mat frame, float dt, bool dr // convert to grayscale Mat frame_gray; - cvtColor(frame, frame_gray, CV_RGB2GRAY); + cvtColor(frame, frame_gray, CV_RGB2GRAY); // convert to binary Mat frame_bin; diff --git a/FTNoIR_Tracker_PT/point_extractor.h b/FTNoIR_Tracker_PT/point_extractor.h index b142d2bb..c62d34f9 100644 --- a/FTNoIR_Tracker_PT/point_extractor.h +++ b/FTNoIR_Tracker_PT/point_extractor.h @@ -9,6 +9,7 @@ #define POINTEXTRACTOR_H #include +#include // ---------------------------------------------------------------------------- // Extracts points from an opencv image diff --git a/FTNoIR_Tracker_PT/point_tracker.cpp b/FTNoIR_Tracker_PT/point_tracker.cpp index acde9154..8b508897 100644 --- a/FTNoIR_Tracker_PT/point_tracker.cpp +++ b/FTNoIR_Tracker_PT/point_tracker.cpp @@ -69,6 +69,13 @@ PointModel::PointModel(Vec3f M01, Vec3f M02) get_d_order(points, d_order); } +#ifdef OPENTRACK_API +static bool d_vals_sort(const pair a, const pair b) +{ + return a.first < b.first; +} +#endif + void PointModel::get_d_order(const std::vector& points, int d_order[]) const { // get sort indices with respect to d scalar product @@ -77,10 +84,17 @@ void PointModel::get_d_order(const std::vector& points, int d_order[] d_vals.push_back(pair(d.dot(points[i]), i)); struct - { - bool operator()(const pair& a, const pair& b) { return a.first < b.first; } - } comp; - sort(d_vals.begin(), d_vals.end(), comp); + { + bool operator()(const pair& a, const pair& b) { return a.first < b.first; } + } comp; + std::sort(d_vals.begin(), + d_vals.end(), +#ifdef OPENTRACK_API + d_vals_sort +#else + comp +#endif + ); for (int i = 0; i& points, float f, float dt) reset(); } + bool no_model = +#ifdef OPENTRACK_API + point_model.get() == NULL; +#else + !point_model; +#endif + // if there is a pointtracking problem, reset the velocities - if (!point_model || points.size() != PointModel::N_POINTS) + if (no_model || points.size() != PointModel::N_POINTS) { //qDebug()<<"Wrong number of points!"; reset_velocities(); diff --git a/FTNoIR_Tracker_PT/point_tracker.h b/FTNoIR_Tracker_PT/point_tracker.h index f52e9dd7..11034100 100644 --- a/FTNoIR_Tracker_PT/point_tracker.h +++ b/FTNoIR_Tracker_PT/point_tracker.h @@ -9,7 +9,11 @@ #define POINTTRACKER_H #include -#include +#ifndef OPENTRACK_API +# include +#else +# include "FTNoIR_Tracker_PT/boost-compat.h" +#endif #include // ---------------------------------------------------------------------------- diff --git a/FTNoIR_Tracker_PT/timer.cpp b/FTNoIR_Tracker_PT/timer.cpp index 363b5b09..ed7606e5 100644 --- a/FTNoIR_Tracker_PT/timer.cpp +++ b/FTNoIR_Tracker_PT/timer.cpp @@ -55,7 +55,7 @@ double Timer::elapsed() startTime = startCount.QuadPart * (1e3 / frequency.QuadPart); endTime = endCount.QuadPart * (1e3 / frequency.QuadPart); #else - if(!stopped) + if(running) gettimeofday(&endCount, NULL); startTime = (startCount.tv_sec * 1e3) + startCount.tv_usec; @@ -63,4 +63,4 @@ double Timer::elapsed() #endif return endTime - startTime; -} \ No newline at end of file +} diff --git a/FTNoIR_Tracker_PT/video_widget.cpp b/FTNoIR_Tracker_PT/video_widget.cpp index 236faaf7..0d31620f 100644 --- a/FTNoIR_Tracker_PT/video_widget.cpp +++ b/FTNoIR_Tracker_PT/video_widget.cpp @@ -14,8 +14,10 @@ using namespace cv; using namespace std; +#ifndef OPENTRACK_API using namespace boost; - +#endif +#ifndef OPENTRACK_API // ---------------------------------------------------------------------------- void VideoWidget::initializeGL() { @@ -100,20 +102,44 @@ void VideoWidget::update_frame_and_points() updateGL(); } +#else +void VideoWidget2::update_image(const cv::Mat& frame) +{ + QMutexLocker foo(&mtx); + QImage qframe = QImage(frame.cols, frame.rows, QImage::Format_RGB888); + uchar* data = qframe.bits(); + const int pitch = qframe.bytesPerLine(); + for (int y = 0; y < frame.rows; y++) + for (int x = 0; x < frame.cols; x++) + { + const int pos = 3 * (y*frame.cols + x); + data[y * pitch + x * 3 + 0] = frame.data[pos + 2]; + data[y * pitch + x * 3 + 1] = frame.data[pos + 1]; + data[y * pitch + x * 3 + 2] = frame.data[pos + 0]; + } + qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); + pixmap = QPixmap::fromImage(qframe); +} +#endif + // ---------------------------------------------------------------------------- -VideoWidgetDialog::VideoWidgetDialog(QWidget *parent, FrameProvider* provider) - : QDialog(parent), - video_widget(NULL) +VideoWidgetDialog::VideoWidgetDialog(QWidget *parent, FrameProvider* provider) + : QDialog(parent), + video_widget(NULL) { - const int VIDEO_FRAME_WIDTH = 640; - const int VIDEO_FRAME_HEIGHT = 480; - - video_widget = new VideoWidget(this, provider); - - QHBoxLayout* layout = new QHBoxLayout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(video_widget); - if (this->layout()) delete this->layout(); - setLayout(layout); - resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT); -} \ No newline at end of file + const int VIDEO_FRAME_WIDTH = 640; + const int VIDEO_FRAME_HEIGHT = 480; + +#ifdef OPENTRACK_API + video_widget = new VideoWidget2(this, provider); +#else + video_widget = new VideoWidget(this, provider); +#endif + + QHBoxLayout* layout = new QHBoxLayout(); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(video_widget); + if (this->layout()) delete this->layout(); + setLayout(layout); + resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT); +} diff --git a/FTNoIR_Tracker_PT/video_widget.h b/FTNoIR_Tracker_PT/video_widget.h index dd5fb642..3164dacc 100644 --- a/FTNoIR_Tracker_PT/video_widget.h +++ b/FTNoIR_Tracker_PT/video_widget.h @@ -10,12 +10,23 @@ #include "frame_observer.h" -#include #include #include #include -#include +#ifndef OPENTRACK_API +# include +# include +#else +# include "FTNoIR_Tracker_PT/boost-compat.h" +# if defined(_WIN32) +# include +# endif +#endif +#include +#include +#include +#ifndef OPENTRACK_API // ---------------------------------------------------------------------------- // OpenGL based widget to display an OpenCV image with some points on top class VideoWidget : public QGLWidget, public FrameObserver @@ -23,7 +34,7 @@ class VideoWidget : public QGLWidget, public FrameObserver Q_OBJECT public: - VideoWidget(QWidget *parent, FrameProvider* provider) : QGLWidget(parent), FrameObserver(provider) {} + VideoWidget(QWidget *parent, FrameProvider* provider) : QGLWidget(parent), FrameObserver(provider) {} virtual void initializeGL(); virtual void resizeGL(int w, int h); @@ -40,19 +51,45 @@ private: boost::shared_ptr< std::vector > points; }; +#else +/* Qt moc likes to skip over preprocessor directives -sh */ +class VideoWidget2 : public QWidget, public FrameObserver +{ + Q_OBJECT + +public: + VideoWidget2(QWidget *parent, FrameProvider* provider) : QWidget(parent), /* to avoid linker errors */ FrameObserver(provider) { + connect(&timer, SIGNAL(timeout()), this, SLOT(update())); + timer.start(45); + } + void update_image(const cv::Mat &frame); + void update_frame_and_points() {} +protected slots: + void paintEvent( QPaintEvent* e ) { + QMutexLocker foo(&mtx); + QPainter painter(this); + painter.drawPixmap(e->rect(), pixmap, e->rect()); + } +private: + QMutex mtx; + QPixmap pixmap; + QTimer timer; +}; +#endif // ---------------------------------------------------------------------------- // A VideoWidget embedded in a dialog frame class VideoWidgetDialog : public QDialog { + Q_OBJECT public: VideoWidgetDialog(QWidget *parent, FrameProvider* provider); virtual ~VideoWidgetDialog() {} - VideoWidget* get_video_widget() { return video_widget; } + VideoWidget2* get_video_widget() { return video_widget; } private: - VideoWidget* video_widget; + VideoWidget2* video_widget; }; #endif // VIDEOWIDGET_H diff --git a/facetracknoir/rotation.h b/facetracknoir/rotation.h index e97ec0f0..747a23f9 100644 --- a/facetracknoir/rotation.h +++ b/facetracknoir/rotation.h @@ -9,15 +9,15 @@ #define ROTATION_H #include // ---------------------------------------------------------------------------- -class Rotation { +class RotationType { public: - Rotation() : a(1.0),b(0.0),c(0.0),d(0.0) {} - Rotation(double yaw, double pitch, double roll) { fromEuler(yaw, pitch, roll); } - Rotation(double a, double b, double c, double d) : a(a),b(b),c(c),d(d) {} + RotationType() : a(1.0),b(0.0),c(0.0),d(0.0) {} + RotationType(double yaw, double pitch, double roll) { fromEuler(yaw, pitch, roll); } + RotationType(double a, double b, double c, double d) : a(a),b(b),c(c),d(d) {} - Rotation inv(){ // inverse - return Rotation(a,-b,-c, -d); + RotationType inv(){ // inverse + return RotationType(a,-b,-c, -d); } @@ -46,10 +46,10 @@ public: yaw = atan2(2.0*(a*d + b*c), 1.0 - 2.0*(c*c + d*d)); } - const Rotation operator*(const Rotation& B) + const RotationType operator*(const RotationType& B) { - const Rotation& A = *this; - return Rotation(A.a*B.a - A.b*B.b - A.c*B.c - A.d*B.d, // quaternion multiplication + const RotationType& A = *this; + return RotationType(A.a*B.a - A.b*B.b - A.c*B.c - A.d*B.d, // quaternion multiplication A.a*B.b + A.b*B.a + A.c*B.d - A.d*B.c, A.a*B.c - A.b*B.d + A.c*B.a + A.d*B.b, A.a*B.d + A.b*B.c - A.c*B.b + A.d*B.a); diff --git a/facetracknoir/tracker_types.cpp b/facetracknoir/tracker_types.cpp index da246722..dec4ff81 100644 --- a/facetracknoir/tracker_types.cpp +++ b/facetracknoir/tracker_types.cpp @@ -7,9 +7,9 @@ T6DOF operator-(const T6DOF& A, const T6DOF& B) { - Rotation R_A(A.axes[Yaw]*D2R, A.axes[Pitch]*D2R, A.axes[Roll]*D2R); - Rotation R_B(B.axes[Yaw]*D2R, B.axes[Pitch]*D2R, B.axes[Roll]*D2R); - Rotation R_C = R_A * R_B.inv(); + RotationType R_A(A.axes[Yaw]*D2R, A.axes[Pitch]*D2R, A.axes[Roll]*D2R); + RotationType R_B(B.axes[Yaw]*D2R, B.axes[Pitch]*D2R, B.axes[Roll]*D2R); + RotationType R_C = R_A * R_B.inv(); T6DOF C; R_C.toEuler(C.axes[Yaw], C.axes[Pitch], C.axes[Roll]); @@ -26,9 +26,9 @@ T6DOF operator-(const T6DOF& A, const T6DOF& B) T6DOF operator+(const T6DOF& A, const T6DOF& B) { - Rotation R_A(A.axes[Yaw]*D2R, A.axes[Pitch]*D2R, A.axes[Roll]*D2R); - Rotation R_B(B.axes[Yaw]*D2R, B.axes[Pitch]*D2R, B.axes[Roll]*D2R); - Rotation R_C = R_A * R_B; + RotationType R_A(A.axes[Yaw]*D2R, A.axes[Pitch]*D2R, A.axes[Roll]*D2R); + RotationType R_B(B.axes[Yaw]*D2R, B.axes[Pitch]*D2R, B.axes[Roll]*D2R); + RotationType R_C = R_A * R_B; T6DOF C; R_C.toEuler(C.axes[Yaw], C.axes[Pitch], C.axes[Roll]); -- cgit v1.2.3 From 28fcbb913ed0969b22fd07c32c63c2a54568b6c6 Mon Sep 17 00:00:00 2001 From: usrusr Date: Tue, 10 Dec 2013 01:52:43 +0100 Subject: add an optional per-pixel hysteresis to remove pixel noise at the expense of a moderate movement threshold (but no lag) --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 32 ++++++++++ FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 1 + FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp | 2 + FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h | 1 + FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp | 2 + FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h | 2 + FTNoIR_Tracker_PT/point_extractor.cpp | 80 +++++++++++++++++++++--- FTNoIR_Tracker_PT/point_extractor.h | 6 ++ 8 files changed, 117 insertions(+), 9 deletions(-) (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index 1495249a..9ad4f83c 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -848,6 +848,38 @@ + + + + + + + Hysteresis + + + threshold_secondary_slider + + + + + + + Per pixel hysteresis width (leave left if there is little difference between dot and non-dot, move right for increased stability against pixel noise) + + + 255 + + + 100 + + + Qt::Horizontal + + + + + + diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp index 5cb7bdf3..dcf28f04 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp @@ -113,6 +113,7 @@ void Tracker::apply(const TrackerSettings& settings) camera.set_f(settings.cam_f); frame_rotation.rotation = static_cast(settings.cam_roll); point_extractor.threshold_val = settings.threshold; + point_extractor.threshold_secondary_val = settings.threshold_secondary; point_extractor.min_size = settings.min_point_size; point_extractor.max_size = settings.max_point_size; point_tracker.point_model = boost::shared_ptr(new PointModel(settings.M01, settings.M02)); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp index fe995163..f8afa790 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp @@ -63,6 +63,7 @@ TrackerDialog::TrackerDialog() ui.campitch_spin->setValue(settings.cam_pitch); ui.camyaw_spin->setValue(settings.cam_yaw); ui.threshold_slider->setValue(settings.threshold); + ui.threshold_secondary_slider->setValue(settings.threshold_secondary); ui.chkEnableRoll->setChecked(settings.bEnableRoll); ui.chkEnablePitch->setChecked(settings.bEnablePitch); @@ -105,6 +106,7 @@ TrackerDialog::TrackerDialog() connect( ui.campitch_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cam_pitch(int)) ); connect( ui.camyaw_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cam_yaw(int)) ); connect( ui.threshold_slider,SIGNAL(sliderMoved(int)), this,SLOT(set_threshold(int)) ); + connect( ui.threshold_secondary_slider,SIGNAL(sliderMoved(int)), this,SLOT(set_threshold_secondary(int)) ); connect( ui.chkEnableRoll,SIGNAL(toggled(bool)), this,SLOT(set_ena_roll(bool)) ); connect( ui.chkEnablePitch,SIGNAL(toggled(bool)), this,SLOT(set_ena_pitch(bool)) ); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h index 3e1af50a..de743ad8 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h @@ -54,6 +54,7 @@ protected slots: void set_min_point_size(int val) { settings.min_point_size = val; settings_changed(); } void set_max_point_size(int val) { settings.max_point_size = val; settings_changed(); } void set_threshold(int val) { settings.threshold = val; settings_changed(); } + void set_threshold_secondary(int val) { settings.threshold_secondary = val; settings_changed(); } void set_ena_roll(bool val) { settings.bEnableRoll = val; settings_changed(); } void set_ena_pitch(bool val) { settings.bEnablePitch = val; settings_changed(); } void set_ena_yaw(bool val) { settings.bEnableYaw = val; settings_changed(); } diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp index 62ba1e3e..50835cb8 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp @@ -29,6 +29,7 @@ void TrackerSettings::load_ini() cam_pitch = iniFile.value("CameraPitch", 0).toInt(); cam_yaw = iniFile.value("CameraYaw", 0).toInt(); threshold = iniFile.value("PointExtractThreshold", 128).toInt(); + threshold_secondary = iniFile.value("PointExtractThresholdSecondary", 128).toInt(); min_point_size = iniFile.value("PointExtractMinSize", 2).toInt(); max_point_size = iniFile.value("PointExtractMaxSize", 50).toInt(); M01[0] = iniFile.value("PointModelM01x", 0).toFloat(); @@ -74,6 +75,7 @@ void TrackerSettings::save_ini() const iniFile.setValue("CameraPitch", cam_pitch); iniFile.setValue("CameraYaw", cam_yaw); iniFile.setValue("PointExtractThreshold", threshold); + iniFile.setValue("PointExtractThresholdSecondary", threshold_secondary); iniFile.setValue("PointExtractMinSize", min_point_size); iniFile.setValue("PointExtractMaxSize", max_point_size); iniFile.setValue("PointModelM01x", M01[0]); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h index 1cf60853..91a7a8d5 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h @@ -28,6 +28,8 @@ struct TrackerSettings // point extraction int threshold; + int threshold_secondary; + int min_point_size; int max_point_size; diff --git a/FTNoIR_Tracker_PT/point_extractor.cpp b/FTNoIR_Tracker_PT/point_extractor.cpp index 261de60f..27a14713 100644 --- a/FTNoIR_Tracker_PT/point_extractor.cpp +++ b/FTNoIR_Tracker_PT/point_extractor.cpp @@ -8,15 +8,27 @@ #include "point_extractor.h" #include + using namespace cv; using namespace std; + +PointExtractor::PointExtractor(){ + first = true; + + + //if (!AllocConsole()){} + //else SetConsoleTitle("debug"); + //freopen("CON", "w", stdout); + //freopen("CON", "w", stderr); +} // ---------------------------------------------------------------------------- const vector& PointExtractor::extract_points(Mat frame, float dt, bool draw_output) { const int W = frame.cols; const int H = frame.rows; + // clear old points points.clear(); @@ -24,10 +36,41 @@ const vector& PointExtractor::extract_points(Mat frame, float dt, bool dr Mat frame_gray; cvtColor(frame, frame_gray, CV_RGB2GRAY); - // convert to binary + int secondary = threshold_secondary_val; + + // mask for everything that passes the threshold (or: the upper threshold of the hysteresis) Mat frame_bin; - threshold(frame_gray, frame_bin, threshold_val, 255, THRESH_BINARY); + // only used if draw_output + Mat frame_bin_copy; + // mask for everything that passes + Mat frame_bin_low; + // mask for lower-threshold && combined result of last, needs to remain in scope until drawing, but is only used if secondary != 0 + Mat frame_last_and_low; + if(secondary==0){ + threshold(frame_gray, frame_bin, threshold_val, 255, THRESH_BINARY); + }else{ + // we recombine a number of buffers, this might be slower than a single loop of per-pixel logic + // but it might as well be faster if openCV makes good use of SIMD + float t = threshold_val; + //float hyst = float(threshold_secondary_val)/512.; + //threshold(frame_gray, frame_bin, (t + ((255.-t)*hyst)), 255, THRESH_BINARY); + float hyst = float(threshold_secondary_val)/256.; + threshold(frame_gray, frame_bin, t, 255, THRESH_BINARY); + threshold(frame_gray, frame_bin_low,std::max(float(1), t - (t*hyst)), 255, THRESH_BINARY); + + if(draw_output) frame_bin.copyTo(frame_bin_copy); + if(first){ + frame_bin.copyTo(frame_last); + first = false; + }else{ + // keep pixels from last if they are above lower threshold + bitwise_and(frame_last, frame_bin_low, frame_last_and_low); + // union of pixels >= higher threshold and pixels >= lower threshold + bitwise_or(frame_bin, frame_last_and_low, frame_last); + frame_last.copyTo(frame_bin); + } + } unsigned int region_size_min = 3.14*min_size*min_size/4.0; unsigned int region_size_max = 3.14*max_size*max_size/4.0; @@ -42,6 +85,7 @@ const vector& PointExtractor::extract_points(Mat frame, float dt, bool dr // find connected components with floodfill if (frame_bin.at(y,x) != 255) continue; Rect rect; + floodFill(frame_bin, Point(x,y), Scalar(blob_index), &rect, Scalar(0), Scalar(0), FLOODFILL_FIXED_RANGE); blob_index++; @@ -70,9 +114,17 @@ const vector& PointExtractor::extract_points(Mat frame, float dt, bool dr for (int j=rect.x; j < (rect.x+rect.width); j++) { if (frame_bin.at(i,j) != blob_index-1) continue; - float val = frame_gray.at(i,j); - val = float(val - threshold_val)/(256 - threshold_val); - val = val*val; // makes it more stable (less emphasis on low values, more on the peak) + float val; + + if(secondary==0){ + val = frame_gray.at(i,j); + val = float(val - threshold_val)/(256 - threshold_val); + val = val*val; // makes it more stable (less emphasis on low values, more on the peak) + }else{ + //hysteresis point detection gets stability from ignoring pixel noise so we decidedly leave the actual pixel values out of the picture + val = frame_last.at(i,j) / 256.; + } + m += val; mx += j * val; my += i * val; @@ -83,6 +135,7 @@ const vector& PointExtractor::extract_points(Mat frame, float dt, bool dr Vec2f c; c[0] = (mx/m - W/2)/W; c[1] = -(my/m - H/2)/W; + //qDebug()< "<& PointExtractor::extract_points(Mat frame, float dt, bool dr // draw output image if (draw_output) { vector channels; - frame_bin.setTo(170, frame_bin); - channels.push_back(frame_gray + frame_bin); - channels.push_back(frame_gray - frame_bin); - channels.push_back(frame_gray - frame_bin); + if(secondary==0){ + frame_bin.setTo(170, frame_bin); + channels.push_back(frame_gray + frame_bin); + channels.push_back(frame_gray - frame_bin); + channels.push_back(frame_gray - frame_bin); + }else{ + frame_bin_copy.setTo(120, frame_bin_copy); + frame_bin_low.setTo(90, frame_bin_low); + channels.push_back(frame_gray + frame_bin_copy); + channels.push_back(frame_gray + frame_last_and_low); + channels.push_back(frame_gray + frame_bin_low); + //channels.push_back(frame_gray + frame_bin); + } merge(channels, frame); } diff --git a/FTNoIR_Tracker_PT/point_extractor.h b/FTNoIR_Tracker_PT/point_extractor.h index c62d34f9..b9f46666 100644 --- a/FTNoIR_Tracker_PT/point_extractor.h +++ b/FTNoIR_Tracker_PT/point_extractor.h @@ -21,12 +21,18 @@ public: // WARNING: returned reference is valid as long as object const std::vector& extract_points(cv::Mat frame, float dt, bool draw_output); const std::vector& get_points() { return points; } + PointExtractor(); int threshold_val; + int threshold_secondary_val; int min_size, max_size; protected: std::vector points; + cv::Mat frame_last; + + + bool first; }; #endif //POINTEXTRACTOR_H -- cgit v1.2.3 From b7eb4245fe6dc261a926d31331b2af3fec959401 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 30 Dec 2013 15:40:24 +0100 Subject: pt: use new settings framework, cleanup --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 214 ++++++--------- FTNoIR_Tracker_PT/camera.h | 12 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 155 ++++------- FTNoIR_Tracker_PT/ftnoir_tracker_pt.h | 36 +-- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp | 318 +++++++++-------------- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h | 69 +---- FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp | 156 ----------- FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h | 137 +++++----- 8 files changed, 338 insertions(+), 759 deletions(-) delete mode 100644 FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index 9ad4f83c..6cd17e8d 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -9,7 +9,7 @@ 0 0 - 458 + 459 590 @@ -69,11 +69,39 @@ - + + + + + + Time until automatic reset of tracker's internal state when no valid tracking result is found + + + 9999 + + + + + + + ms + + + + + + + + + + + + + Dynamic Pose Resolution @@ -89,30 +117,6 @@ - - - - - - Time the tracker thread sleeps after each processed frame - - - - - - 9999 - - - - - - - ms - - - - - @@ -123,12 +127,15 @@ - - + + - + - Time until automatic reset of tracker's internal state when no valid tracking result is found + Time the tracker thread sleeps after each processed frame + + + 9999 @@ -136,7 +143,7 @@ - + ms @@ -144,43 +151,7 @@ - - - - Whether to update the content of the VideoWidget - - - Show VideoWidget - - - - - - - Qt::Horizontal - - - - 30 - 20 - - - - - - - - Qt::Horizontal - - - - 30 - 20 - - - - - + false @@ -635,40 +606,7 @@ - - - - - false - - - - 130 - 0 - - - - - - - VideoWidget - - - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - + @@ -848,38 +786,36 @@ - - - - - - - Hysteresis - - - threshold_secondary_slider - - - - - - - Per pixel hysteresis width (leave left if there is little difference between dot and non-dot, move right for increased stability against pixel noise) - - - 255 - - - 100 - - - Qt::Horizontal - - - - - - + + + + + + Hysteresis + + + threshold_secondary_slider + + + + + + + Per pixel hysteresis width (leave left if there is little difference between dot and non-dot, move right for increased stability against pixel noise) + + + 255 + + + 100 + + + Qt::Horizontal + + + + + @@ -1777,6 +1713,13 @@ + + + + Apply + + + @@ -1816,11 +1759,8 @@ tabWidget - videowidget_check sleep_spin - dynpose_check reset_spin - reset_button chkEnableRoll chkEnablePitch chkEnableYaw diff --git a/FTNoIR_Tracker_PT/camera.h b/FTNoIR_Tracker_PT/camera.h index 78fe8dfb..ea68c387 100644 --- a/FTNoIR_Tracker_PT/camera.h +++ b/FTNoIR_Tracker_PT/camera.h @@ -69,13 +69,13 @@ protected: virtual void _set_fps() = 0; virtual void _set_res() = 0; - bool active; + float dt_valid; + float dt_mean; int desired_index; int active_index; + bool active; CamInfo cam_info; CamInfo cam_desired; - float dt_valid; - float dt_mean; }; @@ -128,9 +128,9 @@ protected: enum RotationType { - CLOCKWISE = -1, - ZERO = 0, - COUNTER_CLOCKWISE = 1 + CLOCKWISE = 0, + ZERO = 1, + COUNTER_CLOCKWISE = 2 }; // ---------------------------------------------------------------------------- diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp index e3af446f..25a19ee7 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp @@ -23,8 +23,7 @@ const float deg2rad = 1.0/rad2deg; //----------------------------------------------------------------------------- Tracker::Tracker() - : frame_count(0), - commands(0), + : commands(0), video_widget(NULL), video_frame(NULL), tracking_valid(false) @@ -38,9 +37,10 @@ Tracker::~Tracker() // terminate tracker thread set_command(ABORT); wait(); - // destroy video widget - show_video_widget = false; - update_show_video_widget(); + s.video_widget = false; + delete video_widget; + video_widget = NULL; + if (video_frame->layout()) delete video_frame->layout(); } void Tracker::set_command(Command command) @@ -86,10 +86,7 @@ void Tracker::run() frame = frame_rotation.rotate_frame(frame); const std::vector& points = point_extractor.extract_points(frame, dt, has_observers()); tracking_valid = point_tracker.track(points, camera.get_info().f, dt); - frame_count++; -#ifdef OPENTRACK_API video_widget->update_image(frame.clone()); -#endif } #ifdef PT_PERF_LOG log_stream<<"dt: "<(settings.cam_roll); - point_extractor.threshold_val = settings.threshold; - point_extractor.threshold_secondary_val = settings.threshold_secondary; - point_extractor.min_size = settings.min_point_size; - point_extractor.max_size = settings.max_point_size; - point_tracker.point_model = boost::shared_ptr(new PointModel(settings.M01, settings.M02)); - point_tracker.dynamic_pose_resolution = settings.dyn_pose_res; - sleep_time = settings.sleep_time; - point_tracker.dt_reset = settings.reset_time / 1000.0; - show_video_widget = settings.video_widget; - update_show_video_widget(); - bEnableRoll = settings.bEnableRoll; - bEnablePitch = settings.bEnablePitch; - bEnableYaw = settings.bEnableYaw; - bEnableX = settings.bEnableX; - bEnableY = settings.bEnableY; - bEnableZ = settings.bEnableZ; - - t_MH = settings.t_MH; - R_GC = Matx33f( cos(deg2rad*settings.cam_yaw), 0, sin(deg2rad*settings.cam_yaw), + camera.set_device_index(s.cam_index); + camera.set_res(s.cam_res_x, s.cam_res_y); + camera.set_fps(s.cam_fps); + camera.set_f(s.cam_f); + frame_rotation.rotation = static_cast(static_cast(s.cam_roll)); + point_extractor.threshold_val = s.threshold; + point_extractor.threshold_secondary_val = s.threshold_secondary; + point_extractor.min_size = s.min_point_size; + point_extractor.max_size = s.max_point_size; + { + cv::Vec3f M01(s.m01_x, s.m01_y, s.m01_z); + cv::Vec3f M02(s.m02_x, s.m02_y, s.m02_z); + point_tracker.point_model = boost::shared_ptr(new PointModel(M01, M02)); + } + point_tracker.dynamic_pose_resolution = s.dyn_pose_res; + point_tracker.dt_reset = s.reset_time / 1000.0; + t_MH = cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z); + R_GC = Matx33f( cos(deg2rad*s.cam_yaw), 0, sin(deg2rad*s.cam_yaw), 0, 1, 0, - -sin(deg2rad*settings.cam_yaw), 0, cos(deg2rad*settings.cam_yaw)); + -sin(deg2rad*s.cam_yaw), 0, cos(deg2rad*s.cam_yaw)); R_GC = R_GC * Matx33f( 1, 0, 0, - 0, cos(deg2rad*settings.cam_pitch), sin(deg2rad*settings.cam_pitch), - 0, -sin(deg2rad*settings.cam_pitch), cos(deg2rad*settings.cam_pitch)); + 0, cos(deg2rad*s.cam_pitch), sin(deg2rad*s.cam_pitch), + 0, -sin(deg2rad*s.cam_pitch), cos(deg2rad*s.cam_pitch)); FrameTrafo X_MH(Matx33f::eye(), t_MH); X_GH_0 = R_GC * X_MH; @@ -169,58 +160,27 @@ bool Tracker::get_frame_and_points(cv::Mat& frame_copy, boost::shared_ptr< std:: return true; } -void Tracker::update_show_video_widget() -{ - if (!show_video_widget && video_widget) { - delete video_widget; - video_widget = NULL; - if (video_frame->layout()) delete video_frame->layout(); - } - else if (video_frame && show_video_widget && !video_widget) - { - const int VIDEO_FRAME_WIDTH = 320; - const int VIDEO_FRAME_HEIGHT = 240; - video_widget = new PTVideoWidget(video_frame, this); - QHBoxLayout* video_layout = new QHBoxLayout(); - video_layout->setContentsMargins(0, 0, 0, 0); - video_layout->addWidget(video_widget); - video_frame->setLayout(video_layout); - video_widget->resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT); - } -} - -//----------------------------------------------------------------------------- -// ITracker interface -void Tracker::Initialize(QFrame *video_frame) -{ - qDebug("Tracker::Initialize"); - // setup video frame - this->video_frame = video_frame; - video_frame->setAttribute(Qt::WA_NativeWindow); - video_frame->show(); - update_show_video_widget(); - TrackerSettings settings; - settings.load_ini(); - camera.start(); - apply(settings); - start(); -} - void Tracker::refreshVideo() { if (video_widget) video_widget->update_frame_and_points(); } -#ifdef OPENTRACK_API void Tracker::StartTracker(QFrame *parent_window) -#else -void Tracker::StartTracker(HWND parent_window) -#endif { -#ifdef OPENTRACK_API - Initialize(parent_window); -#endif - reset_command(PAUSE); + this->video_frame = parent_window; + video_frame->setAttribute(Qt::WA_NativeWindow); + video_frame->show(); + apply(s); + video_widget = new PTVideoWidget(video_frame, this); + QHBoxLayout* video_layout = new QHBoxLayout(parent_window); + video_layout->setContentsMargins(0, 0, 0, 0); + video_layout->addWidget(video_widget); + video_frame->setLayout(video_layout); + video_widget->resize(video_frame->width(), video_frame->height()); + start(); + camera.start(); + start(); + reset_command(PAUSE); } #ifndef OPENTRACK_API @@ -247,18 +207,12 @@ void Tracker::GetHeadPoseData(THeadPoseData *data) Matx33f R = X_GH.R * X_GH_0.R.t(); Vec3f t = X_GH.t - X_GH_0.t; -#ifndef OPENTRACK_API - // get translation(s) - if (bEnableX) data->x = t[0] / 10.0; // convert to cm - if (bEnableY) data->y = t[1] / 10.0; - if (bEnableZ) data->z = t[2] / 10.0; -#else // get translation(s) - if (bEnableX) data[TX] = t[0] / 10.0; // convert to cm - if (bEnableY) data[TY] = t[1] / 10.0; - if (bEnableZ) data[TZ] = t[2] / 10.0; -#endif - // translate rotation matrix from opengl (G) to roll-pitch-yaw (E) frame + if (s.bEnableX) data[TX] = t[0] / 10.0; // convert to cm + if (s.bEnableY) data[TY] = t[1] / 10.0; + if (s.bEnableZ) data[TZ] = t[2] / 10.0; + + // translate rotation matrix from opengl (G) to roll-pitch-yaw (E) frame // -z -> x, y -> z, x -> -y Matx33f R_EG( 0, 0,-1, -1, 0, 0, @@ -271,19 +225,10 @@ void Tracker::GetHeadPoseData(THeadPoseData *data) alpha = atan2( R(1,0), R(0,0)); gamma = atan2( R(2,1), R(2,2)); -#ifndef OPENTRACK_API - if (bEnableYaw) data->yaw = rad2deg * alpha; - if (bEnablePitch) data->pitch = - rad2deg * beta; // FTNoIR expects a minus here - if (bEnableRoll) data->roll = rad2deg * gamma; -#else - if (bEnableYaw) data[Yaw] = rad2deg * alpha; - if (bEnablePitch) data[Pitch] = - rad2deg * beta; // FTNoIR expects a minus here - if (bEnableRoll) data[Roll] = rad2deg * gamma; -#endif + if (s.bEnableYaw) data[Yaw] = rad2deg * alpha; + if (s.bEnablePitch) data[Pitch] = - rad2deg * beta; // FTNoIR expects a minus here + if (s.bEnableRoll) data[Roll] = rad2deg * gamma; } -#ifndef OPENTRACK_API - return true; -#endif } //----------------------------------------------------------------------------- diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h index 54edafb2..c7f1dc02 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h @@ -39,20 +39,11 @@ class Tracker : public ITracker, QThread, public FrameProvider public: Tracker(); virtual ~Tracker(); - - // --- ITracker interface --- - virtual void Initialize(QFrame *videoframe); -#ifdef OPENTRACK_API virtual void StartTracker(QFrame* parent_window); virtual void GetHeadPoseData(double* data); -#else - virtual void StartTracker(HWND parent_window); - virtual void StopTracker(bool exit); - virtual bool GetHeadPoseData(THeadPoseData *data); -#endif virtual void refreshVideo(); - void apply(const TrackerSettings& settings); + void apply(settings& s); void center(); void reset(); // reset the trackers internal state variables void run(); @@ -74,20 +65,12 @@ protected: }; void set_command(Command command); void reset_command(Command command); - int commands; - - int sleep_time; + int commands; - // --- tracking chain --- -#ifdef OPENTRACK_API CVCamera camera; -#else - VICamera camera; -#endif FrameRotation frame_rotation; PointExtractor point_extractor; PointTracker point_tracker; - bool tracking_valid; FrameTrafo X_GH_0; // for centering cv::Vec3f t_MH; // translation from model frame to head frame @@ -96,22 +79,11 @@ protected: // --- ui --- cv::Mat frame; // the output frame for display - void update_show_video_widget(); - bool show_video_widget; -#ifdef OPENTRACK_API PTVideoWidget* video_widget; -#endif QFrame* video_frame; + bool tracking_valid; - // --- misc --- - bool bEnableRoll; - bool bEnablePitch; - bool bEnableYaw; - bool bEnableX; - bool bEnableY; - bool bEnableZ; - - long frame_count; + settings s; Timer time; }; diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp index f8afa790..a88e3a07 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp @@ -21,8 +21,7 @@ using namespace std; //----------------------------------------------------------------------------- TrackerDialog::TrackerDialog() - : settings_dirty(false), - tracker(NULL), + : tracker(NULL), video_widget_dialog(NULL), timer(this), trans_calib_running(false) @@ -32,191 +31,112 @@ TrackerDialog::TrackerDialog() ui.setupUi( this ); - settings.load_ini(); - dialog_settings.load_ini(); - - // initialize ui values - ui.videowidget_check->setChecked(settings.video_widget); - ui.dynpose_check->setChecked(settings.dyn_pose_res); - ui.sleep_spin->setValue(settings.sleep_time); - ui.reset_spin->setValue(settings.reset_time); - - vector device_names; + vector device_names; get_camera_device_names(device_names); for (vector::iterator iter = device_names.begin(); iter != device_names.end(); ++iter) { ui.camdevice_combo->addItem(iter->c_str()); } - ui.camdevice_combo->setCurrentIndex(settings.cam_index); - - ui.f_dspin->setValue(settings.cam_f); - ui.res_x_spin->setValue(settings.cam_res_x); - ui.res_y_spin->setValue(settings.cam_res_y); - ui.fps_spin->setValue(settings.cam_fps); - - ui.camroll_combo->addItem("-90", -1); - ui.camroll_combo->addItem("0" , 0); - ui.camroll_combo->addItem("90" , 1); - int i = ui.camroll_combo->findData(settings.cam_roll); - ui.camroll_combo->setCurrentIndex(i>=0 ? i : 0); - - ui.campitch_spin->setValue(settings.cam_pitch); - ui.camyaw_spin->setValue(settings.cam_yaw); - ui.threshold_slider->setValue(settings.threshold); - ui.threshold_secondary_slider->setValue(settings.threshold_secondary); - - ui.chkEnableRoll->setChecked(settings.bEnableRoll); - ui.chkEnablePitch->setChecked(settings.bEnablePitch); - ui.chkEnableYaw->setChecked(settings.bEnableYaw); - ui.chkEnableX->setChecked(settings.bEnableX); - ui.chkEnableY->setChecked(settings.bEnableY); - ui.chkEnableZ->setChecked(settings.bEnableZ); - - ui.mindiam_spin->setValue(settings.min_point_size); - ui.maxdiam_spin->setValue(settings.max_point_size); - ui.model_tabs->setCurrentIndex(dialog_settings.active_model_panel); - ui.clip_bheight_spin->setValue(dialog_settings.clip_by); - ui.clip_blength_spin->setValue(dialog_settings.clip_bz); - ui.clip_theight_spin->setValue(dialog_settings.clip_ty); - ui.clip_tlength_spin->setValue(dialog_settings.clip_tz); - ui.cap_width_spin->setValue(dialog_settings.cap_x); - ui.cap_height_spin->setValue(dialog_settings.cap_y); - ui.cap_length_spin->setValue(dialog_settings.cap_z); - ui.m1x_spin->setValue(dialog_settings.M01x); - ui.m1y_spin->setValue(dialog_settings.M01y); - ui.m1z_spin->setValue(dialog_settings.M01z); - ui.m2x_spin->setValue(dialog_settings.M02x); - ui.m2y_spin->setValue(dialog_settings.M02y); - ui.m2z_spin->setValue(dialog_settings.M02z); - ui.tx_spin->setValue(settings.t_MH[0]); - ui.ty_spin->setValue(settings.t_MH[1]); - ui.tz_spin->setValue(settings.t_MH[2]); - - // connect Qt signals and slots - connect( ui.videowidget_check,SIGNAL(toggled(bool)), this,SLOT(set_video_widget(bool)) ); - connect( ui.dynpose_check,SIGNAL(toggled(bool)), this,SLOT(set_dyn_pose_res(bool)) ); - connect( ui.sleep_spin,SIGNAL(valueChanged(int)), this,SLOT(set_sleep_time(int)) ); - connect( ui.reset_spin,SIGNAL(valueChanged(int)), this,SLOT(set_reset_time(int)) ); - connect( ui.camdevice_combo,SIGNAL(currentIndexChanged(int)), this,SLOT(set_cam_index(int)) ); - connect( ui.f_dspin,SIGNAL(valueChanged(double)), this,SLOT(set_cam_f(double)) ); - connect( ui.res_x_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cam_res_x(int)) ); - connect( ui.res_y_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cam_res_y(int)) ); - connect( ui.fps_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cam_fps(int)) ); - connect( ui.camroll_combo,SIGNAL(currentIndexChanged(int)), this,SLOT(set_cam_roll(int)) ); - connect( ui.campitch_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cam_pitch(int)) ); - connect( ui.camyaw_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cam_yaw(int)) ); - connect( ui.threshold_slider,SIGNAL(sliderMoved(int)), this,SLOT(set_threshold(int)) ); - connect( ui.threshold_secondary_slider,SIGNAL(sliderMoved(int)), this,SLOT(set_threshold_secondary(int)) ); - - connect( ui.chkEnableRoll,SIGNAL(toggled(bool)), this,SLOT(set_ena_roll(bool)) ); - connect( ui.chkEnablePitch,SIGNAL(toggled(bool)), this,SLOT(set_ena_pitch(bool)) ); - connect( ui.chkEnableYaw,SIGNAL(toggled(bool)), this,SLOT(set_ena_yaw(bool)) ); - connect( ui.chkEnableX,SIGNAL(toggled(bool)), this,SLOT(set_ena_x(bool)) ); - connect( ui.chkEnableY,SIGNAL(toggled(bool)), this,SLOT(set_ena_y(bool)) ); - connect( ui.chkEnableZ,SIGNAL(toggled(bool)), this,SLOT(set_ena_z(bool)) ); - - connect( ui.mindiam_spin,SIGNAL(valueChanged(int)), this,SLOT(set_min_point_size(int)) ); - connect( ui.maxdiam_spin,SIGNAL(valueChanged(int)), this,SLOT(set_max_point_size(int)) ); - connect( ui.model_tabs,SIGNAL(currentChanged(int)), this,SLOT(set_model(int)) ); - connect( ui.clip_theight_spin,SIGNAL(valueChanged(int)), this,SLOT(set_clip_t_height(int)) ); - connect( ui.clip_tlength_spin,SIGNAL(valueChanged(int)), this,SLOT(set_clip_t_length(int)) ); - connect( ui.clip_bheight_spin,SIGNAL(valueChanged(int)), this,SLOT(set_clip_b_height(int)) ); - connect( ui.clip_blength_spin,SIGNAL(valueChanged(int)), this,SLOT(set_clip_b_length(int)) ); - connect( ui.cap_width_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cap_width(int)) ); - connect( ui.cap_height_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cap_height(int)) ); - connect( ui.cap_length_spin,SIGNAL(valueChanged(int)), this,SLOT(set_cap_length(int)) ); - connect( ui.m1x_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m1x(int)) ); - connect( ui.m1y_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m1y(int)) ); - connect( ui.m1z_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m1z(int)) ); - connect( ui.m2x_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m2x(int)) ); - connect( ui.m2y_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m2y(int)) ); - connect( ui.m2z_spin,SIGNAL(valueChanged(int)), this,SLOT(set_m2z(int)) ); - connect( ui.tx_spin,SIGNAL(valueChanged(int)), this,SLOT(set_tx(int)) ); - connect( ui.ty_spin,SIGNAL(valueChanged(int)), this,SLOT(set_ty(int)) ); - connect( ui.tz_spin,SIGNAL(valueChanged(int)), this,SLOT(set_tz(int)) ); - - connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool)) ); - - connect( ui.videowidget_button,SIGNAL(clicked()), this,SLOT(create_video_widget()) ); - - connect(ui.reset_button, SIGNAL(clicked()), this, SLOT(doReset())); - //connect(ui.center_button, SIGNAL(clicked()), this, SLOT(doCenter())); - - connect(ui.ok_button, SIGNAL(clicked()), this, SLOT(doOK())); - connect(ui.cancel_button, SIGNAL(clicked()), this, SLOT(doCancel())); - - connect(&timer,SIGNAL(timeout()), this,SLOT(poll_tracker_info())); - timer.start(100); -} -TrackerDialog::~TrackerDialog() -{ - qDebug()<<"TrackerDialog::~TrackerDialog"; -} + ui.camroll_combo->addItem("-90"); + ui.camroll_combo->addItem("0"); + ui.camroll_combo->addItem("90"); -void TrackerDialog::set_cam_roll(int idx) -{ - settings.cam_roll = ui.camroll_combo->itemData(idx).toInt(); - settings_changed(); + tie_setting(s.dyn_pose_res, ui.dynpose_check); + tie_setting(s.sleep_time, ui.sleep_spin); + tie_setting(s.reset_time, ui.reset_spin); + + tie_setting(s.cam_index, ui.camdevice_combo); + tie_setting(s.cam_f, ui.f_dspin); + tie_setting(s.cam_res_x, ui.res_x_spin); + tie_setting(s.cam_res_y, ui.res_y_spin); + tie_setting(s.cam_fps, ui.fps_spin); + tie_setting(s.cam_roll, ui.camroll_combo); + tie_setting(s.cam_pitch, ui.campitch_spin); + tie_setting(s.cam_yaw, ui.camyaw_spin); + + tie_setting(s.threshold_secondary, ui.threshold_secondary_slider); + tie_setting(s.threshold, ui.threshold_slider); + + tie_setting(s.bEnableYaw, ui.chkEnableYaw); + tie_setting(s.bEnablePitch, ui.chkEnablePitch); + tie_setting(s.bEnableRoll, ui.chkEnableRoll); + tie_setting(s.bEnableX, ui.chkEnableX); + tie_setting(s.bEnableY, ui.chkEnableY); + tie_setting(s.bEnableZ, ui.chkEnableZ); + + tie_setting(s.min_point_size, ui.mindiam_spin); + tie_setting(s.max_point_size, ui.maxdiam_spin); + + tie_setting(s.clip_by, ui.clip_bheight_spin); + tie_setting(s.clip_bz, ui.clip_blength_spin); + tie_setting(s.clip_ty, ui.clip_theight_spin); + tie_setting(s.clip_tz, ui.clip_tlength_spin); + + tie_setting(s.cap_x, ui.cap_width_spin); + tie_setting(s.cap_y, ui.cap_height_spin); + tie_setting(s.cap_z, ui.cap_length_spin); + + tie_setting(s.m01_x, ui.m1x_spin); + tie_setting(s.m01_y, ui.m1y_spin); + tie_setting(s.m01_z, ui.m1z_spin); + + tie_setting(s.m02_x, ui.m2x_spin); + tie_setting(s.m02_y, ui.m2y_spin); + tie_setting(s.m02_z, ui.m2z_spin); + + tie_setting(s.t_MH_x, ui.tx_spin); + tie_setting(s.t_MH_y, ui.ty_spin); + tie_setting(s.t_MH_z, ui.tz_spin); + + connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool)) ); + connect(ui.reset_button, SIGNAL(clicked()), this, SLOT(doReset())); + + connect(ui.ok_button, SIGNAL(clicked()), this, SLOT(doOK())); + connect(ui.cancel_button, SIGNAL(clicked()), this, SLOT(doCancel())); + connect(ui.btnApply, SIGNAL(clicked()), this, SLOT(doApply())); + + ui.model_tabs->setCurrentIndex(s.active_model_panel); + + connect(ui.model_tabs, SIGNAL(currentChanged(int)), this, SLOT(set_model(int))); + connect(&timer,SIGNAL(timeout()), this,SLOT(poll_tracker_info())); + timer.start(100); + + connect(s.b.get(), SIGNAL(bundleChanged()), this, SLOT(do_apply_without_saving())); } void TrackerDialog::set_model_clip() { - settings.M01[0] = 0; - settings.M01[1] = dialog_settings.clip_ty; - settings.M01[2] = -dialog_settings.clip_tz; - settings.M02[0] = 0; - settings.M02[1] = -dialog_settings.clip_by; - settings.M02[2] = -dialog_settings.clip_bz; + s.m01_x = 0; + s.m01_y = static_cast(s.clip_ty); + s.m01_z = -static_cast(s.clip_tz); + s.m02_x = 0; + s.m02_y = -static_cast(s.clip_by); + s.m02_z = -static_cast(s.clip_bz); settings_changed(); } void TrackerDialog::set_model_cap() { - settings.M01[0] = -dialog_settings.cap_x; - settings.M01[1] = -dialog_settings.cap_y; - settings.M01[2] = -dialog_settings.cap_z; - settings.M02[0] = dialog_settings.cap_x; - settings.M02[1] = -dialog_settings.cap_y; - settings.M02[2] = -dialog_settings.cap_z; + s.m01_x = -static_cast(s.cap_x); + s.m01_y = -static_cast(s.cap_y); + s.m01_z = -static_cast(s.cap_z); + s.m02_x = static_cast(s.cap_x); + s.m02_y = -static_cast(s.cap_y); + s.m02_z = -static_cast(s.cap_z); settings_changed(); } void TrackerDialog::set_model_custom() { - settings.M01[0] = dialog_settings.M01x; - settings.M01[1] = dialog_settings.M01y; - settings.M01[2] = dialog_settings.M01z; - settings.M02[0] = dialog_settings.M02x; - settings.M02[1] = dialog_settings.M02y; - settings.M02[2] = dialog_settings.M02z; - settings_changed(); } void TrackerDialog::set_model(int val) { - dialog_settings.active_model_panel = val; - - switch (val) { - - case TrackerDialogSettings::MODEL_CLIP: - set_model_clip(); - break; - - case TrackerDialogSettings::MODEL_CAP: - set_model_cap(); - break; - - case TrackerDialogSettings::MODEL_CUSTOM: - set_model_custom(); - break; - - default: - break; - } + s.active_model_panel = val; } void TrackerDialog::startstop_trans_calib(bool start) @@ -231,7 +151,12 @@ void TrackerDialog::startstop_trans_calib(bool start) { qDebug()<<"TrackerDialog:: Stoppping translation calibration"; trans_calib_running = false; - settings.t_MH = trans_calib.get_estimate(); + { + auto tmp = trans_calib.get_estimate(); + s.t_MH_x = tmp[0]; + s.t_MH_y = tmp[1]; + s.t_MH_z = tmp[2]; + } settings_changed(); } } @@ -244,17 +169,15 @@ void TrackerDialog::trans_calib_step() tracker->get_pose(&X_CM); trans_calib.update(X_CM.R, X_CM.t); cv::Vec3f t_MH = trans_calib.get_estimate(); - //qDebug()<<"TrackerDialog:: Current translation estimate: "<setValue(t_MH[0]); - ui.ty_spin->setValue(t_MH[1]); - ui.tz_spin->setValue(t_MH[2]); + s.t_MH_x = t_MH[0]; + s.t_MH_y = t_MH[1]; + s.t_MH_z = t_MH[2]; } } void TrackerDialog::settings_changed() { - settings_dirty = true; - if (tracker) tracker->apply(settings); + if (tracker) tracker->apply(s); } void TrackerDialog::doCenter() @@ -267,25 +190,52 @@ void TrackerDialog::doReset() if (tracker) tracker->reset(); } +void TrackerDialog::save() +{ + do_apply_without_saving(); + s.b->save(); +} + void TrackerDialog::doOK() { - settings.save_ini(); - dialog_settings.save_ini(); + save(); close(); } +void TrackerDialog::do_apply_without_saving() +{ + switch (s.active_model_panel) { + default: + case 0: + set_model_clip(); + break; + case 1: + set_model_cap(); + break; + case 2: + set_model_custom(); + break; + } + if (tracker) tracker->apply(s); +} + +void TrackerDialog::doApply() +{ + save(); +} + void TrackerDialog::doCancel() { - if (settings_dirty) { + if (s.b->modifiedp()) { int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard ); switch (ret) { case QMessageBox::Save: - settings.save_ini(); - dialog_settings.save_ini(); + save(); close(); break; case QMessageBox::Discard: + s.b->revert(); close(); break; case QMessageBox::Cancel: @@ -319,8 +269,6 @@ void TrackerDialog::create_video_widget() video_widget_dialog->setAttribute( Qt::WA_DeleteOnClose ); connect( video_widget_dialog, SIGNAL(destroyed(QObject*)), this, SLOT(widget_destroyed(QObject*)) ); video_widget_dialog->show(); - - ui.videowidget_button->setEnabled(false); } void TrackerDialog::destroy_video_widget(bool do_delete /*= true*/) @@ -329,7 +277,6 @@ void TrackerDialog::destroy_video_widget(bool do_delete /*= true*/) if (do_delete) delete video_widget_dialog; video_widget_dialog = NULL; } - if (tracker) ui.videowidget_button->setEnabled(true); } void TrackerDialog::poll_tracker_info() @@ -369,24 +316,12 @@ void TrackerDialog::poll_tracker_info() } } - -//----------------------------------------------------------------------------- -// ITrackerDialog interface -void TrackerDialog::Initialize(QWidget *parent) -{ - QPoint offsetpos(200, 200); - if (parent) { - this->move(parent->pos() + offsetpos); - } - show(); -} - void TrackerDialog::registerTracker(ITracker *t) { qDebug()<<"TrackerDialog:: Tracker registered"; tracker = static_cast(t); - if (isVisible() && settings_dirty) tracker->apply(settings); - ui.videowidget_button->setEnabled(true); + if (isVisible() & s.b->modifiedp()) + tracker->apply(s); ui.tcalib_button->setEnabled(true); //ui.center_button->setEnabled(true); ui.reset_button->setEnabled(true); @@ -397,19 +332,12 @@ void TrackerDialog::unRegisterTracker() qDebug()<<"TrackerDialog:: Tracker un-registered"; tracker = NULL; destroy_video_widget(); - ui.videowidget_button->setEnabled(false); ui.tcalib_button->setEnabled(false); //ui.center_button->setEnabled(false); ui.reset_button->setEnabled(false); } -//----------------------------------------------------------------------------- -#ifdef OPENTRACK_API extern "C" FTNOIR_TRACKER_BASE_EXPORT ITrackerDialog* CALLING_CONVENTION GetDialog( ) -#else -#pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0") -FTNOIR_TRACKER_BASE_EXPORT ITrackerDialogPtr __stdcall GetTrackerDialog( ) -#endif { return new TrackerDialog; } diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h index de743ad8..0325160d 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h @@ -28,71 +28,24 @@ class TrackerDialog : public QWidget, Ui::UICPTClientControls, public ITrackerDi Q_OBJECT public: TrackerDialog(); - ~TrackerDialog(); - - // ITrackerDialog interface - void Initialize(QWidget *parent); void registerTracker(ITracker *tracker); void unRegisterTracker(); - + void save(); void trans_calib_step(); -protected slots: - // ugly qt stuff - void set_video_widget(bool val) { settings.video_widget = val; settings_changed(); } - void set_dyn_pose_res(bool val) { settings.dyn_pose_res = val; settings_changed(); } - void set_sleep_time(int val) { settings.sleep_time = val; settings_changed(); } - void set_reset_time(int val) { settings.reset_time = val; settings_changed(); } - void set_cam_index(int idx) { settings.cam_index = idx; settings_changed(); } - void set_cam_f(double val) { settings.cam_f = val; settings_changed(); } - void set_cam_res_x(int val) { settings.cam_res_x = val; settings_changed(); } - void set_cam_res_y(int val) { settings.cam_res_y = val; settings_changed(); } - void set_cam_fps(int val) { settings.cam_fps = val; settings_changed(); } - void set_cam_roll(int idx); - void set_cam_pitch(int val) { settings.cam_pitch = val; settings_changed(); } - void set_cam_yaw(int val) { settings.cam_yaw = val; settings_changed(); } - void set_min_point_size(int val) { settings.min_point_size = val; settings_changed(); } - void set_max_point_size(int val) { settings.max_point_size = val; settings_changed(); } - void set_threshold(int val) { settings.threshold = val; settings_changed(); } - void set_threshold_secondary(int val) { settings.threshold_secondary = val; settings_changed(); } - void set_ena_roll(bool val) { settings.bEnableRoll = val; settings_changed(); } - void set_ena_pitch(bool val) { settings.bEnablePitch = val; settings_changed(); } - void set_ena_yaw(bool val) { settings.bEnableYaw = val; settings_changed(); } - void set_ena_x(bool val) { settings.bEnableX = val; settings_changed(); } - void set_ena_y(bool val) { settings.bEnableY = val; settings_changed(); } - void set_ena_z(bool val) { settings.bEnableZ = val; settings_changed(); } - - void set_clip_t_height(int val) { dialog_settings.clip_ty = val; set_model_clip(); } - void set_clip_t_length(int val) { dialog_settings.clip_tz = val; set_model_clip(); } - void set_clip_b_height(int val) { dialog_settings.clip_by = val; set_model_clip(); } - void set_clip_b_length(int val) { dialog_settings.clip_bz = val; set_model_clip(); } - void set_cap_width(int val) { dialog_settings.cap_x = val; set_model_cap(); } - void set_cap_height(int val) { dialog_settings.cap_y = val; set_model_cap(); } - void set_cap_length(int val) { dialog_settings.cap_z = val; set_model_cap(); } - void set_m1x(int val) { dialog_settings.M01x = val; set_model_custom(); } - void set_m1y(int val) { dialog_settings.M01y = val; set_model_custom(); } - void set_m1z(int val) { dialog_settings.M01z = val; set_model_custom(); } - void set_m2x(int val) { dialog_settings.M02x = val; set_model_custom(); } - void set_m2y(int val) { dialog_settings.M02y = val; set_model_custom(); } - void set_m2z(int val) { dialog_settings.M02z = val; set_model_custom(); } - void set_tx(int val) { settings.t_MH[0] = val; settings_changed(); } - void set_ty(int val) { settings.t_MH[1] = val; settings_changed(); } - void set_tz(int val) { settings.t_MH[2] = val; settings_changed(); } - void set_model(int model_id); - - void doCenter(); - void doReset(); - +public slots: + void doCenter(); + void doReset(); void doOK(); + void doApply(); void doCancel(); + void do_apply_without_saving(); void startstop_trans_calib(bool start); - void widget_destroyed(QObject* obj); - void create_video_widget(); - void poll_tracker_info(); + void set_model(int idx); protected: void destroy_video_widget(bool do_delete = true); @@ -103,15 +56,11 @@ protected: void settings_changed(); - TrackerSettings settings; - TrackerDialogSettings dialog_settings; - bool settings_dirty; - + settings s; Tracker* tracker; + VideoWidgetDialog* video_widget_dialog; QTimer timer; - VideoWidgetDialog* video_widget_dialog; - TranslationCalibrator trans_calib; bool trans_calib_running; diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp deleted file mode 100644 index 50835cb8..00000000 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* Copyright (c) 2012 Patrick Ruoff - * - * 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 "ftnoir_tracker_pt.h" -#include -#include - -//----------------------------------------------------------------------------- -void TrackerSettings::load_ini() -{ - qDebug("TrackerSettings::load_ini()"); - - QSettings settings("opentrack"); - QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - iniFile.beginGroup( "PointTracker" ); - - cam_index = iniFile.value("CameraId", 0).toInt(); - cam_f = iniFile.value("CameraF", 1).toFloat(); - cam_res_x = iniFile.value("CameraResX", 640).toInt(); - cam_res_y = iniFile.value("CameraResY", 480).toInt(); - cam_fps = iniFile.value("CameraFPS", 30).toInt(); - cam_roll = iniFile.value("CameraRoll", 0).toInt(); - cam_pitch = iniFile.value("CameraPitch", 0).toInt(); - cam_yaw = iniFile.value("CameraYaw", 0).toInt(); - threshold = iniFile.value("PointExtractThreshold", 128).toInt(); - threshold_secondary = iniFile.value("PointExtractThresholdSecondary", 128).toInt(); - min_point_size = iniFile.value("PointExtractMinSize", 2).toInt(); - max_point_size = iniFile.value("PointExtractMaxSize", 50).toInt(); - M01[0] = iniFile.value("PointModelM01x", 0).toFloat(); - M01[1] = iniFile.value("PointModelM01y", 40).toFloat(); - M01[2] = iniFile.value("PointModelM01z", -30).toFloat(); - M02[0] = iniFile.value("PointModelM02x", 0).toFloat(); - M02[1] = iniFile.value("PointModelM02y", -70).toFloat(); - M02[2] = iniFile.value("PointModelM02z", -80).toFloat(); - t_MH[0] = iniFile.value("tMHx", 0).toFloat(); - t_MH[1] = iniFile.value("tMHy", 0).toFloat(); - t_MH[2] = iniFile.value("tMHz", 0).toFloat(); - dyn_pose_res = iniFile.value("DynamicPoseResolution", true).toBool(); - video_widget = iniFile.value("VideoWidget", true).toBool(); - sleep_time = iniFile.value("SleepTime", 10).toInt(); - reset_time = iniFile.value("ResetTime", 1000).toInt(); - - bEnableRoll = iniFile.value("EnableRoll", 1).toBool(); - bEnablePitch = iniFile.value("EnablePitch", 1).toBool(); - bEnableYaw = iniFile.value("EnableYaw", 1).toBool(); - bEnableX = iniFile.value("EnableX", 1).toBool(); - bEnableY = iniFile.value("EnableY", 1).toBool(); - bEnableZ = iniFile.value("EnableZ", 1).toBool(); - - iniFile.endGroup(); -} - -void TrackerSettings::save_ini() const -{ - qDebug("TrackerSettings::save_ini()"); - - QSettings settings("opentrack"); - QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - iniFile.beginGroup ( "PointTracker" ); - - iniFile.setValue("CameraId", cam_index); - iniFile.setValue("CameraF", cam_f); - iniFile.setValue("CameraResX", cam_res_x); - iniFile.setValue("CameraResY", cam_res_y); - iniFile.setValue("CameraFPS", cam_fps); - iniFile.setValue("CameraRoll", cam_roll); - iniFile.setValue("CameraPitch", cam_pitch); - iniFile.setValue("CameraYaw", cam_yaw); - iniFile.setValue("PointExtractThreshold", threshold); - iniFile.setValue("PointExtractThresholdSecondary", threshold_secondary); - iniFile.setValue("PointExtractMinSize", min_point_size); - iniFile.setValue("PointExtractMaxSize", max_point_size); - iniFile.setValue("PointModelM01x", M01[0]); - iniFile.setValue("PointModelM01y", M01[1]); - iniFile.setValue("PointModelM01z", M01[2]); - iniFile.setValue("PointModelM02x", M02[0]); - iniFile.setValue("PointModelM02y", M02[1]); - iniFile.setValue("PointModelM02z", M02[2]); - iniFile.setValue("tMHx", t_MH[0]); - iniFile.setValue("tMHy", t_MH[1]); - iniFile.setValue("tMHz", t_MH[2]); - iniFile.setValue("DynamicPoseResolution", dyn_pose_res); - iniFile.setValue("VideoWidget", video_widget); - iniFile.setValue("SleepTime", sleep_time); - iniFile.setValue("ResetTime", reset_time); - - iniFile.setValue( "EnableRoll", bEnableRoll ); - iniFile.setValue( "EnablePitch", bEnablePitch ); - iniFile.setValue( "EnableYaw", bEnableYaw ); - iniFile.setValue( "EnableX", bEnableX ); - iniFile.setValue( "EnableY", bEnableY ); - iniFile.setValue( "EnableZ", bEnableZ ); - - iniFile.endGroup(); -} - -//----------------------------------------------------------------------------- -void TrackerDialogSettings::load_ini() -{ - qDebug("TrackerDialogSettings::load_ini()"); - - QSettings settings("opentrack"); - QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - iniFile.beginGroup( "PointTrackerDialog" ); - - active_model_panel = iniFile.value("ActiveModelPanel", MODEL_CLIP).toInt(); - M01x = iniFile.value("CustomM01x", 0).toInt(); - M01y = iniFile.value("CustomM01y", 40).toInt(); - M01z = iniFile.value("CustomM01z", -30).toInt(); - M02x = iniFile.value("CustomM02x", 0).toInt(); - M02y = iniFile.value("CustomM02y", -70).toInt(); - M02z = iniFile.value("CustomM02z", -80).toInt(); - clip_ty = iniFile.value("ClipTopHeight", 40).toInt(); - clip_tz = iniFile.value("ClipTopLength", 30).toInt(); - clip_by = iniFile.value("ClipBottomHeight", 70).toInt(); - clip_bz = iniFile.value("ClipBottomLength", 80).toInt(); - cap_x = iniFile.value("CapHalfWidth", 40).toInt(); - cap_y = iniFile.value("CapHeight", 60).toInt(); - cap_z = iniFile.value("CapLength", 100).toInt(); -} - -void TrackerDialogSettings::save_ini() const -{ - qDebug("TrackerDialogSettings::save_ini()"); - - QSettings settings("opentrack"); - QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - - iniFile.beginGroup ( "PointTrackerDialog" ); - - iniFile.setValue("ActiveModelPanel", active_model_panel); - iniFile.setValue("CustomM01x", M01x); - iniFile.setValue("CustomM01y", M01y); - iniFile.setValue("CustomM01z", M01z); - iniFile.setValue("CustomM02x", M02x); - iniFile.setValue("CustomM02y", M02y); - iniFile.setValue("CustomM02z", M02z); - iniFile.setValue("ClipTopHeight", clip_ty); - iniFile.setValue("ClipTopLength", clip_tz); - iniFile.setValue("ClipBottomHeight", clip_by); - iniFile.setValue("ClipBottomLength", clip_bz); - iniFile.setValue("CapHalfWidth", cap_x); - iniFile.setValue("CapHeight", cap_y); - iniFile.setValue("CapLength", cap_z); -} diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h index 91a7a8d5..8c590db2 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h @@ -11,80 +11,81 @@ #include #include "point_tracker.h" +#include "facetracknoir/options.hpp" +using namespace options; -//----------------------------------------------------------------------------- -// Tracker settings and their ini-IO -struct TrackerSettings -{ - // camera - int cam_index; - float cam_f; - int cam_res_x; - int cam_res_y; - int cam_fps; - int cam_roll; - int cam_pitch; - int cam_yaw; - - // point extraction - int threshold; - int threshold_secondary; - - int min_point_size; - int max_point_size; - - // point tracking - cv::Vec3f M01; - cv::Vec3f M02; - bool dyn_pose_res; - - // head to model translation - cv::Vec3f t_MH; - - int sleep_time; // in ms - int reset_time; // in ms - bool video_widget; +struct settings +{ + pbundle b; + value cam_index, + cam_res_x, + cam_res_y, + cam_fps, + cam_roll, + cam_pitch, + cam_yaw, + threshold, + threshold_secondary, + min_point_size, + max_point_size; + value cam_f; - bool bEnableRoll; - bool bEnablePitch; - bool bEnableYaw; - bool bEnableX; - bool bEnableY; - bool bEnableZ; + value m01_x, m01_y, m01_z; + value m02_x, m02_y, m02_z; + value dyn_pose_res, video_widget; - void load_ini(); - void save_ini() const; -}; + value t_MH_x, t_MH_y, t_MH_z; + value sleep_time, reset_time; -//----------------------------------------------------------------------------- -// Settings specific to the tracker dialog and their ini-IO -struct TrackerDialogSettings -{ - enum - { - MODEL_CLIP, - MODEL_CAP, - MODEL_CUSTOM - }; - int active_model_panel; + value bEnableYaw, bEnablePitch, bEnableRoll; + value bEnableX, bEnableY, bEnableZ; - int M01x; - int M01y; - int M01z; - int M02x; - int M02y; - int M02z; - int clip_ty; - int clip_tz; - int clip_by; - int clip_bz; - int cap_x; - int cap_y; - int cap_z; + value clip_ty, clip_tz, clip_by, clip_bz; + value active_model_panel, cap_x, cap_y, cap_z; - void load_ini(); - void save_ini() const; + settings() : + b(bundle("tracker-pt")), + cam_index(b, "camera-index", 0), + cam_res_x(b, "camera-res-width", 640), + cam_res_y(b, "camera-res-height", 480), + cam_fps(b, "camera-fps", 30), + cam_roll(b, "camera-roll", 1), + cam_pitch(b, "camera-pitch", 0), + cam_yaw(b, "camera-yaw", 0), + threshold(b, "threshold-primary", 128), + threshold_secondary(b, "threshold-secondary", 128), + min_point_size(b, "min-point-size", 10), + max_point_size(b, "max-point-size", 50), + cam_f(b, "camera-focal-length", 1), + m01_x(b, "m_01-x", 0), + m01_y(b, "m_01-y", 0), + m01_z(b, "m_01-z", 0), + m02_x(b, "m_02-x", 0), + m02_y(b, "m_02-y", 0), + m02_z(b, "m_02-z", 0), + dyn_pose_res(b, "dynamic-pose-resolution", false), + video_widget(b, "video-widget", true), + t_MH_x(b, "model-centroid-x", 0), + t_MH_y(b, "model-centroid-y", 0), + t_MH_z(b, "model-centroid-z", 0), + sleep_time(b, "sleep-time", 0), + reset_time(b, "reset-time", 0), + bEnableYaw(b, "enable-yaw", true), + bEnablePitch(b, "enable-pitch", true), + bEnableRoll(b, "enable-roll", true), + bEnableX(b, "enable-x", true), + bEnableY(b, "enable-y", true), + bEnableZ(b, "enable-z", true), + clip_ty(b, "clip-ty", 0), + clip_tz(b, "clip-tz", 0), + clip_by(b, "clip-by", 0), + clip_bz(b, "clip-bz", 0), + active_model_panel(b, "active-model-panel", 0), + cap_x(b, "cap-x", 0), + cap_y(b, "cap-y", 0), + cap_z(b, "cap-z", 0) + {} }; -#endif //FTNOIR_TRACKER_PT_SETTINGS_H \ No newline at end of file +#endif //FTNOIR_TRACKER_PT_SETTINGS_H -- cgit v1.2.3 From b66bf8bccc9a52d8c24763010567da8c083c482e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 4 Jan 2014 13:26:04 +0100 Subject: PT: remove sleep interval The rationale is that camera blocks while the frame's being retrieved anyway. --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 161 +++++++++---------------- FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 43 +++---- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp | 1 - FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h | 3 +- 4 files changed, 81 insertions(+), 127 deletions(-) (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index 6cd17e8d..ce708849 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -10,7 +10,7 @@ 0 0 459 - 590 + 621 @@ -66,105 +66,65 @@ Tracker Thread - - - - - - - - - Time until automatic reset of tracker's internal state when no valid tracking result is found - - - 9999 - - - - - - - ms - - - - - - - - - - - - - - - - - - - Dynamic Pose Resolution - - - - - - - Sleep time - - - sleep_spin - - - - - - - Auto-reset time - - - reset_spin - - - - - - - - - Time the tracker thread sleeps after each processed frame - - - - - - 9999 - - - - - - - ms - - - - - - - - - false - - - Reset the tracker's internal state - - - Reset - - - - + + + + + Auto-reset time + + + reset_spin + + + + + + + + 0 + 0 + + + + Time until automatic reset of tracker's internal state when no valid tracking result is found + + + ms + + + 9999 + + + + + + + Dynamic Pose Resolution + + + + + + + + + + + + + + + + + false + + + Reset the tracker's internal state + + + Reset + + @@ -1759,7 +1719,6 @@ tabWidget - sleep_spin reset_spin chkEnableRoll chkEnablePitch diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp index fad53d60..e8bc7208 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp @@ -70,31 +70,28 @@ void Tracker::run() bool new_frame; forever { - { - QMutexLocker lock(&mutex); - - if (commands & ABORT) break; - if (commands & PAUSE) continue; - commands = 0; - - dt = time.elapsed() / 1000.0; - time.restart(); - - new_frame = camera.get_frame(dt, &frame); - if (new_frame && !frame.empty()) - { - frame = frame_rotation.rotate_frame(frame); - const std::vector& points = point_extractor.extract_points(frame, dt, has_observers()); - tracking_valid = point_tracker.track(points, camera.get_info().f, dt); - video_widget->update_image(frame.clone()); - } + QMutexLocker lock(&mutex); + + if (commands & ABORT) break; + if (commands & PAUSE) continue; + commands = 0; + + dt = time.elapsed() / 1000.0; + time.restart(); + + new_frame = camera.get_frame(dt, &frame); + if (new_frame && !frame.empty()) + { + frame = frame_rotation.rotate_frame(frame); + const std::vector& points = point_extractor.extract_points(frame, dt, has_observers()); + tracking_valid = point_tracker.track(points, camera.get_info().f, dt); + video_widget->update_image(frame.clone()); + } #ifdef PT_PERF_LOG - log_stream<<"dt: "<addItem("90"); tie_setting(s.dyn_pose_res, ui.dynpose_check); - tie_setting(s.sleep_time, ui.sleep_spin); tie_setting(s.reset_time, ui.reset_spin); tie_setting(s.cam_index, ui.camdevice_combo); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h index a828ea48..564e1264 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h @@ -36,7 +36,7 @@ struct settings value t_MH_x, t_MH_y, t_MH_z; - value sleep_time, reset_time; + value reset_time; value bEnableYaw, bEnablePitch, bEnableRoll; value bEnableX, bEnableY, bEnableZ; @@ -69,7 +69,6 @@ struct settings t_MH_x(b, "model-centroid-x", 0), t_MH_y(b, "model-centroid-y", 0), t_MH_z(b, "model-centroid-z", 0), - sleep_time(b, "sleep-time", 0), reset_time(b, "reset-time", 0), bEnableYaw(b, "enable-yaw", true), bEnablePitch(b, "enable-pitch", true), -- cgit v1.2.3 From cc3a10f7117b11b4b3f2644224ae728e395a9e9b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 5 Jan 2014 12:14:21 +0100 Subject: change icons, remove self-references --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 2 +- FTNoIR_Tracker_PT/Resources/icon.ico | Bin 4286 -> 0 bytes FTNoIR_Tracker_PT/ftnoir_tracker_pt.qrc | 19 ++++---- facetracknoir/facetracknoir.cpp | 2 +- facetracknoir/facetracknoir.ui | 48 ++++++++++----------- facetracknoir/ftnoir_keyboardshortcuts.ui | 2 +- .../uielements/logo_facetracknoir_32px.jpg | Bin 1082 -> 0 bytes .../uielements/logo_facetracknoir_32px.png | Bin 2822 -> 0 bytes facetracknoir/uielements/logo_noir.png | Bin 26173 -> 0 bytes facetracknoir/uielements/logo_noir_small.png | Bin 6384 -> 0 bytes .../uielements/logo_noir_small_target.png | Bin 5971 -> 0 bytes .../uielements/logo_noir_small_target90px.png | Bin 5582 -> 0 bytes facetracknoir/uielements/logofacetracknoir.png | Bin 5437 -> 0 bytes facetracknoir/uielements/logofacetracknoir60px.png | Bin 3369 -> 0 bytes .../ftnoir_accela_filtercontrols.ui | 14 +++--- ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui | 16 +++---- .../ftnoir_kalman_filtercontrols.ui | 12 +++--- ftnoir_protocol_fg/ftnoir_fgcontrols.ui | 12 +++--- ftnoir_protocol_ft/ftnoir_ftcontrols.ui | 12 +++--- ftnoir_protocol_ftn/ftn-protocol.qrc | 5 --- ftnoir_protocol_ftn/ftnoir_ftncontrols.ui | 8 ++-- ftnoir_protocol_ftn/images/facetracknoir.png | Bin 634 -> 0 bytes ftnoir_protocol_mouse/ftnoir_mousecontrols.ui | 14 +++--- .../ftnoir_tracker_joystick_controls.ui | 4 +- ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui | 2 +- 25 files changed, 87 insertions(+), 85 deletions(-) delete mode 100644 FTNoIR_Tracker_PT/Resources/icon.ico delete mode 100644 facetracknoir/uielements/logo_facetracknoir_32px.jpg delete mode 100644 facetracknoir/uielements/logo_facetracknoir_32px.png delete mode 100644 facetracknoir/uielements/logo_noir.png delete mode 100644 facetracknoir/uielements/logo_noir_small.png delete mode 100644 facetracknoir/uielements/logo_noir_small_target.png delete mode 100644 facetracknoir/uielements/logo_noir_small_target90px.png delete mode 100644 facetracknoir/uielements/logofacetracknoir.png delete mode 100644 facetracknoir/uielements/logofacetracknoir60px.png delete mode 100644 ftnoir_protocol_ftn/ftn-protocol.qrc delete mode 100644 ftnoir_protocol_ftn/images/facetracknoir.png (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index ce708849..9f00cf29 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -24,7 +24,7 @@ - :/Resources/icon.ico:/Resources/icon.ico + :/Resources/Logo_IR.png:/Resources/Logo_IR.png Qt::LeftToRight diff --git a/FTNoIR_Tracker_PT/Resources/icon.ico b/FTNoIR_Tracker_PT/Resources/icon.ico deleted file mode 100644 index c4b2aedc..00000000 Binary files a/FTNoIR_Tracker_PT/Resources/icon.ico and /dev/null differ diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.qrc b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.qrc index 9b510981..a8f9a1af 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.qrc +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.qrc @@ -1,10 +1,9 @@ - - - Resources/icon.ico - Resources/cap_front.png - Resources/cap_side.png - Resources/clip_front.png - Resources/clip_side.png - Resources/Logo_IR.png - - + + + Resources/cap_front.png + Resources/cap_side.png + Resources/clip_front.png + Resources/clip_side.png + Resources/Logo_IR.png + + diff --git a/facetracknoir/facetracknoir.cpp b/facetracknoir/facetracknoir.cpp index de5b491f..f2767587 100644 --- a/facetracknoir/facetracknoir.cpp +++ b/facetracknoir/facetracknoir.cpp @@ -246,7 +246,7 @@ void FaceTrackNoIR::open() { QString fileName = dialog.getOpenFileName( this, - tr("Select one FTNoir settings file"), + tr("Open the settings file"), QCoreApplication::applicationDirPath() + "/settings/", tr("Settings file (*.ini);;All Files (*)"), NULL); diff --git a/facetracknoir/facetracknoir.ui b/facetracknoir/facetracknoir.ui index c25ee0db..d5300b0f 100644 --- a/facetracknoir/facetracknoir.ui +++ b/facetracknoir/facetracknoir.ui @@ -10,8 +10,8 @@ 0 0 - 788 - 554 + 790 + 500 @@ -82,8 +82,8 @@ - 5 - 170 + 10 + 130 320 240 @@ -113,7 +113,7 @@ 0 - -10 + 0 320 240 @@ -141,8 +141,8 @@ - 110 - 50 + 100 + 10 229 121 @@ -516,8 +516,8 @@ - 20 - 50 + 10 + 20 81 100 @@ -545,7 +545,7 @@ 350 - 370 + 270 191 91 @@ -631,7 +631,7 @@ 580 - 460 + 390 171 38 @@ -677,9 +677,9 @@ - 130 - 30 - 651 + 370 + 40 + 411 20 @@ -702,9 +702,9 @@ - 350 - 270 - 191 + 550 + 210 + 231 91 @@ -868,9 +868,9 @@ - 130 - 0 - 651 + 370 + 10 + 411 25 @@ -980,7 +980,7 @@ 350 - 470 + 400 190 65 @@ -1060,7 +1060,7 @@ 580 - 410 + 340 171 38 @@ -1228,7 +1228,7 @@ 10 - 420 + 380 141 106 @@ -1468,7 +1468,7 @@ 160 - 420 + 380 161 111 diff --git a/facetracknoir/ftnoir_keyboardshortcuts.ui b/facetracknoir/ftnoir_keyboardshortcuts.ui index 0d4e9142..94d11734 100644 --- a/facetracknoir/ftnoir_keyboardshortcuts.ui +++ b/facetracknoir/ftnoir_keyboardshortcuts.ui @@ -21,7 +21,7 @@ - images/FaceTrackNoIR.pngimages/FaceTrackNoIR.png + images/facetracknoir.pngimages/facetracknoir.png Qt::LeftToRight diff --git a/facetracknoir/uielements/logo_facetracknoir_32px.jpg b/facetracknoir/uielements/logo_facetracknoir_32px.jpg deleted file mode 100644 index 73ead853..00000000 Binary files a/facetracknoir/uielements/logo_facetracknoir_32px.jpg and /dev/null differ diff --git a/facetracknoir/uielements/logo_facetracknoir_32px.png b/facetracknoir/uielements/logo_facetracknoir_32px.png deleted file mode 100644 index c4e63c76..00000000 Binary files a/facetracknoir/uielements/logo_facetracknoir_32px.png and /dev/null differ diff --git a/facetracknoir/uielements/logo_noir.png b/facetracknoir/uielements/logo_noir.png deleted file mode 100644 index bb654a07..00000000 Binary files a/facetracknoir/uielements/logo_noir.png and /dev/null differ diff --git a/facetracknoir/uielements/logo_noir_small.png b/facetracknoir/uielements/logo_noir_small.png deleted file mode 100644 index 5d49e0b1..00000000 Binary files a/facetracknoir/uielements/logo_noir_small.png and /dev/null differ diff --git a/facetracknoir/uielements/logo_noir_small_target.png b/facetracknoir/uielements/logo_noir_small_target.png deleted file mode 100644 index 4bbaf41f..00000000 Binary files a/facetracknoir/uielements/logo_noir_small_target.png and /dev/null differ diff --git a/facetracknoir/uielements/logo_noir_small_target90px.png b/facetracknoir/uielements/logo_noir_small_target90px.png deleted file mode 100644 index ecaa4e12..00000000 Binary files a/facetracknoir/uielements/logo_noir_small_target90px.png and /dev/null differ diff --git a/facetracknoir/uielements/logofacetracknoir.png b/facetracknoir/uielements/logofacetracknoir.png deleted file mode 100644 index a1a3407b..00000000 Binary files a/facetracknoir/uielements/logofacetracknoir.png and /dev/null differ diff --git a/facetracknoir/uielements/logofacetracknoir60px.png b/facetracknoir/uielements/logofacetracknoir60px.png deleted file mode 100644 index f01f6024..00000000 Binary files a/facetracknoir/uielements/logofacetracknoir60px.png and /dev/null differ diff --git a/ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui b/ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui index 4ea78c9f..ba750cd6 100644 --- a/ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui +++ b/ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui @@ -9,8 +9,8 @@ 0 0 - 202 - 241 + 215 + 285 @@ -32,11 +32,11 @@ - Filter settings + Accela filter settings - - images/FaceTrackNoIR.pngimages/FaceTrackNoIR.png + + :/images/filter-16.png:/images/filter-16.png Qt::LeftToRight @@ -346,7 +346,9 @@ background:none; - + + + startEngineClicked() diff --git a/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui b/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui index 8a0e485a..a1083265 100644 --- a/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui +++ b/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui @@ -9,7 +9,7 @@ 0 0 - 374 + 477 380 @@ -20,15 +20,11 @@ - EWMA2 Filter settings FaceTrackNoIR + EWMA2 filter settings - - - images/facetracknoir.png - - images/facetracknoir.png - + + :/images/filter-16.png:/images/filter-16.png Qt::LeftToRight @@ -486,7 +482,9 @@ p, li { white-space: pre-wrap; } btnOK btnCancel - + + + minSmooth diff --git a/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui b/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui index d1cff81e..a9fdec6e 100644 --- a/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui +++ b/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui @@ -20,13 +20,11 @@ - Filter settings + Kalman settings - - - images/facetracknoir.png - images/facetracknoir.png + + :/images/filter-16.png:/images/filter-16.png Qt::LeftToRight @@ -64,7 +62,9 @@ - + + + diff --git a/ftnoir_protocol_fg/ftnoir_fgcontrols.ui b/ftnoir_protocol_fg/ftnoir_fgcontrols.ui index f3b54486..e351647b 100644 --- a/ftnoir_protocol_fg/ftnoir_fgcontrols.ui +++ b/ftnoir_protocol_fg/ftnoir_fgcontrols.ui @@ -9,16 +9,16 @@ 0 0 - 404 + 415 112 - FlightGear settings FaceTrackNoIR + FlightGear protocol settings - - images/FaceTrackNoIR.pngimages/FaceTrackNoIR.png + + :/images/filter-16.png:/images/filter-16.png Qt::LeftToRight @@ -131,7 +131,9 @@ spinIPFourthNibble spinPortNumber - + + + startEngineClicked() diff --git a/ftnoir_protocol_ft/ftnoir_ftcontrols.ui b/ftnoir_protocol_ft/ftnoir_ftcontrols.ui index f4d94ee8..39787d90 100644 --- a/ftnoir_protocol_ft/ftnoir_ftcontrols.ui +++ b/ftnoir_protocol_ft/ftnoir_ftcontrols.ui @@ -13,7 +13,7 @@ 0 0 407 - 347 + 414 @@ -29,11 +29,11 @@ - FreeTrack 2.0 settings FaceTrackNoIR + freetrack protocol settings - - images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico + + :/images/freetrack.png:/images/freetrack.png Qt::LeftToRight @@ -214,7 +214,9 @@ - + + + startEngineClicked() diff --git a/ftnoir_protocol_ftn/ftn-protocol.qrc b/ftnoir_protocol_ftn/ftn-protocol.qrc deleted file mode 100644 index 18ae0aae..00000000 --- a/ftnoir_protocol_ftn/ftn-protocol.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - images/facetracknoir.png - - diff --git a/ftnoir_protocol_ftn/ftnoir_ftncontrols.ui b/ftnoir_protocol_ftn/ftnoir_ftncontrols.ui index ac6988d7..429e7046 100644 --- a/ftnoir_protocol_ftn/ftnoir_ftncontrols.ui +++ b/ftnoir_protocol_ftn/ftnoir_ftncontrols.ui @@ -17,8 +17,8 @@ UDP protocol settings - - images/FaceTrackNoIR.pngimages/FaceTrackNoIR.png + + :/images/facetracknoir.png:/images/facetracknoir.png Qt::LeftToRight @@ -254,7 +254,9 @@ btnOK btnCancel - + + + startEngineClicked() diff --git a/ftnoir_protocol_ftn/images/facetracknoir.png b/ftnoir_protocol_ftn/images/facetracknoir.png deleted file mode 100644 index b69a13ef..00000000 Binary files a/ftnoir_protocol_ftn/images/facetracknoir.png and /dev/null differ diff --git a/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui b/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui index ee15ded2..540e4f0d 100644 --- a/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui +++ b/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui @@ -9,16 +9,16 @@ 0 0 - 250 - 112 + 257 + 114 - MouseLook settings FaceTrackNoIR + Mouse protocol settings - - :/images/Mouse.png:/images/Mouse.png + + :/images/mouse.png:/images/mouse.png Qt::LeftToRight @@ -193,7 +193,9 @@ - + + + startEngineClicked() diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui index e1f1d28c..a0fa43d3 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui @@ -20,11 +20,11 @@ - Joystick protcool settings + Joystick protocol settings - images/FaceTrackNoIR.pngimages/FaceTrackNoIR.png + ../facetracknoir/images/facetracknoir.png../facetracknoir/images/facetracknoir.png Qt::LeftToRight diff --git a/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui b/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui index 6c71b50b..fc614477 100644 --- a/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui +++ b/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui @@ -18,7 +18,7 @@ - images/FaceTrackNoIR.pngimages/FaceTrackNoIR.png + ../facetracknoir/images/facetracknoir.png../facetracknoir/images/facetracknoir.png Qt::LeftToRight -- cgit v1.2.3 From 9b42cf232a918987d675cdf041e49c73e597b110 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 8 Jan 2014 17:12:37 +0100 Subject: fix hyst slider --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 3 +++ 1 file changed, 3 insertions(+) (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index 9f00cf29..db7a5998 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -766,6 +766,9 @@ 255 + + 1 + 100 -- cgit v1.2.3 From 98facf366f9e5100cbd8da4e55c10029be73d4e3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 8 Jan 2014 18:01:35 +0100 Subject: apply -> save, that's what it actually does --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index db7a5998..bdbed955 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -1679,7 +1679,7 @@ - Apply + Save -- cgit v1.2.3 From 267010ba42b00cfd1ecc73c86d99c647ff191175 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 8 Jan 2014 19:40:06 +0100 Subject: use levmarq instead of coplanar POSIT implemented in numerically unstable fashion Signed-off-by: Stanislaw Halik --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 13 +- FTNoIR_Tracker_PT/camera.cpp | 8 +- FTNoIR_Tracker_PT/camera.h | 6 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 4 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp | 2 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h | 4 +- FTNoIR_Tracker_PT/point_tracker.cpp | 191 ++++++------------------- FTNoIR_Tracker_PT/point_tracker.h | 33 ++++- 8 files changed, 92 insertions(+), 169 deletions(-) (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index bdbed955..461253cf 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -515,23 +515,26 @@ - F/W + FOV - f_dspin + fov_dspin - + The camera's focal length devided by its sensor width 2 + + 1.000000000000000 + - 0.100000000000000 + 1.000000000000000 @@ -1733,7 +1736,7 @@ res_x_spin res_y_spin fps_spin - f_dspin + fov_dspin camroll_combo campitch_spin camyaw_spin diff --git a/FTNoIR_Tracker_PT/camera.cpp b/FTNoIR_Tracker_PT/camera.cpp index 754533c5..8986be60 100644 --- a/FTNoIR_Tracker_PT/camera.cpp +++ b/FTNoIR_Tracker_PT/camera.cpp @@ -108,11 +108,11 @@ void Camera::set_device_index(int index) } } -void Camera::set_f(float f) +void Camera::set_fov(float f) { - if (cam_desired.f != f) + if (cam_desired.fov != f) { - cam_desired.f = f; + cam_desired.fov = f; _set_f(); } } @@ -208,7 +208,7 @@ void CVCamera::_set_index() void CVCamera::_set_f() { - cam_info.f = cam_desired.f; + cam_info.fov = cam_desired.fov; } void CVCamera::_set_fps() diff --git a/FTNoIR_Tracker_PT/camera.h b/FTNoIR_Tracker_PT/camera.h index ea68c387..6768e419 100644 --- a/FTNoIR_Tracker_PT/camera.h +++ b/FTNoIR_Tracker_PT/camera.h @@ -25,12 +25,12 @@ void get_camera_device_names(std::vector& device_names); // ---------------------------------------------------------------------------- struct CamInfo { - CamInfo() : res_x(0), res_y(0), fps(0), f(1) {} + CamInfo() : res_x(0), res_y(0), fps(0), fov(56) {} int res_x; int res_y; int fps; - float f; // (focal length) / (sensor width) + float fov; }; // ---------------------------------------------------------------------------- @@ -48,7 +48,7 @@ public: // calls corresponding template methods and reinitializes frame rate calculation void set_device_index(int index); - void set_f(float f); + void set_fov(float f); void set_fps(int fps); void set_res(int x_res, int y_res); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp index 6bcad861..a3e8919b 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp @@ -84,7 +84,7 @@ void Tracker::run() { frame = frame_rotation.rotate_frame(frame); const std::vector& points = point_extractor.extract_points(frame, dt, false); - tracking_valid = point_tracker.track(points, camera.get_info().f, dt); + tracking_valid = point_tracker.track(points, camera.get_info().fov, dt, frame.cols, frame.rows, t_MH); video_widget->update_image(frame); } #ifdef PT_PERF_LOG @@ -104,7 +104,7 @@ void Tracker::apply(settings& s) camera.set_device_index(s.cam_index); camera.set_res(s.cam_res_x, s.cam_res_y); camera.set_fps(s.cam_fps); - camera.set_f(s.cam_f); + camera.set_fov(s.cam_fov); frame_rotation.rotation = static_cast(static_cast(s.cam_roll)); point_extractor.threshold_val = s.threshold; point_extractor.threshold_secondary_val = s.threshold_secondary; diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp index c103b78c..4ae20f48 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp @@ -46,7 +46,7 @@ TrackerDialog::TrackerDialog() tie_setting(s.reset_time, ui.reset_spin); tie_setting(s.cam_index, ui.camdevice_combo); - tie_setting(s.cam_f, ui.f_dspin); + tie_setting(s.cam_fov, ui.fov_dspin); tie_setting(s.cam_res_x, ui.res_x_spin); tie_setting(s.cam_res_y, ui.res_y_spin); tie_setting(s.cam_fps, ui.fps_spin); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h index 564e1264..e0dfa2e6 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h @@ -28,7 +28,7 @@ struct settings threshold_secondary, min_point_size, max_point_size; - value cam_f; + value cam_fov; value m01_x, m01_y, m01_z; value m02_x, m02_y, m02_z; @@ -57,7 +57,7 @@ struct settings threshold_secondary(b, "threshold-secondary", 128), min_point_size(b, "min-point-size", 10), max_point_size(b, "max-point-size", 50), - cam_f(b, "camera-focal-length", 1), + cam_fov(b, "camera-fov", 56), m01_x(b, "m_01-x", 0), m01_y(b, "m_01-y", 0), m01_z(b, "m_01-z", 0), diff --git a/FTNoIR_Tracker_PT/point_tracker.cpp b/FTNoIR_Tracker_PT/point_tracker.cpp index dfefdaf8..1df70b17 100644 --- a/FTNoIR_Tracker_PT/point_tracker.cpp +++ b/FTNoIR_Tracker_PT/point_tracker.cpp @@ -17,23 +17,6 @@ using namespace cv; using namespace boost; using namespace std; -const float PI = 3.14159265358979323846f; - -// ---------------------------------------------------------------------------- -static void get_row(const Matx33f& m, int i, Vec3f& v) -{ - v[0] = m(i,0); - v[1] = m(i,1); - v[2] = m(i,2); -} - -static void set_row(Matx33f& m, int i, const Vec3f& v) -{ - m(i,0) = v[0]; - m(i,1) = v[1]; - m(i,2) = v[2]; -} - // ---------------------------------------------------------------------------- PointModel::PointModel(Vec3f M01, Vec3f M02) : M01(M01), @@ -108,9 +91,11 @@ PointTracker::PointTracker() dt_reset(1), v_t(0,0,0), v_r(0,0,0), - dynamic_pose_resolution(true) + dynamic_pose_resolution(true), + fov(0), + _w(0), + _h(0) { - X_CM.t[2] = 1000; // default position: 1 m away from cam; } void PointTracker::reset() @@ -128,7 +113,7 @@ void PointTracker::reset_velocities() } -bool PointTracker::track(const vector& points, float f, float dt) +bool PointTracker::track(const vector& points, float fov, float dt, int w, int h, const cv::Vec3f& headpos) { if (!dynamic_pose_resolution) init_phase = true; @@ -140,12 +125,7 @@ bool PointTracker::track(const vector& points, float f, float dt) reset(); } - bool no_model = -#ifdef OPENTRACK_API - point_model.get() == NULL; -#else - !point_model; -#endif + bool no_model = !point_model; // if there is a pointtracking problem, reset the velocities if (no_model || points.size() != PointModel::N_POINTS) @@ -161,7 +141,7 @@ bool PointTracker::track(const vector& points, float f, float dt) predict(dt_valid); // if there is a point correspondence problem something has gone wrong, do a reset - if (!find_correspondences(points, f)) + if (!find_correspondences(points)) { //qDebug()<<"Error in finding point correspondences!"; X_CM = X_CM_old; // undo prediction @@ -169,7 +149,8 @@ bool PointTracker::track(const vector& points, float f, float dt) return false; } - int n_iter = POSIT(f); + // XXX TODO fov + POSIT(fov, w, h, headpos); //qDebug()<<"Number of POSIT iterations: "<& points, float f) +bool PointTracker::find_correspondences(const vector& points) { if (init_phase) { // We do a simple freetrack-like sorting in the init phase... @@ -215,9 +196,9 @@ bool PointTracker::find_correspondences(const vector& points, float f) else { // ... otherwise we look at the distance to the projection of the expected model points // project model points under current pose - p_exp[0] = project(Vec3f(0,0,0), f); - p_exp[1] = project(point_model->M01, f); - p_exp[2] = project(point_model->M02, f); + p_exp[0] = project(Vec3f(0,0,0)); + p_exp[1] = project(point_model->M01); + p_exp[2] = project(point_model->M02); // set correspondences by minimum distance to projected model point bool point_taken[PointModel::N_POINTS]; @@ -251,130 +232,48 @@ bool PointTracker::find_correspondences(const vector& points, float f) -int PointTracker::POSIT(float f) +void PointTracker::POSIT(float fov, int w, int h, const cv::Vec3f& headpos) { - // POSIT algorithm for coplanar points as presented in - // [Denis Oberkampf, Daniel F. DeMenthon, Larry S. Davis: "Iterative Pose Estimation Using Coplanar Feature Points"] - // we use the same notation as in the paper here - - // The expected rotation used for resolving the ambiguity in POSIT: - // In every iteration step the rotation closer to R_expected is taken - Matx33f R_expected; - if (init_phase) - R_expected = Matx33f::eye(); // in the init phase, we want to be close to the default pose = no rotation - else - R_expected = X_CM.R; // later we want to be close to the last (predicted) rotation - - // initial pose = last (predicted) pose - Vec3f k; - get_row(R_expected, 2, k); - float Z0 = init_phase ? 1000 : X_CM.t[2]; - - float old_epsilon_1 = 0; - float old_epsilon_2 = 0; - float epsilon_1 = 1; - float epsilon_2 = 1; - - Vec3f I0, J0; - Vec2f I0_coeff, J0_coeff; - - Vec3f I_1, J_1, I_2, J_2; - Matx33f R_1, R_2; - Matx33f* R_current; - - const int MAX_ITER = 100; - const float EPS_THRESHOLD = 1e-4; - - int i=1; - for (; iM01)/Z0; - epsilon_2 = k.dot(point_model->M02)/Z0; - - // vector of scalar products and - Vec2f I0_M0i(p[1][0]*(1.0 + epsilon_1) - p[0][0], - p[2][0]*(1.0 + epsilon_2) - p[0][0]); - Vec2f J0_M0i(p[1][1]*(1.0 + epsilon_1) - p[0][1], - p[2][1]*(1.0 + epsilon_2) - p[0][1]); - - // construct projection of I, J onto M0i plane: I0 and J0 - I0_coeff = point_model->P * I0_M0i; - J0_coeff = point_model->P * J0_M0i; - I0 = I0_coeff[0]*point_model->M01 + I0_coeff[1]*point_model->M02; - J0 = J0_coeff[0]*point_model->M01 + J0_coeff[1]*point_model->M02; - - // calculate u component of I, J - float II0 = I0.dot(I0); - float IJ0 = I0.dot(J0); - float JJ0 = J0.dot(J0); - float rho, theta; - if (JJ0 == II0) { - rho = sqrt(abs(2*IJ0)); - theta = -PI/4; - if (IJ0<0) theta *= -1; - } - else { - rho = sqrt(sqrt( (JJ0-II0)*(JJ0-II0) + 4*IJ0*IJ0 )); - theta = atan( -2*IJ0 / (JJ0-II0) ); - if (JJ0 - II0 < 0) theta += PI; - theta /= 2; - } + // XXX hack + this->fov = fov; + _w = w; + _h = h; + std::vector obj_points; + std::vector img_points; - // construct the two solutions - I_1 = I0 + rho*cos(theta)*point_model->u; - I_2 = I0 - rho*cos(theta)*point_model->u; + obj_points.push_back(headpos); + obj_points.push_back(point_model->M01 + headpos); + obj_points.push_back(point_model->M02 + headpos); - J_1 = J0 + rho*sin(theta)*point_model->u; - J_2 = J0 - rho*sin(theta)*point_model->u; + img_points.push_back(p[0]); + img_points.push_back(p[1]); + img_points.push_back(p[2]); - float norm_const = 1.0/norm(I_1); // all have the same norm - - // create rotation matrices - I_1 *= norm_const; J_1 *= norm_const; - I_2 *= norm_const; J_2 *= norm_const; + const float HT_PI = 3.1415926535; - set_row(R_1, 0, I_1); - set_row(R_1, 1, J_1); - set_row(R_1, 2, I_1.cross(J_1)); - - set_row(R_2, 0, I_2); - set_row(R_2, 1, J_2); - set_row(R_2, 2, I_2.cross(J_2)); + const float focal_length_w = 0.5 * w / tan(fov * HT_PI / 180); + const float focal_length_h = 0.5 * h / tan(fov * h / w * HT_PI / 180.0); - // the single translation solution - Z0 = norm_const * f; + cv::Mat intrinsics = cv::Mat::eye(3, 3, CV_32FC1); + intrinsics.at (0, 0) = focal_length_w; + intrinsics.at (1, 1) = focal_length_h; + intrinsics.at (0, 2) = w/2; + intrinsics.at (1, 2) = h/2; - // pick the rotation solution closer to the expected one - // in simple metric d(A,B) = || I - A * B^T || - float R_1_deviation = norm(Matx33f::eye() - R_expected * R_1.t()); - float R_2_deviation = norm(Matx33f::eye() - R_expected * R_2.t()); + cv::Mat dist_coeffs = cv::Mat::zeros(5, 1, CV_32FC1); - if (R_1_deviation < R_2_deviation) - R_current = &R_1; - else - R_current = &R_2; + bool lastp = !rvec.empty() && !tvec.empty() && !init_phase; - get_row(*R_current, 2, k); + cv::solvePnP(obj_points, img_points, intrinsics, dist_coeffs, rvec, tvec, lastp, cv::ITERATIVE); - // check for convergence condition - if (abs(epsilon_1 - old_epsilon_1) + abs(epsilon_2 - old_epsilon_2) < EPS_THRESHOLD) - break; - old_epsilon_1 = epsilon_1; - old_epsilon_2 = epsilon_2; - } + cv::Mat rmat; + cv::Rodrigues(rvec, rmat); // apply results - X_CM.R = *R_current; - X_CM.t[0] = p[0][0] * Z0/f; - X_CM.t[1] = p[0][1] * Z0/f; - X_CM.t[2] = Z0; - - return i; - - //Rodrigues(X_CM.R, r); - //qDebug()<<"iter: "<(i); + for (int j = 0; j < 3; j++) + X_CM.R(i, j) = rmat.at(i, j); + } } diff --git a/FTNoIR_Tracker_PT/point_tracker.h b/FTNoIR_Tracker_PT/point_tracker.h index 11034100..e05e8f98 100644 --- a/FTNoIR_Tracker_PT/point_tracker.h +++ b/FTNoIR_Tracker_PT/point_tracker.h @@ -90,7 +90,7 @@ public: // track the pose using the set of normalized point coordinates (x pos in range -0.5:0.5) // f : (focal length)/(sensor width) // dt : time since last call - bool track(const std::vector& points, float f, float dt); + bool track(const std::vector& points, float fov, float dt, int w, int h, const cv::Vec3f &headpos); boost::shared_ptr point_model; bool dynamic_pose_resolution; @@ -98,15 +98,35 @@ public: FrameTrafo get_pose() const { return X_CM; } void reset(); + float fov; + int _w, _h; protected: - inline cv::Vec2f project(const cv::Vec3f& v_M, float f) + cv::Vec2f project(const cv::Vec3f& v_M) { - cv::Vec3f v_C = X_CM * v_M; - return cv::Vec2f(f*v_C[0]/v_C[2], f*v_C[1]/v_C[2]); + if (!rvec.empty() && !tvec.empty() && fov > 0) + { + const float HT_PI = 3.1415926535; + const int w = _w, h = _h; + const float focal_length_w = 0.5 * w / tan(fov * HT_PI / 180); + const float focal_length_h = 0.5 * h / tan(fov * h / w * HT_PI / 180.0); + + cv::Mat intrinsics = cv::Mat::eye(3, 3, CV_32FC1); + intrinsics.at (0, 0) = focal_length_w; + intrinsics.at (1, 1) = focal_length_h; + intrinsics.at (0, 2) = w/2; + intrinsics.at (1, 2) = h/2; + std::vector xs; + xs.push_back(v_M); + cv::Mat dist_coeffs = cv::Mat::zeros(5, 1, CV_32FC1); + std::vector rets(1); + cv::projectPoints(xs, rvec, tvec, intrinsics, dist_coeffs, rets); + return rets[0]; + } + return cv::Vec2f(); } - bool find_correspondences(const std::vector& points, float f); + bool find_correspondences(const std::vector& points); cv::Vec2f p[PointModel::N_POINTS]; // the points in model order cv::Vec2f p_exp[PointModel::N_POINTS]; // the expected point positions @@ -116,7 +136,7 @@ protected: void reset_velocities(); - int POSIT(float f); // The POSIT algorithm, returns the number of iterations + void POSIT(float fov, int w, int h, const cv::Vec3f &headpos); // The POSIT algorithm, returns the number of iterations bool init_phase; float dt_valid; // time since last valid tracking result @@ -124,6 +144,7 @@ protected: cv::Vec3f v_r; FrameTrafo X_CM; // trafo from model to camera FrameTrafo X_CM_old; + cv::Mat rvec, tvec; }; #endif //POINTTRACKER_H -- cgit v1.2.3 From 689c297be28e2f5050e234bdc69594c53166f194 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 12 Jan 2014 19:54:04 +0100 Subject: Revert "use levmarq instead of coplanar POSIT implemented in numerically unstable fashion" This reverts commit 0bc59a0a7a42bcf65ebf3814e5f25fb17d735faa. --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 13 +- FTNoIR_Tracker_PT/camera.cpp | 8 +- FTNoIR_Tracker_PT/camera.h | 6 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 4 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp | 2 +- FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h | 4 +- FTNoIR_Tracker_PT/point_tracker.cpp | 191 +++++++++++++++++++------ FTNoIR_Tracker_PT/point_tracker.h | 33 +---- 8 files changed, 169 insertions(+), 92 deletions(-) (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index 461253cf..bdbed955 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -515,26 +515,23 @@ - FOV + F/W - fov_dspin + f_dspin - + The camera's focal length devided by its sensor width 2 - - 1.000000000000000 - - 1.000000000000000 + 0.100000000000000 @@ -1736,7 +1733,7 @@ res_x_spin res_y_spin fps_spin - fov_dspin + f_dspin camroll_combo campitch_spin camyaw_spin diff --git a/FTNoIR_Tracker_PT/camera.cpp b/FTNoIR_Tracker_PT/camera.cpp index 8986be60..754533c5 100644 --- a/FTNoIR_Tracker_PT/camera.cpp +++ b/FTNoIR_Tracker_PT/camera.cpp @@ -108,11 +108,11 @@ void Camera::set_device_index(int index) } } -void Camera::set_fov(float f) +void Camera::set_f(float f) { - if (cam_desired.fov != f) + if (cam_desired.f != f) { - cam_desired.fov = f; + cam_desired.f = f; _set_f(); } } @@ -208,7 +208,7 @@ void CVCamera::_set_index() void CVCamera::_set_f() { - cam_info.fov = cam_desired.fov; + cam_info.f = cam_desired.f; } void CVCamera::_set_fps() diff --git a/FTNoIR_Tracker_PT/camera.h b/FTNoIR_Tracker_PT/camera.h index 6768e419..ea68c387 100644 --- a/FTNoIR_Tracker_PT/camera.h +++ b/FTNoIR_Tracker_PT/camera.h @@ -25,12 +25,12 @@ void get_camera_device_names(std::vector& device_names); // ---------------------------------------------------------------------------- struct CamInfo { - CamInfo() : res_x(0), res_y(0), fps(0), fov(56) {} + CamInfo() : res_x(0), res_y(0), fps(0), f(1) {} int res_x; int res_y; int fps; - float fov; + float f; // (focal length) / (sensor width) }; // ---------------------------------------------------------------------------- @@ -48,7 +48,7 @@ public: // calls corresponding template methods and reinitializes frame rate calculation void set_device_index(int index); - void set_fov(float f); + void set_f(float f); void set_fps(int fps); void set_res(int x_res, int y_res); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp index 740cf3da..53d9c9e4 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp @@ -83,7 +83,7 @@ void Tracker::run() { frame = frame_rotation.rotate_frame(frame); const std::vector& points = point_extractor.extract_points(frame, dt, false); - tracking_valid = point_tracker.track(points, camera.get_info().fov, dt, frame.cols, frame.rows, t_MH); + tracking_valid = point_tracker.track(points, camera.get_info().f, dt); video_widget->update_image(frame); } #ifdef PT_PERF_LOG @@ -103,7 +103,7 @@ void Tracker::apply(settings& s) camera.set_device_index(s.cam_index); camera.set_res(s.cam_res_x, s.cam_res_y); camera.set_fps(s.cam_fps); - camera.set_fov(s.cam_fov); + camera.set_f(s.cam_f); frame_rotation.rotation = static_cast(static_cast(s.cam_roll)); point_extractor.threshold_val = s.threshold; point_extractor.threshold_secondary_val = s.threshold_secondary; diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp index 4ae20f48..c103b78c 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp @@ -46,7 +46,7 @@ TrackerDialog::TrackerDialog() tie_setting(s.reset_time, ui.reset_spin); tie_setting(s.cam_index, ui.camdevice_combo); - tie_setting(s.cam_fov, ui.fov_dspin); + tie_setting(s.cam_f, ui.f_dspin); tie_setting(s.cam_res_x, ui.res_x_spin); tie_setting(s.cam_res_y, ui.res_y_spin); tie_setting(s.cam_fps, ui.fps_spin); diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h index b2ab8854..109090b3 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt_settings.h @@ -28,7 +28,7 @@ struct settings threshold_secondary, min_point_size, max_point_size; - value cam_fov; + value cam_f; value m01_x, m01_y, m01_z; value m02_x, m02_y, m02_z; @@ -57,7 +57,7 @@ struct settings threshold_secondary(b, "threshold-secondary", 128), min_point_size(b, "min-point-size", 10), max_point_size(b, "max-point-size", 50), - cam_fov(b, "camera-fov", 56), + cam_f(b, "camera-focal-length", 1), m01_x(b, "m_01-x", 0), m01_y(b, "m_01-y", 0), m01_z(b, "m_01-z", 0), diff --git a/FTNoIR_Tracker_PT/point_tracker.cpp b/FTNoIR_Tracker_PT/point_tracker.cpp index 1df70b17..dfefdaf8 100644 --- a/FTNoIR_Tracker_PT/point_tracker.cpp +++ b/FTNoIR_Tracker_PT/point_tracker.cpp @@ -17,6 +17,23 @@ using namespace cv; using namespace boost; using namespace std; +const float PI = 3.14159265358979323846f; + +// ---------------------------------------------------------------------------- +static void get_row(const Matx33f& m, int i, Vec3f& v) +{ + v[0] = m(i,0); + v[1] = m(i,1); + v[2] = m(i,2); +} + +static void set_row(Matx33f& m, int i, const Vec3f& v) +{ + m(i,0) = v[0]; + m(i,1) = v[1]; + m(i,2) = v[2]; +} + // ---------------------------------------------------------------------------- PointModel::PointModel(Vec3f M01, Vec3f M02) : M01(M01), @@ -91,11 +108,9 @@ PointTracker::PointTracker() dt_reset(1), v_t(0,0,0), v_r(0,0,0), - dynamic_pose_resolution(true), - fov(0), - _w(0), - _h(0) + dynamic_pose_resolution(true) { + X_CM.t[2] = 1000; // default position: 1 m away from cam; } void PointTracker::reset() @@ -113,7 +128,7 @@ void PointTracker::reset_velocities() } -bool PointTracker::track(const vector& points, float fov, float dt, int w, int h, const cv::Vec3f& headpos) +bool PointTracker::track(const vector& points, float f, float dt) { if (!dynamic_pose_resolution) init_phase = true; @@ -125,7 +140,12 @@ bool PointTracker::track(const vector& points, float fov, float dt, int w reset(); } - bool no_model = !point_model; + bool no_model = +#ifdef OPENTRACK_API + point_model.get() == NULL; +#else + !point_model; +#endif // if there is a pointtracking problem, reset the velocities if (no_model || points.size() != PointModel::N_POINTS) @@ -141,7 +161,7 @@ bool PointTracker::track(const vector& points, float fov, float dt, int w predict(dt_valid); // if there is a point correspondence problem something has gone wrong, do a reset - if (!find_correspondences(points)) + if (!find_correspondences(points, f)) { //qDebug()<<"Error in finding point correspondences!"; X_CM = X_CM_old; // undo prediction @@ -149,8 +169,7 @@ bool PointTracker::track(const vector& points, float fov, float dt, int w return false; } - // XXX TODO fov - POSIT(fov, w, h, headpos); + int n_iter = POSIT(f); //qDebug()<<"Number of POSIT iterations: "<& points) +bool PointTracker::find_correspondences(const vector& points, float f) { if (init_phase) { // We do a simple freetrack-like sorting in the init phase... @@ -196,9 +215,9 @@ bool PointTracker::find_correspondences(const vector& points) else { // ... otherwise we look at the distance to the projection of the expected model points // project model points under current pose - p_exp[0] = project(Vec3f(0,0,0)); - p_exp[1] = project(point_model->M01); - p_exp[2] = project(point_model->M02); + p_exp[0] = project(Vec3f(0,0,0), f); + p_exp[1] = project(point_model->M01, f); + p_exp[2] = project(point_model->M02, f); // set correspondences by minimum distance to projected model point bool point_taken[PointModel::N_POINTS]; @@ -232,48 +251,130 @@ bool PointTracker::find_correspondences(const vector& points) -void PointTracker::POSIT(float fov, int w, int h, const cv::Vec3f& headpos) +int PointTracker::POSIT(float f) { - // XXX hack - this->fov = fov; - _w = w; - _h = h; - std::vector obj_points; - std::vector img_points; + // POSIT algorithm for coplanar points as presented in + // [Denis Oberkampf, Daniel F. DeMenthon, Larry S. Davis: "Iterative Pose Estimation Using Coplanar Feature Points"] + // we use the same notation as in the paper here + + // The expected rotation used for resolving the ambiguity in POSIT: + // In every iteration step the rotation closer to R_expected is taken + Matx33f R_expected; + if (init_phase) + R_expected = Matx33f::eye(); // in the init phase, we want to be close to the default pose = no rotation + else + R_expected = X_CM.R; // later we want to be close to the last (predicted) rotation + + // initial pose = last (predicted) pose + Vec3f k; + get_row(R_expected, 2, k); + float Z0 = init_phase ? 1000 : X_CM.t[2]; + + float old_epsilon_1 = 0; + float old_epsilon_2 = 0; + float epsilon_1 = 1; + float epsilon_2 = 1; + + Vec3f I0, J0; + Vec2f I0_coeff, J0_coeff; + + Vec3f I_1, J_1, I_2, J_2; + Matx33f R_1, R_2; + Matx33f* R_current; + + const int MAX_ITER = 100; + const float EPS_THRESHOLD = 1e-4; + + int i=1; + for (; iM01)/Z0; + epsilon_2 = k.dot(point_model->M02)/Z0; + + // vector of scalar products and + Vec2f I0_M0i(p[1][0]*(1.0 + epsilon_1) - p[0][0], + p[2][0]*(1.0 + epsilon_2) - p[0][0]); + Vec2f J0_M0i(p[1][1]*(1.0 + epsilon_1) - p[0][1], + p[2][1]*(1.0 + epsilon_2) - p[0][1]); + + // construct projection of I, J onto M0i plane: I0 and J0 + I0_coeff = point_model->P * I0_M0i; + J0_coeff = point_model->P * J0_M0i; + I0 = I0_coeff[0]*point_model->M01 + I0_coeff[1]*point_model->M02; + J0 = J0_coeff[0]*point_model->M01 + J0_coeff[1]*point_model->M02; + + // calculate u component of I, J + float II0 = I0.dot(I0); + float IJ0 = I0.dot(J0); + float JJ0 = J0.dot(J0); + float rho, theta; + if (JJ0 == II0) { + rho = sqrt(abs(2*IJ0)); + theta = -PI/4; + if (IJ0<0) theta *= -1; + } + else { + rho = sqrt(sqrt( (JJ0-II0)*(JJ0-II0) + 4*IJ0*IJ0 )); + theta = atan( -2*IJ0 / (JJ0-II0) ); + if (JJ0 - II0 < 0) theta += PI; + theta /= 2; + } - obj_points.push_back(headpos); - obj_points.push_back(point_model->M01 + headpos); - obj_points.push_back(point_model->M02 + headpos); + // construct the two solutions + I_1 = I0 + rho*cos(theta)*point_model->u; + I_2 = I0 - rho*cos(theta)*point_model->u; - img_points.push_back(p[0]); - img_points.push_back(p[1]); - img_points.push_back(p[2]); + J_1 = J0 + rho*sin(theta)*point_model->u; + J_2 = J0 - rho*sin(theta)*point_model->u; - const float HT_PI = 3.1415926535; + float norm_const = 1.0/norm(I_1); // all have the same norm + + // create rotation matrices + I_1 *= norm_const; J_1 *= norm_const; + I_2 *= norm_const; J_2 *= norm_const; - const float focal_length_w = 0.5 * w / tan(fov * HT_PI / 180); - const float focal_length_h = 0.5 * h / tan(fov * h / w * HT_PI / 180.0); + set_row(R_1, 0, I_1); + set_row(R_1, 1, J_1); + set_row(R_1, 2, I_1.cross(J_1)); + + set_row(R_2, 0, I_2); + set_row(R_2, 1, J_2); + set_row(R_2, 2, I_2.cross(J_2)); - cv::Mat intrinsics = cv::Mat::eye(3, 3, CV_32FC1); - intrinsics.at (0, 0) = focal_length_w; - intrinsics.at (1, 1) = focal_length_h; - intrinsics.at (0, 2) = w/2; - intrinsics.at (1, 2) = h/2; + // the single translation solution + Z0 = norm_const * f; - cv::Mat dist_coeffs = cv::Mat::zeros(5, 1, CV_32FC1); + // pick the rotation solution closer to the expected one + // in simple metric d(A,B) = || I - A * B^T || + float R_1_deviation = norm(Matx33f::eye() - R_expected * R_1.t()); + float R_2_deviation = norm(Matx33f::eye() - R_expected * R_2.t()); - bool lastp = !rvec.empty() && !tvec.empty() && !init_phase; + if (R_1_deviation < R_2_deviation) + R_current = &R_1; + else + R_current = &R_2; - cv::solvePnP(obj_points, img_points, intrinsics, dist_coeffs, rvec, tvec, lastp, cv::ITERATIVE); + get_row(*R_current, 2, k); - cv::Mat rmat; - cv::Rodrigues(rvec, rmat); + // check for convergence condition + if (abs(epsilon_1 - old_epsilon_1) + abs(epsilon_2 - old_epsilon_2) < EPS_THRESHOLD) + break; + old_epsilon_1 = epsilon_1; + old_epsilon_2 = epsilon_2; + } // apply results - for (int i = 0; i < 3; i++) - { - X_CM.t[i] = tvec.at(i); - for (int j = 0; j < 3; j++) - X_CM.R(i, j) = rmat.at(i, j); - } + X_CM.R = *R_current; + X_CM.t[0] = p[0][0] * Z0/f; + X_CM.t[1] = p[0][1] * Z0/f; + X_CM.t[2] = Z0; + + return i; + + //Rodrigues(X_CM.R, r); + //qDebug()<<"iter: "<& points, float fov, float dt, int w, int h, const cv::Vec3f &headpos); + bool track(const std::vector& points, float f, float dt); boost::shared_ptr point_model; bool dynamic_pose_resolution; @@ -98,35 +98,15 @@ public: FrameTrafo get_pose() const { return X_CM; } void reset(); - float fov; - int _w, _h; protected: - cv::Vec2f project(const cv::Vec3f& v_M) + inline cv::Vec2f project(const cv::Vec3f& v_M, float f) { - if (!rvec.empty() && !tvec.empty() && fov > 0) - { - const float HT_PI = 3.1415926535; - const int w = _w, h = _h; - const float focal_length_w = 0.5 * w / tan(fov * HT_PI / 180); - const float focal_length_h = 0.5 * h / tan(fov * h / w * HT_PI / 180.0); - - cv::Mat intrinsics = cv::Mat::eye(3, 3, CV_32FC1); - intrinsics.at (0, 0) = focal_length_w; - intrinsics.at (1, 1) = focal_length_h; - intrinsics.at (0, 2) = w/2; - intrinsics.at (1, 2) = h/2; - std::vector xs; - xs.push_back(v_M); - cv::Mat dist_coeffs = cv::Mat::zeros(5, 1, CV_32FC1); - std::vector rets(1); - cv::projectPoints(xs, rvec, tvec, intrinsics, dist_coeffs, rets); - return rets[0]; - } - return cv::Vec2f(); + cv::Vec3f v_C = X_CM * v_M; + return cv::Vec2f(f*v_C[0]/v_C[2], f*v_C[1]/v_C[2]); } - bool find_correspondences(const std::vector& points); + bool find_correspondences(const std::vector& points, float f); cv::Vec2f p[PointModel::N_POINTS]; // the points in model order cv::Vec2f p_exp[PointModel::N_POINTS]; // the expected point positions @@ -136,7 +116,7 @@ protected: void reset_velocities(); - void POSIT(float fov, int w, int h, const cv::Vec3f &headpos); // The POSIT algorithm, returns the number of iterations + int POSIT(float f); // The POSIT algorithm, returns the number of iterations bool init_phase; float dt_valid; // time since last valid tracking result @@ -144,7 +124,6 @@ protected: cv::Vec3f v_r; FrameTrafo X_CM; // trafo from model to camera FrameTrafo X_CM_old; - cv::Mat rvec, tvec; }; #endif //POINTTRACKER_H -- cgit v1.2.3 From 65facfc7c819a5fc14385aedbb2848eb68bac390 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 15 Jan 2014 19:17:51 +0100 Subject: make all tracker/protocol/filter dialogs non-modal --- FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 2 +- ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui | 2 +- ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui | 2 +- ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui | 2 +- ftnoir_protocol_fg/ftnoir_fgcontrols.ui | 2 +- ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui | 2 +- ftnoir_protocol_ft/ftnoir_ftcontrols.ui | 2 +- ftnoir_protocol_ftn/ftnoir_ftncontrols.ui | 2 +- ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui | 2 +- ftnoir_protocol_mouse/ftnoir_mousecontrols.ui | 2 +- ftnoir_protocol_sc/ftnoir_sccontrols.ui | 2 +- ftnoir_protocol_vjoy/ftnoir_vjoy_controls.ui | 2 +- ftnoir_protocol_wine/ftnoir_winecontrols.ui | 2 +- ftnoir_tracker_aruco/aruco-trackercontrols.ui | 2 +- ftnoir_tracker_ht/ht-trackercontrols.ui | 2 +- ftnoir_tracker_hydra/ftnoir_hydra_clientcontrols.ui | 2 +- ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui | 2 +- ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui | 2 +- ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) (limited to 'FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui') diff --git a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui index bdbed955..0bbec7e1 100644 --- a/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui +++ b/FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui @@ -3,7 +3,7 @@ UICPTClientControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui b/ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui index debd1250..c544263d 100644 --- a/ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui +++ b/ftnoir_filter_accela/ftnoir_accela_filtercontrols.ui @@ -3,7 +3,7 @@ AccelaUICFilterControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui b/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui index a1083265..8ee633cc 100644 --- a/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui +++ b/ftnoir_filter_ewma2/ftnoir_ewma_filtercontrols.ui @@ -3,7 +3,7 @@ UICFilterControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui b/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui index a9fdec6e..e0c849c9 100644 --- a/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui +++ b/ftnoir_filter_kalman/ftnoir_kalman_filtercontrols.ui @@ -3,7 +3,7 @@ KalmanUICFilterControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_protocol_fg/ftnoir_fgcontrols.ui b/ftnoir_protocol_fg/ftnoir_fgcontrols.ui index e351647b..a4092c05 100644 --- a/ftnoir_protocol_fg/ftnoir_fgcontrols.ui +++ b/ftnoir_protocol_fg/ftnoir_fgcontrols.ui @@ -3,7 +3,7 @@ UICFGControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui b/ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui index 1ce77862..6cb066bd 100644 --- a/ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui +++ b/ftnoir_protocol_fsuipc/ftnoir_fsuipccontrols.ui @@ -3,7 +3,7 @@ UICFSUIPCControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_protocol_ft/ftnoir_ftcontrols.ui b/ftnoir_protocol_ft/ftnoir_ftcontrols.ui index bd5980b4..941aaff0 100644 --- a/ftnoir_protocol_ft/ftnoir_ftcontrols.ui +++ b/ftnoir_protocol_ft/ftnoir_ftcontrols.ui @@ -3,7 +3,7 @@ UICFTControls - Qt::ApplicationModal + Qt::NonModal true diff --git a/ftnoir_protocol_ftn/ftnoir_ftncontrols.ui b/ftnoir_protocol_ftn/ftnoir_ftncontrols.ui index 429e7046..48679f3c 100644 --- a/ftnoir_protocol_ftn/ftnoir_ftncontrols.ui +++ b/ftnoir_protocol_ftn/ftnoir_ftncontrols.ui @@ -3,7 +3,7 @@ UICFTNControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui b/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui index e85e001e..d2b86445 100644 --- a/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui +++ b/ftnoir_protocol_libevdev/ftnoir_libevdev_controls.ui @@ -3,7 +3,7 @@ UICLibevdevControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui b/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui index 540e4f0d..2705fff7 100644 --- a/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui +++ b/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui @@ -3,7 +3,7 @@ UICMOUSEControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_protocol_sc/ftnoir_sccontrols.ui b/ftnoir_protocol_sc/ftnoir_sccontrols.ui index 430b3912..87dc8d86 100644 --- a/ftnoir_protocol_sc/ftnoir_sccontrols.ui +++ b/ftnoir_protocol_sc/ftnoir_sccontrols.ui @@ -3,7 +3,7 @@ UICSCControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_protocol_vjoy/ftnoir_vjoy_controls.ui b/ftnoir_protocol_vjoy/ftnoir_vjoy_controls.ui index 94b229fb..2214b887 100644 --- a/ftnoir_protocol_vjoy/ftnoir_vjoy_controls.ui +++ b/ftnoir_protocol_vjoy/ftnoir_vjoy_controls.ui @@ -3,7 +3,7 @@ UICVJoyControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_protocol_wine/ftnoir_winecontrols.ui b/ftnoir_protocol_wine/ftnoir_winecontrols.ui index 749feb0f..9356c448 100644 --- a/ftnoir_protocol_wine/ftnoir_winecontrols.ui +++ b/ftnoir_protocol_wine/ftnoir_winecontrols.ui @@ -3,7 +3,7 @@ UICFTControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_tracker_aruco/aruco-trackercontrols.ui b/ftnoir_tracker_aruco/aruco-trackercontrols.ui index e0794eb9..1d5a4241 100644 --- a/ftnoir_tracker_aruco/aruco-trackercontrols.ui +++ b/ftnoir_tracker_aruco/aruco-trackercontrols.ui @@ -3,7 +3,7 @@ Form - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_tracker_ht/ht-trackercontrols.ui b/ftnoir_tracker_ht/ht-trackercontrols.ui index 55501ef1..f57022c8 100644 --- a/ftnoir_tracker_ht/ht-trackercontrols.ui +++ b/ftnoir_tracker_ht/ht-trackercontrols.ui @@ -3,7 +3,7 @@ Form - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_tracker_hydra/ftnoir_hydra_clientcontrols.ui b/ftnoir_tracker_hydra/ftnoir_hydra_clientcontrols.ui index 1acbf93f..e5e41bec 100644 --- a/ftnoir_tracker_hydra/ftnoir_hydra_clientcontrols.ui +++ b/ftnoir_tracker_hydra/ftnoir_hydra_clientcontrols.ui @@ -3,7 +3,7 @@ UIHydraControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui index 7522cf31..5d349169 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui @@ -3,7 +3,7 @@ UIJoystickControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui b/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui index e868a9c3..a9168239 100644 --- a/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui +++ b/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui @@ -3,7 +3,7 @@ UIRiftControls - Qt::ApplicationModal + Qt::NonModal diff --git a/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui b/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui index fc614477..5c602792 100644 --- a/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui +++ b/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui @@ -3,7 +3,7 @@ UICFTNClientControls - Qt::ApplicationModal + Qt::NonModal -- cgit v1.2.3