From 028f2faa5f48e4beb77427ddd708f0372e0de97f Mon Sep 17 00:00:00 2001 From: Stéphane Lenclud Date: Sat, 20 Apr 2019 18:59:59 +0200 Subject: Easy Tracker: Deadzone implementation to minimize noise. Added Deadzone pixels size to settings. Clip and Custom model settings tabs disabled. --- tracker-easy/lang/nl_NL.ts | 16 +++- tracker-easy/lang/ru_RU.ts | 16 +++- tracker-easy/lang/stub.ts | 16 +++- tracker-easy/lang/zh_CN.ts | 16 +++- tracker-easy/settings.h | 1 + tracker-easy/tracker-easy-dialog.cpp | 1 + tracker-easy/tracker-easy-settings.ui | 161 +++++++++++++++++++++------------- tracker-easy/tracker-easy.cpp | 115 +++++++++++++++++------- tracker-easy/tracker-easy.h | 10 ++- 9 files changed, 243 insertions(+), 109 deletions(-) diff --git a/tracker-easy/lang/nl_NL.ts b/tracker-easy/lang/nl_NL.ts index 1054e1f7..f83e859a 100644 --- a/tracker-easy/lang/nl_NL.ts +++ b/tracker-easy/lang/nl_NL.ts @@ -242,10 +242,6 @@ Don't roll or change position. About - - <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> - - Status @@ -266,5 +262,17 @@ Don't roll or change position. Debug (full size preview) + + Deadzone + + + + <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> + + + + Size in pixels of half the edge defining deadzone squares around tracked points + + diff --git a/tracker-easy/lang/ru_RU.ts b/tracker-easy/lang/ru_RU.ts index 66245b14..0dbc8323 100644 --- a/tracker-easy/lang/ru_RU.ts +++ b/tracker-easy/lang/ru_RU.ts @@ -247,10 +247,6 @@ ROLL или X/Y-смещения. About О программе - - <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> - <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;">Руководство (PointTracker)</span></a></p></body></html> - Status Статус @@ -271,5 +267,17 @@ ROLL или X/Y-смещения. Debug (full size preview) + + Deadzone + + + + <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> + + + + Size in pixels of half the edge defining deadzone squares around tracked points + + diff --git a/tracker-easy/lang/stub.ts b/tracker-easy/lang/stub.ts index eca29787..32b314e9 100644 --- a/tracker-easy/lang/stub.ts +++ b/tracker-easy/lang/stub.ts @@ -242,10 +242,6 @@ Don't roll or change position. About - - <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> - - Status @@ -266,5 +262,17 @@ Don't roll or change position. Debug (full size preview) + + Deadzone + + + + <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> + + + + Size in pixels of half the edge defining deadzone squares around tracked points + + diff --git a/tracker-easy/lang/zh_CN.ts b/tracker-easy/lang/zh_CN.ts index 656cb8db..f90e261f 100644 --- a/tracker-easy/lang/zh_CN.ts +++ b/tracker-easy/lang/zh_CN.ts @@ -213,10 +213,6 @@ About 关于 - - <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> - <html><head/><body><p><span style=" font-weight:600;">FTNoIR PointTracker Plugin<br/>Version 1.1</span></p><p><span style=" font-weight:600;">Patrick Ruoff</span></p><p><a href="http://ftnoirpt.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">参考手册 (外部链接)</span></a></p></body></html> - Status 状态 @@ -266,5 +262,17 @@ Don't roll or change position. Debug (full size preview) + + Deadzone + + + + <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> + + + + Size in pixels of half the edge defining deadzone squares around tracked points + + diff --git a/tracker-easy/settings.h b/tracker-easy/settings.h index dcfb6be0..53b80052 100644 --- a/tracker-easy/settings.h +++ b/tracker-easy/settings.h @@ -34,6 +34,7 @@ namespace EasyTracker { cam_fps{ b, "camera-fps", 30 }; value min_point_size{ b, "min-point-size", 2.5 }, max_point_size{ b, "max-point-size", 50 }; + value DeadzoneRectHalfEdgeSize { b, "deadzone-rect-half-edge-size", 1 }; value m01_x{ b, "m_01-x", 0 }, m01_y{ b, "m_01-y", 0 }, m01_z{ b, "m_01-z", 0 }; value m02_x{ b, "m_02-x", 0 }, m02_y{ b, "m_02-y", 0 }, m02_z{ b, "m_02-z", 0 }; diff --git a/tracker-easy/tracker-easy-dialog.cpp b/tracker-easy/tracker-easy-dialog.cpp index f56ddfdb..e3b72e38 100644 --- a/tracker-easy/tracker-easy-dialog.cpp +++ b/tracker-easy/tracker-easy-dialog.cpp @@ -45,6 +45,7 @@ namespace EasyTracker tie_setting(s.min_point_size, ui.mindiam_spin); tie_setting(s.max_point_size, ui.maxdiam_spin); + tie_setting(s.DeadzoneRectHalfEdgeSize, ui.spinDeadzone); tie_setting(s.clip_by, ui.clip_bheight_spin); tie_setting(s.clip_bz, ui.clip_blength_spin); diff --git a/tracker-easy/tracker-easy-settings.ui b/tracker-easy/tracker-easy-settings.ui index 4430020d..ffe6ebce 100644 --- a/tracker-easy/tracker-easy-settings.ui +++ b/tracker-easy/tracker-easy-settings.ui @@ -418,23 +418,27 @@ Point extraction - - + + - + 0 0 - Threshold - - - threshold_slider + + + + Value + + + + @@ -450,8 +454,8 @@ - - + + 0 @@ -459,14 +463,49 @@ - Max size + Enable, slider sets point size + + + + + + + + 0 + 0 + + + + Threshold - maxdiam_spin + threshold_slider - + + + + + 0 + 0 + + + + Minimum point diameter + + + px + + + 1 + + + 0.100000000000000 + + + + @@ -497,21 +536,30 @@ - - + + 0 0 - - Enable, slider sets point size + + Maximum point diameter + + + px + + + 1 + + + 0.100000000000000 - - + + 0 @@ -519,71 +567,55 @@ - Automatic threshold + Max size + + + maxdiam_spin - - + + 0 0 - - Maximum point diameter - - - px - - - 1 - - - 0.100000000000000 + + Automatic threshold - - + + 0 0 - - Minimum point diameter - - - px - - - 1 + + Deadzone - - 0.100000000000000 + + maxdiam_spin - - + + - + 0 0 - - + + Size in pixels of half the edge defining deadzone squares around tracked points - - - - - - Value + + px @@ -599,6 +631,9 @@ + + true + 0 @@ -609,7 +644,7 @@ QTabWidget::Rounded - 0 + 2 false @@ -620,7 +655,10 @@ false - + + + false + Clip @@ -780,7 +818,7 @@ - + Cap @@ -915,7 +953,10 @@ - + + + false + Custom @@ -1301,7 +1342,7 @@ Don't roll or change position. - <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> + <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> Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop diff --git a/tracker-easy/tracker-easy.cpp b/tracker-easy/tracker-easy.cpp index e0ab5f7c..199bf95a 100644 --- a/tracker-easy/tracker-easy.cpp +++ b/tracker-easy/tracker-easy.cpp @@ -48,7 +48,12 @@ namespace EasyTracker // We could not get this working, nevermind //connect(&iSettings.cam_fps, value_::value_changed(), this, &Tracker::SetFps, Qt::DirectConnection); + // Make sure deadzones are updated whenever the settings are changed + connect(&iSettings.DeadzoneRectHalfEdgeSize, value_::value_changed(), this, &Tracker::UpdateDeadzones, Qt::DirectConnection); + CreateModelFromSettings(); + + UpdateDeadzones(iSettings.DeadzoneRectHalfEdgeSize); } Tracker::~Tracker() @@ -198,47 +203,79 @@ namespace EasyTracker iTrackedPoints.push_back(iPoints[leftPointIndex]); iTrackedPoints.push_back(iPoints[topPointIndex]); - dbgout << "Object: " << iModel << "\n"; - dbgout << "Points: " << iTrackedPoints << "\n"; + bool movedEnough = true; + // Check if we moved enough since last time we were here + // This is our deadzone management + if (iSettings.DeadzoneRectHalfEdgeSize != 0 // Check if deazones are enabled + && iTrackedRects.size() == iTrackedPoints.size()) + { + movedEnough = false; + for (size_t i = 0; i < iTrackedPoints.size(); i++) + { + if (!iTrackedRects[i].contains(iTrackedPoints[i])) + { + movedEnough = true; + break; + } + } + } + + if (movedEnough) + { + // Build deadzone rectangles if needed + iTrackedRects.clear(); + if (iSettings.DeadzoneRectHalfEdgeSize != 0) // Check if deazones are enabled + { + for (const cv::Point& pt : iTrackedPoints) + { + cv::Rect rect(pt - cv::Point(iDeadzoneHalfEdge, iDeadzoneHalfEdge), cv::Size(iDeadzoneEdge, iDeadzoneEdge)); + iTrackedRects.push_back(rect); + } + } + + 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); - if (solutionCount > 0) - { - dbgout << "Solution count: " << solutionCount << "\n"; - int minPitch = std::numeric_limits::max(); - // Find the solution we want amongst all possible ones - for (int i = 0; i < solutionCount; i++) + // 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); + + if (solutionCount > 0) { - dbgout << "Translation:\n"; - dbgout << iTranslations.at(i); - dbgout << "\n"; - dbgout << "Rotation:\n"; - //dbgout << rvecs.at(i); - cv::Mat rotationCameraMatrix; - cv::Rodrigues(iRotations[i], rotationCameraMatrix); - cv::Vec3d angles; - getEulerAngles(rotationCameraMatrix, angles); - iAngles.push_back(angles); - - // Check if pitch is closest to zero - int absolutePitch = std::abs(angles[0]); - if (minPitch > absolutePitch) + dbgout << "Solution count: " << solutionCount << "\n"; + int minPitch = std::numeric_limits::max(); + // Find the solution we want amongst all possible ones + for (int i = 0; i < solutionCount; i++) { - // The solution with pitch closest to zero is the one we want - minPitch = absolutePitch; - iBestSolutionIndex = i; + dbgout << "Translation:\n"; + dbgout << iTranslations.at(i); + dbgout << "\n"; + dbgout << "Rotation:\n"; + //dbgout << rvecs.at(i); + cv::Mat rotationCameraMatrix; + cv::Rodrigues(iRotations[i], rotationCameraMatrix); + cv::Vec3d angles; + getEulerAngles(rotationCameraMatrix, angles); + iAngles.push_back(angles); + + // Check if pitch is closest to zero + int absolutePitch = std::abs(angles[0]); + if (minPitch > absolutePitch) + { + // The solution with pitch closest to zero is the one we want + minPitch = absolutePitch; + iBestSolutionIndex = i; + } + + dbgout << angles; + dbgout << "\n"; } - dbgout << angles; dbgout << "\n"; } - - dbgout << "\n"; } } @@ -274,6 +311,12 @@ namespace EasyTracker iPreview.DrawCross(iPoints[topPointIndex]); } + // Render our deadzone rects + for (const cv::Rect& rect : iTrackedRects) + { + cv::rectangle(iPreview.iFrameRgb,rect,cv::Scalar(255,0,0)); + } + // Show full size preview pop-up if (iSettings.debug) { @@ -397,6 +440,14 @@ namespace EasyTracker iKf.Init(18, 6, 0, dt); } + void Tracker::UpdateDeadzones(int aHalfEdgeSize) + { + QMutexLocker l(¢er_lock); + iDeadzoneHalfEdge = aHalfEdgeSize; + iDeadzoneEdge = iDeadzoneHalfEdge * 2; + iTrackedRects.clear(); + } + module_status Tracker::start_tracker(QFrame* video_frame) { diff --git a/tracker-easy/tracker-easy.h b/tracker-easy/tracker-easy.h index 05fdb94a..bbafcefa 100644 --- a/tracker-easy/tracker-easy.h +++ b/tracker-easy/tracker-easy.h @@ -61,13 +61,14 @@ namespace EasyTracker void CreateModelFromSettings(); void CreateCameraIntrinsicsMatrices(); void ProcessFrame(); - + // bool maybe_reopen_camera(); void set_fov(int value); void SetFps(int aFps); void DoSetFps(int aFps); + void UpdateDeadzones(int aHalfEdgeSize); QMutex camera_mtx; QThread iThread; @@ -93,6 +94,10 @@ namespace EasyTracker std::atomic ever_success = false; mutable QMutex center_lock, data_lock; + // Deadzone + int iDeadzoneEdge=0; + int iDeadzoneHalfEdge=0; + // Statistics Timer iTimer; Timer iFpsTimer; @@ -108,6 +113,9 @@ namespace EasyTracker std::vector iModel; // Bitmap points corresponding to model vertices std::vector iTrackedPoints; + + std::vector iTrackedRects; + // Intrinsics camera matrix cv::Mat iCameraMatrix; // Intrinsics distortion coefficients as a matrix -- cgit v1.2.3