From a24e7bdd9745918f7d5fdc852ce65233b41363f9 Mon Sep 17 00:00:00 2001 From: Stéphane Lenclud Date: Sun, 21 Apr 2019 13:15:57 +0200 Subject: Easy Tracker: PNP solver now a settings option. --- tracker-easy/lang/nl_NL.ts | 56 ++++++++++++++++++++--------------- tracker-easy/lang/ru_RU.ts | 56 ++++++++++++++++++++--------------- tracker-easy/lang/stub.ts | 56 ++++++++++++++++++++--------------- tracker-easy/lang/zh_CN.ts | 36 +++++++++++++--------- tracker-easy/settings.h | 13 ++------ tracker-easy/tracker-easy-dialog.cpp | 14 +++------ tracker-easy/tracker-easy-settings.ui | 27 ++++++++++++----- tracker-easy/tracker-easy.cpp | 39 ++++++++++++++++-------- tracker-easy/tracker-easy.h | 4 +++ 9 files changed, 174 insertions(+), 127 deletions(-) diff --git a/tracker-easy/lang/nl_NL.ts b/tracker-easy/lang/nl_NL.ts index f83e859a..21ea306e 100644 --- a/tracker-easy/lang/nl_NL.ts +++ b/tracker-easy/lang/nl_NL.ts @@ -137,26 +137,6 @@ Enable, slider sets point size - - Color channels used - - - - Average - - - - Natural - - - - Red only - - - - Blue only - - Maximum point diameter @@ -254,10 +234,6 @@ Don't roll or change position. Camera Info: - - Green only - - Debug (full size preview) @@ -274,5 +250,37 @@ Don't roll or change position. Size in pixels of half the edge defining deadzone squares around tracked points + + Perspective-N-Point solver + + + + Make sure you pick a solver supporting the number of marker you are using. For three points detection use either P3P or AP3P. + + + + P3P + + + + ITERATIVE + + + + EPNP + + + + DLS + + + + UPNP + + + + AP3P + + diff --git a/tracker-easy/lang/ru_RU.ts b/tracker-easy/lang/ru_RU.ts index 0dbc8323..bc725e23 100644 --- a/tracker-easy/lang/ru_RU.ts +++ b/tracker-easy/lang/ru_RU.ts @@ -137,26 +137,6 @@ Enable, slider sets point size Полузнок устанавливает размер точек - - Color channels used - - - - Average - - - - Natural - - - - Red only - - - - Blue only - - Maximum point diameter @@ -259,10 +239,6 @@ ROLL или X/Y-смещения. Camera Info: Параметры камеры: - - Green only - - Debug (full size preview) @@ -279,5 +255,37 @@ ROLL или X/Y-смещения. Size in pixels of half the edge defining deadzone squares around tracked points + + Perspective-N-Point solver + + + + Make sure you pick a solver supporting the number of marker you are using. For three points detection use either P3P or AP3P. + + + + P3P + + + + ITERATIVE + + + + EPNP + + + + DLS + + + + UPNP + + + + AP3P + + diff --git a/tracker-easy/lang/stub.ts b/tracker-easy/lang/stub.ts index 32b314e9..75e29070 100644 --- a/tracker-easy/lang/stub.ts +++ b/tracker-easy/lang/stub.ts @@ -137,26 +137,6 @@ Enable, slider sets point size - - Color channels used - - - - Average - - - - Natural - - - - Red only - - - - Blue only - - Maximum point diameter @@ -254,10 +234,6 @@ Don't roll or change position. Camera Info: - - Green only - - Debug (full size preview) @@ -274,5 +250,37 @@ Don't roll or change position. Size in pixels of half the edge defining deadzone squares around tracked points + + Perspective-N-Point solver + + + + Make sure you pick a solver supporting the number of marker you are using. For three points detection use either P3P or AP3P. + + + + P3P + + + + ITERATIVE + + + + EPNP + + + + DLS + + + + UPNP + + + + AP3P + + diff --git a/tracker-easy/lang/zh_CN.ts b/tracker-easy/lang/zh_CN.ts index f90e261f..68172059 100644 --- a/tracker-easy/lang/zh_CN.ts +++ b/tracker-easy/lang/zh_CN.ts @@ -226,52 +226,60 @@ 设备信息: - Color channels used + Value - Average + Use only yaw and pitch while calibrating. +Don't roll or change position. + 用pitch和yaw校准。不要roll或者变换位置 + + + Debug (full size preview) - Natural + Deadzone - Red only + <html><head/><body><p><span style=" font-weight:600;">Easy Tracker<br/>Version 0.1</span></p><p><span style=" font-weight:600;">by Stéphane Lenclud</span></p><p>See <a href="https://github.com/opentrack/opentrack/wiki/Easy-Tracker"><span style=" font-weight:600; text-decoration: underline; color:#9999AA;">documentation on GitHub</span></a></p></body></html> - Blue only + Size in pixels of half the edge defining deadzone squares around tracked points - Value + Perspective-N-Point solver - Use only yaw and pitch while calibrating. -Don't roll or change position. - 用pitch和yaw校准。不要roll或者变换位置 + Make sure you pick a solver supporting the number of marker you are using. For three points detection use either P3P or AP3P. + - Green only + P3P - Debug (full size preview) + ITERATIVE - Deadzone + EPNP - <html><head/><body><p><span style=" font-weight:600;">Easy Tracker<br/>Version 0.1</span></p><p><span style=" font-weight:600;">by Stéphane Lenclud</span></p><p>See <a href="https://github.com/opentrack/opentrack/wiki/Easy-Tracker"><span style=" font-weight:600; text-decoration: underline; color:#9999AA;">documentation on GitHub</span></a></p></body></html> + DLS - Size in pixels of half the edge defining deadzone squares around tracked points + UPNP + + + + AP3P diff --git a/tracker-easy/settings.h b/tracker-easy/settings.h index 53b80052..4d043e6a 100644 --- a/tracker-easy/settings.h +++ b/tracker-easy/settings.h @@ -1,19 +1,10 @@ #pragma once #include "options/options.hpp" +#include #include -enum pt_color_type -{ - // explicit values, gotta preserve the numbering in .ini - // don't reuse when removing some of the modes - pt_color_natural = 2, - pt_color_red_only = 3, - pt_color_average = 5, - pt_color_blue_only = 6, - pt_color_green_only = 7, -}; namespace EasyTracker { @@ -58,7 +49,7 @@ namespace EasyTracker { value debug{ b, "debug", false }; value auto_threshold{ b, "automatic-threshold", true }; - value blob_color{ b, "blob-color", pt_color_natural }; + value PnpSolver{ b, "pnp-solver", cv::SOLVEPNP_P3P }; value threshold_slider{ b, "threshold-slider", { 128, 0, 255 } }; diff --git a/tracker-easy/tracker-easy-dialog.cpp b/tracker-easy/tracker-easy-dialog.cpp index e3b72e38..36c5d99d 100644 --- a/tracker-easy/tracker-easy-dialog.cpp +++ b/tracker-easy/tracker-easy-dialog.cpp @@ -11,6 +11,7 @@ #include "video/camera.hpp" #include +#include #include #include @@ -95,18 +96,11 @@ namespace EasyTracker connect(this, &Dialog::poll_tracker_info, this, &Dialog::poll_tracker_info_impl, Qt::DirectConnection); - constexpr pt_color_type color_types[] = { - pt_color_average, - pt_color_natural, - pt_color_red_only, - pt_color_green_only, - pt_color_blue_only, - }; - for (unsigned k = 0; k < std::size(color_types); k++) - ui.blob_color->setItemData(k, int(color_types[k])); + for (unsigned k = 0; k < cv::SOLVEPNP_MAX_COUNT; k++) + ui.comboBoxSolvers->setItemData(k, k); - tie_setting(s.blob_color, ui.blob_color); + tie_setting(s.PnpSolver, ui.comboBoxSolvers); tie_setting(s.threshold_slider, ui.threshold_value_display, [this](const slider_value& val) { return threshold_display_text(int(val)); diff --git a/tracker-easy/tracker-easy-settings.ui b/tracker-easy/tracker-easy-settings.ui index ffe6ebce..9ff929dc 100644 --- a/tracker-easy/tracker-easy-settings.ui +++ b/tracker-easy/tracker-easy-settings.ui @@ -198,7 +198,7 @@ - Color channels used + Perspective-N-Point solver @@ -242,36 +242,47 @@ - + 0 0 + + Make sure you pick a solver supporting the number of marker you are using. For three points detection use either P3P or AP3P. + + + P3P + + + + ITERATIVE + + - Average + EPNP - Natural + P3P - Red only + DLS - Green only + UPNP - Blue only + AP3P @@ -1393,7 +1404,7 @@ Don't roll or change position. fov debug camera_settings - blob_color + comboBoxSolvers auto_threshold threshold_slider mindiam_spin diff --git a/tracker-easy/tracker-easy.cpp b/tracker-easy/tracker-easy.cpp index 199bf95a..ebc6e128 100644 --- a/tracker-easy/tracker-easy.cpp +++ b/tracker-easy/tracker-easy.cpp @@ -50,10 +50,13 @@ namespace EasyTracker // Make sure deadzones are updated whenever the settings are changed connect(&iSettings.DeadzoneRectHalfEdgeSize, value_::value_changed(), this, &Tracker::UpdateDeadzones, Qt::DirectConnection); + UpdateDeadzones(iSettings.DeadzoneRectHalfEdgeSize); - CreateModelFromSettings(); + // Make sure solver is updated whenever the settings are changed + connect(&iSettings.PnpSolver, value_::value_changed(), this, &Tracker::UpdateSolver, Qt::DirectConnection); + UpdateSolver(iSettings.PnpSolver); - UpdateDeadzones(iSettings.DeadzoneRectHalfEdgeSize); + CreateModelFromSettings(); } Tracker::~Tracker() @@ -62,9 +65,12 @@ namespace EasyTracker iThread.exit(); iThread.wait(); - - QMutexLocker l(&camera_mtx); - camera->stop(); + + if (camera) + { + QMutexLocker l(&camera_mtx); + camera->stop(); + } } @@ -156,8 +162,6 @@ namespace EasyTracker { ever_success.store(true, std::memory_order_relaxed); - // Solve P3P problem with OpenCV - //Bitmap origin is top left iTrackedPoints.clear(); // Tracked points must match the order of the object model points. @@ -233,15 +237,13 @@ namespace EasyTracker } } - dbgout << "Object: " << iModel << "\n"; dbgout << "Points: " << iTrackedPoints << "\n"; - - // TODO: try SOLVEPNP_AP3P too, make it a settings option? iAngles.clear(); iBestSolutionIndex = -1; - int solutionCount = cv::solveP3P(iModel, iTrackedPoints, iCameraMatrix, iDistCoeffsMatrix, iRotations, iTranslations, cv::SOLVEPNP_P3P); + // Solve P3P problem with OpenCV + int solutionCount = cv::solveP3P(iModel, iTrackedPoints, iCameraMatrix, iDistCoeffsMatrix, iRotations, iTranslations, iSolver); if (solutionCount > 0) { @@ -449,10 +451,23 @@ namespace EasyTracker } + void Tracker::UpdateSolver(int aSolver) + { + QMutexLocker l(¢er_lock); + iSolver = aSolver; + } + + + module_status Tracker::start_tracker(QFrame* video_frame) { - //video_frame->setAttribute(Qt::WA_NativeWindow); + // Check that we support that solver + if (iSolver!=cv::SOLVEPNP_P3P && iSolver != cv::SOLVEPNP_AP3P) + { + return module_status("Error: Solver not supported use either P3P or AP3P."); + } + //video_frame->setAttribute(Qt::WA_NativeWindow); widget = std::make_unique(video_frame); layout = std::make_unique(video_frame); layout->setContentsMargins(0, 0, 0, 0); diff --git a/tracker-easy/tracker-easy.h b/tracker-easy/tracker-easy.h index bbafcefa..41226d23 100644 --- a/tracker-easy/tracker-easy.h +++ b/tracker-easy/tracker-easy.h @@ -69,6 +69,7 @@ namespace EasyTracker void SetFps(int aFps); void DoSetFps(int aFps); void UpdateDeadzones(int aHalfEdgeSize); + void UpdateSolver(int aSolver); QMutex camera_mtx; QThread iThread; @@ -98,6 +99,9 @@ namespace EasyTracker int iDeadzoneEdge=0; int iDeadzoneHalfEdge=0; + // Solver + int iSolver = cv::SOLVEPNP_P3P; + // Statistics Timer iTimer; Timer iFpsTimer; -- cgit v1.2.3