diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-09-15 15:00:56 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-09-15 15:00:56 +0200 |
commit | 490f3ddb79018d13182fc17bb92943bbe427643d (patch) | |
tree | d1efc46c88878cf5435a19bfc9519dfd098220a8 /FTNoIR_Tracker_PT | |
parent | bef7aff31e5ea073f0f160ca6a2f1e56b7dd881a (diff) |
New PT from Patrick Ruoff adapted to Linux
Diffstat (limited to 'FTNoIR_Tracker_PT')
-rw-r--r-- | FTNoIR_Tracker_PT/FTNoIR_PT_Controls.ui | 4 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/boost-compat.h | 6 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/camera.cpp | 135 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/camera.h | 96 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/frame_observer.cpp | 4 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/frame_observer.h | 8 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 56 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/ftnoir_tracker_pt.h | 33 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.cpp | 15 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/ftnoir_tracker_pt_dialog.h | 6 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.cpp | 10 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/ftnoir_tracker_pt_dll.h | 18 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/point_extractor.cpp | 2 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/point_extractor.h | 1 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/point_tracker.cpp | 31 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/point_tracker.h | 6 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/timer.cpp | 4 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/video_widget.cpp | 58 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/video_widget.h | 47 |
19 files changed, 405 insertions, 135 deletions
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 @@ <rect>
<x>0</x>
<y>0</y>
- <width>395</width>
- <height>552</height>
+ <width>458</width>
+ <height>590</height>
</rect>
</property>
<property name="sizePolicy">
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 <memory> +#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 <unistd.h>
+#endif
+
+#ifdef OPENTRACK_API
+void get_camera_device_names(std::vector<std::string>& 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<char const*>(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<std::string>& device_names)
{
@@ -22,6 +85,7 @@ void get_camera_device_names(std::vector<std::string>& 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 <opencv2/opencv.hpp>
-#include "videoInput/videoInput.h"
-#include <boost/shared_ptr.hpp>
+#ifndef OPENTRACK_API
+# include <boost/shared_ptr.hpp>
+#else
+# include "FTNoIR_Tracker_PT/boost-compat.h"
+# include <opencv2/highgui.hpp>
+# include <opencv2/highgui/highgui_c.h>
+#endif
#include <string>
// ----------------------------------------------------------------------------
@@ -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<FrameObserver*>::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 <QMutex>
#include <opencv2/opencv.hpp>
-#include <boost/shared_ptr.hpp>
+#ifndef OPENTRACK_API
+# include <boost/shared_ptr.hpp>
+#else
+# include "FTNoIR_Tracker_PT/boost-compat.h"
+#endif
#include <set>
//-----------------------------------------------------------------------------
@@ -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 <QFile>
#include <QCoreApplication>
+#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<cv::Vec2f>& 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: "<<dt;
@@ -113,12 +120,16 @@ void Tracker::apply(const TrackerSettings& settings) camera.set_res(settings.cam_res_x, settings.cam_res_y);
camera.set_fps(settings.cam_fps);
camera.set_f(settings.cam_f);
- frame_rotation.rotation = static_cast<FrameRotation::Rotation>(settings.cam_roll);
+ frame_rotation.rotation = static_cast<RotationType>(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<PointModel>(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<PointModel>(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 <QThread>
#include <QMutex>
+#include <QMutexLocker>
#include <QTime>
#include <opencv2/opencv.hpp>
-#include <boost/shared_ptr.hpp>
+#ifndef OPENTRACK_API
+# include <boost/shared_ptr.hpp>
+#else
+# include "FTNoIR_Tracker_PT/boost-compat.h"
+#endif
#include <vector>
//-----------------------------------------------------------------------------
@@ -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 <QMessageBox>
#include <QDebug>
#include <opencv2/opencv.hpp>
-#include <boost/shared_ptr.hpp>
+#ifndef OPENTRACK_API
+# include <boost/shared_ptr.hpp>
+#else
+# include "FTNoIR_Tracker_PT/boost-compat.h"
+#endif
#include <vector>
using namespace std;
@@ -39,7 +43,7 @@ TrackerDialog::TrackerDialog() vector<string> device_names;
get_camera_device_names(device_names);
- for (auto iter = device_names.begin(); iter != device_names.end(); ++iter)
+ for (vector<string>::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 <QIcon>
//-----------------------------------------------------------------------------
@@ -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<Vec2f>& 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 <opencv2/opencv.hpp>
+#include <opencv2/imgproc/imgproc_c.h>
// ----------------------------------------------------------------------------
// 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<float,int> a, const pair<float,int> b)
+{
+ return a.first < b.first;
+}
+#endif
+
void PointModel::get_d_order(const std::vector<cv::Vec2f>& 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<cv::Vec2f>& points, int d_order[] d_vals.push_back(pair<float, int>(d.dot(points[i]), i));
struct
- {
- bool operator()(const pair<float, int>& a, const pair<float, int>& b) { return a.first < b.first; }
- } comp;
- sort(d_vals.begin(), d_vals.end(), comp);
+ {
+ bool operator()(const pair<float, int>& a, const pair<float, int>& 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.size(); ++i)
d_order[i] = d_vals[i].second;
@@ -126,8 +140,15 @@ bool PointTracker::track(const vector<Vec2f>& 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 <opencv2/opencv.hpp>
-#include <boost/shared_ptr.hpp>
+#ifndef OPENTRACK_API
+# include <boost/shared_ptr.hpp>
+#else
+# include "FTNoIR_Tracker_PT/boost-compat.h"
+#endif
#include <list>
// ----------------------------------------------------------------------------
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 <QGLWidget>
#include <QTime>
#include <QDialog>
#include <opencv2/opencv.hpp>
-#include <boost/shared_ptr.hpp>
+#ifndef OPENTRACK_API
+# include <QGLWidget>
+# include <boost/shared_ptr.hpp>
+#else
+# include "FTNoIR_Tracker_PT/boost-compat.h"
+# if defined(_WIN32)
+# include <dshow.h>
+# endif
+#endif
+#include <QPainter>
+#include <QPaintEvent>
+#include <QTimer>
+#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<cv::Vec2f> > 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
|