summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStéphane Lenclud <github@lenclud.com>2019-04-16 18:01:57 +0200
committerStéphane Lenclud <github@lenclud.com>2019-04-24 18:46:12 +0200
commitbe51a114bca4f3f43ed88001cdc510ccf246079f (patch)
treeac0b3b4f2a3b7091cb4657a422469e13716e380c
parent1fb6122dce1a5bc117e925006d87828a52cfecb6 (diff)
Easy Tracker: Mostly code clean-up.
-rw-r--r--tracker-easy/tracker-easy.cpp26
-rw-r--r--tracker-easy/tracker-easy.h10
-rw-r--r--tracker-kinect-face/camera_kinect_ir.cpp332
-rw-r--r--tracker-kinect-face/camera_kinect_ir.h6
4 files changed, 189 insertions, 185 deletions
diff --git a/tracker-easy/tracker-easy.cpp b/tracker-easy/tracker-easy.cpp
index 68e3be36..4afb928a 100644
--- a/tracker-easy/tracker-easy.cpp
+++ b/tracker-easy/tracker-easy.cpp
@@ -36,17 +36,17 @@ namespace EasyTracker
{
Tracker::Tracker() :
- s{ KModuleName },
+ iSettings{ KModuleName },
iPreview{ preview_width, preview_height }
{
cv::setBreakOnError(true);
cv::setNumThreads(1);
- connect(s.b.get(), &bundle_::saving, this, &Tracker::maybe_reopen_camera, Qt::DirectConnection);
- connect(s.b.get(), &bundle_::reloading, this, &Tracker::maybe_reopen_camera, Qt::DirectConnection);
+ connect(iSettings.b.get(), &bundle_::saving, this, &Tracker::maybe_reopen_camera, Qt::DirectConnection);
+ connect(iSettings.b.get(), &bundle_::reloading, this, &Tracker::maybe_reopen_camera, Qt::DirectConnection);
- connect(&s.fov, value_::value_changed<int>(), this, &Tracker::set_fov, Qt::DirectConnection);
- set_fov(s.fov);
+ connect(&iSettings.fov, value_::value_changed<int>(), this, &Tracker::set_fov, Qt::DirectConnection);
+ set_fov(iSettings.fov);
CreateModelFromSettings();
}
@@ -92,8 +92,8 @@ namespace EasyTracker
// TODO: Need to support clip too. That's cap only for now.
// s.active_model_panel != PointModel::Clip
iModel.clear();
- iModel.push_back(cv::Point3f(s.cap_x / 10.0, s.cap_z / 10.0, -s.cap_y / 10.0)); // Right
- iModel.push_back(cv::Point3f(-s.cap_x / 10.0, s.cap_z / 10.0, -s.cap_y / 10.0)); // Left
+ iModel.push_back(cv::Point3f(iSettings.cap_x / 10.0, iSettings.cap_z / 10.0, -iSettings.cap_y / 10.0)); // Right
+ iModel.push_back(cv::Point3f(-iSettings.cap_x / 10.0, iSettings.cap_z / 10.0, -iSettings.cap_y / 10.0)); // Left
iModel.push_back(cv::Point3f(0, 0, 0)); // Top
}
@@ -286,7 +286,7 @@ namespace EasyTracker
}
// Show full size preview pop-up
- if (s.debug)
+ if (iSettings.debug)
{
cv::imshow("Preview", iPreview.iFrameRgb);
cv::waitKey(1);
@@ -306,7 +306,7 @@ namespace EasyTracker
else
{
// No preview, destroy preview pop-up
- if (s.debug)
+ if (iSettings.debug)
{
cv::destroyWindow("Preview");
}
@@ -345,9 +345,9 @@ namespace EasyTracker
return true;
}
- iCameraInfo.fps = s.cam_fps;
- iCameraInfo.width = s.cam_res_x;
- iCameraInfo.height = s.cam_res_y;
+ iCameraInfo.fps = iSettings.cam_fps;
+ iCameraInfo.width = iSettings.cam_res_x;
+ iCameraInfo.height = iSettings.cam_res_y;
bool res = camera->start(iCameraInfo);
// We got new our camera intrinsics, create corresponding matrices
@@ -374,7 +374,7 @@ namespace EasyTracker
video_frame->show();
// Create our camera
- camera = video::make_camera(s.camera_name);
+ camera = video::make_camera(iSettings.camera_name);
start(QThread::HighPriority);
diff --git a/tracker-easy/tracker-easy.h b/tracker-easy/tracker-easy.h
index 257dd6ca..06551533 100644
--- a/tracker-easy/tracker-easy.h
+++ b/tracker-easy/tracker-easy.h
@@ -39,11 +39,16 @@ namespace EasyTracker
struct Tracker : QThread, ITracker
{
- public:
+ // We had problem where Qt slots would not get disconnected upon object destruction.
+ // Issue seems to be gone now even without Q_OBJECT declaration, go figure.
+ //Q_OBJECT
+ public:
friend class Dialog;
explicit Tracker();
~Tracker() override;
+
+ // From ITracker
module_status start_tracker(QFrame* parent_window) override;
void data(double* data) override;
bool center() override;
@@ -52,6 +57,7 @@ namespace EasyTracker
void CreateModelFromSettings();
void CreateCameraIntrinsicsMatrices();
+ // From QThread
void run() override;
bool maybe_reopen_camera();
@@ -60,7 +66,7 @@ namespace EasyTracker
QMutex camera_mtx;
- Settings s;
+ Settings iSettings;
std::unique_ptr<QLayout> layout;
std::vector<cv::Point> iPoints;
diff --git a/tracker-kinect-face/camera_kinect_ir.cpp b/tracker-kinect-face/camera_kinect_ir.cpp
index e170b15a..b881d51f 100644
--- a/tracker-kinect-face/camera_kinect_ir.cpp
+++ b/tracker-kinect-face/camera_kinect_ir.cpp
@@ -10,7 +10,7 @@
#ifdef OTR_HAVE_OPENCV
-//#include "frame.hpp"
+ //#include "frame.hpp"
#include "compat/sleep.hpp"
#include "compat/math-imports.hpp"
@@ -28,7 +28,7 @@ namespace Kinect {
{
if (name.compare(KKinectIRSensor) == 0)
{
- return std::make_unique<CameraKinectIr>();
+ return std::make_unique<InfraredCamera>();
}
return nullptr;
@@ -49,239 +49,237 @@ namespace Kinect {
return false;
}
-// Register our camera provider thus making sure Point Tracker can use Kinect V2 IR Sensor
-OTR_REGISTER_CAMERA(CamerasProvider)
+ // Register our camera provider thus making sure Point Tracker can use Kinect V2 IR Sensor
+ OTR_REGISTER_CAMERA(CamerasProvider)
-CameraKinectIr::CameraKinectIr()
-{
-}
-
+ InfraredCamera::InfraredCamera()
+ {
+ }
-CameraKinectIr::~CameraKinectIr()
-{
- stop();
-}
-bool CameraKinectIr::show_dialog()
-{
- return false;
-}
+ InfraredCamera::~InfraredCamera()
+ {
+ stop();
+ }
-bool CameraKinectIr::is_open()
-{
- return iInfraredFrameReader!=nullptr;
-}
+ bool InfraredCamera::show_dialog()
+ {
+ return false;
+ }
-///
-/// Wait until we get a first frame
-///
-void CameraKinectIr::WaitForFirstFrame()
-{
- bool new_frame = false;
- int attempts = 200; // Kinect cold start can take a while
- while (!new_frame && attempts>0)
+ bool InfraredCamera::is_open()
{
- new_frame = get_frame_(iMatFrame);
- portable::sleep(100);
- --attempts;
+ return iInfraredFrameReader != nullptr;
}
-}
+ ///
+ /// Wait until we get a first frame
+ ///
+ void InfraredCamera::WaitForFirstFrame()
+ {
+ bool new_frame = false;
+ int attempts = 200; // Kinect cold start can take a while
+ while (!new_frame && attempts > 0)
+ {
+ new_frame = get_frame_(iMatFrame);
+ portable::sleep(100);
+ --attempts;
+ }
+ }
-std::tuple<const video::impl::frame&, bool> CameraKinectIr::get_frame()
-{
- bool new_frame = false;
- new_frame = get_frame_(iMatFrame);
-
- iFrame.data = iMatFrame.ptr();
- iFrame.width = iWidth;
- iFrame.height = iHeight;
- iFrame.stride = cv::Mat::AUTO_STEP;
- iFrame.channels = iMatFrame.channels();
- iFrame.channelSize = iMatFrame.elemSize1();
- return { iFrame, new_frame };
-}
-// Safe release for interfaces
-template<class Interface>
-inline void SafeRelease(Interface *& pInterfaceToRelease)
-{
- if (pInterfaceToRelease != NULL)
+ std::tuple<const video::impl::frame&, bool> InfraredCamera::get_frame()
{
- pInterfaceToRelease->Release();
- pInterfaceToRelease = NULL;
- }
-}
-
-///
-///
-///
-bool CameraKinectIr::start(info& aInfo)
-{
- stop();
+ bool new_frame = false;
+ new_frame = get_frame_(iMatFrame);
- HRESULT hr;
+ iFrame.data = iMatFrame.ptr();
+ iFrame.width = iWidth;
+ iFrame.height = iHeight;
+ iFrame.stride = cv::Mat::AUTO_STEP;
+ iFrame.channels = iMatFrame.channels();
+ iFrame.channelSize = iMatFrame.elemSize1();
+ return { iFrame, new_frame };
+ }
- // Get and open Kinect sensor
- hr = GetDefaultKinectSensor(&iKinectSensor);
- if (SUCCEEDED(hr))
+ // Safe release for interfaces
+ template<class Interface>
+ inline void SafeRelease(Interface *& pInterfaceToRelease)
{
- hr = iKinectSensor->Open();
+ if (pInterfaceToRelease != NULL)
+ {
+ pInterfaceToRelease->Release();
+ pInterfaceToRelease = NULL;
+ }
}
- // Create infrared frame reader
- if (SUCCEEDED(hr))
+ ///
+ ///
+ ///
+ bool InfraredCamera::start(info& aInfo)
{
- // Initialize the Kinect and get the infrared reader
- IInfraredFrameSource* pInfraredFrameSource = NULL;
+ stop();
- hr = iKinectSensor->Open();
+ HRESULT hr;
+ // Get and open Kinect sensor
+ hr = GetDefaultKinectSensor(&iKinectSensor);
if (SUCCEEDED(hr))
{
- hr = iKinectSensor->get_InfraredFrameSource(&pInfraredFrameSource);
+ hr = iKinectSensor->Open();
}
+ // Create infrared frame reader
if (SUCCEEDED(hr))
{
- hr = pInfraredFrameSource->OpenReader(&iInfraredFrameReader);
- }
+ // Initialize the Kinect and get the infrared reader
+ IInfraredFrameSource* pInfraredFrameSource = NULL;
- SafeRelease(pInfraredFrameSource);
+ hr = iKinectSensor->Open();
- if (SUCCEEDED(hr))
- {
- iKinectSensor->get_CoordinateMapper(&iCoordinateMapper);
- }
- }
+ if (SUCCEEDED(hr))
+ {
+ hr = iKinectSensor->get_InfraredFrameSource(&pInfraredFrameSource);
+ }
+ if (SUCCEEDED(hr))
+ {
+ hr = pInfraredFrameSource->OpenReader(&iInfraredFrameReader);
+ }
- if (SUCCEEDED(hr))
- {
- WaitForFirstFrame();
- bool success = iMatFrame.ptr() != nullptr;
- if (success)
- {
- // Provide frame info
- aInfo.width = iWidth;
- aInfo.height = iHeight;
+ SafeRelease(pInfraredFrameSource);
- CameraIntrinsics intrinsics;
- hr = iCoordinateMapper->GetDepthCameraIntrinsics(&intrinsics);
if (SUCCEEDED(hr))
{
- aInfo.focalLengthX = intrinsics.FocalLengthX;
- aInfo.focalLengthY = intrinsics.FocalLengthY;
- aInfo.principalPointX = intrinsics.PrincipalPointX;
- aInfo.principalPointY = intrinsics.PrincipalPointY;
- aInfo.radialDistortionFourthOrder = intrinsics.RadialDistortionFourthOrder;
- aInfo.radialDistortionSecondOrder = intrinsics.RadialDistortionSecondOrder;
- aInfo.radialDistortionSixthOrder = intrinsics.RadialDistortionSixthOrder;
+ iKinectSensor->get_CoordinateMapper(&iCoordinateMapper);
}
-
}
- return success;
- }
- stop();
- return false;
-}
+ if (SUCCEEDED(hr))
+ {
+ WaitForFirstFrame();
+ bool success = iMatFrame.ptr() != nullptr;
+ if (success)
+ {
+ // Provide frame info
+ aInfo.width = iWidth;
+ aInfo.height = iHeight;
+
+ CameraIntrinsics intrinsics;
+ hr = iCoordinateMapper->GetDepthCameraIntrinsics(&intrinsics);
+ if (SUCCEEDED(hr))
+ {
+ aInfo.focalLengthX = intrinsics.FocalLengthX;
+ aInfo.focalLengthY = intrinsics.FocalLengthY;
+ aInfo.principalPointX = intrinsics.PrincipalPointX;
+ aInfo.principalPointY = intrinsics.PrincipalPointY;
+ aInfo.radialDistortionFourthOrder = intrinsics.RadialDistortionFourthOrder;
+ aInfo.radialDistortionSecondOrder = intrinsics.RadialDistortionSecondOrder;
+ aInfo.radialDistortionSixthOrder = intrinsics.RadialDistortionSixthOrder;
+ }
-void CameraKinectIr::stop()
-{
- // done with infrared frame reader
- SafeRelease(iInfraredFrame);
- SafeRelease(iInfraredFrameReader);
+ }
- // close the Kinect Sensor
- if (iKinectSensor)
- {
- iKinectSensor->Close();
+ return success;
+ }
+
+ stop();
+ return false;
}
- SafeRelease(iCoordinateMapper);
- SafeRelease(iKinectSensor);
+ void InfraredCamera::stop()
+ {
+ // done with infrared frame reader
+ SafeRelease(iInfraredFrame);
+ SafeRelease(iInfraredFrameReader);
- // Free up our memory buffer if any
- iMatFrame = cv::Mat();
-}
+ // close the Kinect Sensor
+ if (iKinectSensor)
+ {
+ iKinectSensor->Close();
+ }
-bool CameraKinectIr::get_frame_(cv::Mat& aFrame)
-{
+ SafeRelease(iCoordinateMapper);
+ SafeRelease(iKinectSensor);
- if (!iInfraredFrameReader)
- {
- return false;
+ // Free up our memory buffer if any
+ iMatFrame = cv::Mat();
}
- bool success = false;
+ bool InfraredCamera::get_frame_(cv::Mat& aFrame)
+ {
- // Release previous frame if any
- SafeRelease(iInfraredFrame);
+ if (!iInfraredFrameReader)
+ {
+ return false;
+ }
- HRESULT hr = iInfraredFrameReader->AcquireLatestFrame(&iInfraredFrame);
+ bool success = false;
- if (SUCCEEDED(hr))
- {
- if (iFirstFrame)
- {
- IFrameDescription* frameDescription = NULL;
+ // Release previous frame if any
+ SafeRelease(iInfraredFrame);
- if (SUCCEEDED(hr))
- {
- hr = iInfraredFrame->get_FrameDescription(&frameDescription);
- }
+ HRESULT hr = iInfraredFrameReader->AcquireLatestFrame(&iInfraredFrame);
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr))
+ {
+ if (iFirstFrame)
{
- hr = frameDescription->get_Width(&iWidth);
+ IFrameDescription* frameDescription = NULL;
+
+ if (SUCCEEDED(hr))
+ {
+ hr = iInfraredFrame->get_FrameDescription(&frameDescription);
+ }
+
+ if (SUCCEEDED(hr))
+ {
+ hr = frameDescription->get_Width(&iWidth);
+ }
+
+ if (SUCCEEDED(hr))
+ {
+ hr = frameDescription->get_Height(&iHeight);
+ }
+
+ if (SUCCEEDED(hr))
+ {
+ hr = frameDescription->get_DiagonalFieldOfView(&iFov);
+ }
+
+ if (SUCCEEDED(hr))
+ {
+ iFirstFrame = false;
+ }
+
+ SafeRelease(frameDescription);
}
- if (SUCCEEDED(hr))
- {
- hr = frameDescription->get_Height(&iHeight);
- }
+
+ UINT nBufferSize = 0;
+ UINT16 *pBuffer = NULL;
if (SUCCEEDED(hr))
{
- hr = frameDescription->get_DiagonalFieldOfView(&iFov);
+ hr = iInfraredFrame->AccessUnderlyingBuffer(&nBufferSize, &pBuffer);
}
if (SUCCEEDED(hr))
{
- iFirstFrame = false;
+ // Create an OpenCV matrix with our 16-bits IR buffer
+ aFrame = cv::Mat(iHeight, iWidth, CV_16UC1, pBuffer, cv::Mat::AUTO_STEP);
+ // Any processing of the frame is left to the user
+ success = true;
}
-
- SafeRelease(frameDescription);
}
- UINT nBufferSize = 0;
- UINT16 *pBuffer = NULL;
-
- if (SUCCEEDED(hr))
- {
- hr = iInfraredFrame->AccessUnderlyingBuffer(&nBufferSize, &pBuffer);
- }
-
- if (SUCCEEDED(hr))
- {
- // Create an OpenCV matrix with our 16-bits IR buffer
- aFrame = cv::Mat(iHeight, iWidth, CV_16UC1, pBuffer, cv::Mat::AUTO_STEP);
- // Any processing of the frame is left to the user
- success = true;
- }
+ return success;
}
-
- return success;
-}
-
-
-
}
#endif
diff --git a/tracker-kinect-face/camera_kinect_ir.h b/tracker-kinect-face/camera_kinect_ir.h
index b88efdcd..83acb4d6 100644
--- a/tracker-kinect-face/camera_kinect_ir.h
+++ b/tracker-kinect-face/camera_kinect_ir.h
@@ -39,10 +39,10 @@ namespace Kinect {
///
/// Implement our camera interface using Kinect V2 SDK IR Sensor.
///
-struct CameraKinectIr final : video::impl::camera
+struct InfraredCamera final : video::impl::camera
{
- CameraKinectIr();
- ~CameraKinectIr() override;
+ InfraredCamera();
+ ~InfraredCamera() override;
// From video::impl::camera
[[nodiscard]] bool start(info& args) override;