From deb7a542d465e69462e0ca500d21db9d97e14aea Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 16 Jun 2015 10:06:01 +0200 Subject: options: add support for QRadioButton --- opentrack/options.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/opentrack/options.hpp b/opentrack/options.hpp index c33c2f53..5511f567 100644 --- a/opentrack/options.hpp +++ b/opentrack/options.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -450,4 +451,12 @@ namespace options { base_value::connect(t, SIGNAL(currentChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE); base_value::connect(&v, SIGNAL(valueChanged(int)), t, SLOT(setCurrentIndex(int)), v.SAFE_CONNTYPE); } + + template<> + inline void tie_setting(value& v, QRadioButton* t) + { + t->setChecked(v); + base_value::connect(t, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool)), v.DIRECT_CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(bool)), t, SLOT(setChecked(bool)), v.SAFE_CONNTYPE); + } } -- cgit v1.2.3 From 8c7f5b4a4cc84acb843957f0dea6a52faffd87a5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 16 Jun 2015 10:18:03 +0200 Subject: pt: include opencv headers only when necessary Settings header can't have it since it's included in ui in trackhat branch --- ftnoir_tracker_pt/ftnoir_tracker_pt.h | 1 - ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.h b/ftnoir_tracker_pt/ftnoir_tracker_pt.h index 771631cd..3b9f1648 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #ifndef OPENTRACK_API # include diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h index 30647412..14786013 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h @@ -8,8 +8,6 @@ #ifndef FTNOIR_TRACKER_PT_SETTINGS_H #define FTNOIR_TRACKER_PT_SETTINGS_H -#include - #include "opentrack/options.hpp" using namespace options; -- cgit v1.2.3 From dc4860023d78e52feb44d16fb8782cb4f0cbcc19 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 16 Jun 2015 12:04:07 +0200 Subject: pt: try simple method of point extraction To be reverted if broken --- ftnoir_tracker_pt/point_extractor.cpp | 107 ++++++++-------------------------- 1 file changed, 25 insertions(+), 82 deletions(-) diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index 2c39c2e2..5f7f6829 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -30,9 +30,6 @@ std::vector PointExtractor::extract_points(Mat& frame) frame_last = cv::Mat(); } - // clear old points - points.clear(); - // convert to grayscale Mat frame_gray; cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); @@ -78,88 +75,34 @@ std::vector PointExtractor::extract_points(Mat& frame) 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; - - int blob_index = 1; - for (int y=0; y= 255) break; - for (int x=0; x= 255) break; - - // 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++; - - // calculate the size of the connected component - unsigned int region_size = 0; - for (int i=rect.y; i < (rect.y+rect.height); i++) - { - for (int j=rect.x; j < (rect.x+rect.width); j++) - { - if (frame_bin.at(i,j) != blob_index-1) continue; - region_size++; - } - } - - if (region_size < region_size_min || region_size > region_size_max) continue; - - // calculate the center of mass: - // mx = (sum_ij j*f(frame_grey_ij)) / (sum_ij f(frame_grey_ij)) - // my = ... - // f maps from [threshold,256] -> [0, 1], lower values are mapped to 0 - float m = 0; - float mx = 0; - float my = 0; - for (int i=rect.y; i < (rect.y+rect.height); i++) - { - for (int j=rect.x; j < (rect.x+rect.width); j++) - { - if (frame_bin.at(i,j) != blob_index-1) continue; - float val; - - if(secondary==0){ - val = frame_gray.at(i,j); - val = float(val - primary)/(256 - primary); - 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; - } - } - - // convert to centered camera coordinate system with y axis upwards - Vec2f c; - c[0] = (mx/m - W/2)/W; - c[1] = -(my/m - H/2)/W; - //qDebug()< "<> contours; + cv::findContours(frame_bin, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); + + // clear old points + points.clear(); + + for (auto& c : contours) + { + auto m = cv::moments(cv::Mat(c)); + const double area = m.m00; + if (area == 0.) + continue; + cv::Vec2f pos(m.m10 / m.m00, m.m01 / m.m00); + if (area < region_size_min || area > region_size_max) + continue; + pos[0] = (pos[0] - W/2)/W; + pos[1] = -(pos[1] - H/2)/W; + + points.push_back(pos); + } // draw output image vector channels; - 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_bin_copy); - channels.push_back(frame_gray - frame_bin_copy); - //channels.push_back(frame_gray + frame_bin); - } + 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); merge(channels, frame); return points; -- cgit v1.2.3 From 16a111959fb89594d5cb15bd223372d9d2b3d12b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 16 Jun 2015 12:04:24 +0200 Subject: simple-mat: allow pitch axis go -180->180 To be reverted if broken --- opentrack/simple-mat.hpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp index 5ee9029c..1cea967e 100644 --- a/opentrack/simple-mat.hpp +++ b/opentrack/simple-mat.hpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace { // last param to fool SFINAE into overloading @@ -215,22 +216,20 @@ struct Mat static dmat<3, 1> rmat_to_euler(const dmat<3, 3>& R) { static constexpr double pi = 3.141592653; - const double up = 90 * pi / 180.; - static constexpr double bound = 1. - 2e-4; - if (R(0, 2) > bound) + const double pitch_1 = asin(-R(0, 2)); + const double pitch_2 = pi - pitch_1; + const double cos_p1 = cos(pitch_1), cos_p2 = cos(pitch_2); + const double roll_1 = atan2(R(1, 2) / cos_p1, R(2, 2) / cos_p1); + const double roll_2 = atan2(R(1, 2) / cos_p2, R(2, 2) / cos_p2); + const double yaw_1 = atan2(R(0, 1) / cos_p1, R(0, 0) / cos_p1); + const double yaw_2 = atan2(R(0, 1) / cos_p2, R(0, 0) / cos_p2); + if (std::abs(pitch_1) + std::abs(roll_1) + std::abs(yaw_1) > std::abs(pitch_2) + std::abs(roll_2) + std::abs(yaw_2)) { - double roll = atan(R(1, 0) / R(2, 0)); - return dmat<3, 1>({0., up, roll}); + bool fix_neg_pitch = pitch_1 < 0; + return dmat<3, 1>({yaw_2, std::fmod(fix_neg_pitch ? -pi - pitch_1 : pitch_2, pi), roll_2}); } - if (R(0, 2) < -bound) - { - double roll = atan(R(1, 0) / R(2, 0)); - return dmat<3, 1>({0., -up, roll}); - } - double pitch = asin(-R(0, 2)); - double roll = atan2(R(1, 2), R(2, 2)); - double yaw = atan2(R(0, 1), R(0, 0)); - return dmat<3, 1>({yaw, pitch, roll}); + else + return dmat<3, 1>({yaw_1, pitch_1, roll_1}); } // tait-bryan angles, not euler -- cgit v1.2.3 From 3fafaac47277ff5932aad10e02bd1cd5470f41a5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 18 Jun 2015 08:46:18 +0200 Subject: forgot #pragma once, add headers --- opentrack/state.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/opentrack/state.hpp b/opentrack/state.hpp index a9f66241..bfbf113e 100644 --- a/opentrack/state.hpp +++ b/opentrack/state.hpp @@ -1,11 +1,13 @@ +#pragma once + #include #include "opentrack/options.hpp" using namespace options; #include "opentrack/plugin-support.hpp" #include "opentrack/main-settings.hpp" #include "opentrack/mappings.hpp" - -struct Work; +#include "opentrack/selected-libraries.hpp" +#include "opentrack/work.hpp" struct State { State() : -- cgit v1.2.3 From a001c2b6de41f4593ae94005ed5449ef5589ab4d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 18 Jun 2015 08:46:26 +0200 Subject: cmake: add toolchain debug version --- cmake/mingw-w64-debug.cmake | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cmake/mingw-w64-debug.cmake diff --git a/cmake/mingw-w64-debug.cmake b/cmake/mingw-w64-debug.cmake new file mode 100644 index 00000000..7a371e5d --- /dev/null +++ b/cmake/mingw-w64-debug.cmake @@ -0,0 +1,38 @@ +# this file only serves as toolchain file when specified so explicitly +# when building the software. from repository's root directory: +# mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=$(pwd)/../cmake/mingw-w64.cmake +# -sh 20140922 + +SET(CMAKE_SYSTEM_NAME Windows) +SET(CMAKE_SYSTEM_VERSION 1) + +# specify the cross compiler +set(c i686-w64-mingw32-) + +SET(CMAKE_C_COMPILER ${c}gcc) +SET(CMAKE_CXX_COMPILER ${c}g++) +set(CMAKE_RC_COMPILER ${c}windres) +set(CMAKE_LINKER ${c}ld) +set(CMAKE_AR ${c}gcc-ar CACHE STRING "" FORCE) +set(CMAKE_NM ${c}gcc-nm CACHE STRING "" FORCE) +set(CMAKE_RANLIB ${c}gcc-ranlib CACHE STRING "" FORCE) + +SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) + +# search for programs in the host directories +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# don't poison with system compile-time data +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(cpu "-O2 -march=i686 -mtune=corei7-avx -ffast-math -mfpmath=both -msse -msse2 -mno-sse3 -mno-avx") +set(rice "-ggdb") + +set(CFLAGS-OVERRIDE "" CACHE STRING "") + +set(CMAKE_C_FLAGS_RELEASE "${rice} ${cpu} ${CFLAGS-OVERRIDE}" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE) +set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${cpu} ${CFLAGS-OVERRIDE}" CACHE STRING "" FORCE) +set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} CACHE STRING "" FORCE) +set(CMAKE_MODULE_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} CACHE STRING "" FORCE) +set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "" FORCE) -- cgit v1.2.3