diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2013-04-02 18:41:01 +0200 | 
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-04-02 18:41:01 +0200 | 
| commit | 8303597a865400a363ae574ccde819302495f498 (patch) | |
| tree | c83b383b3ec818f610cc6137f2b72ee7b4173b09 /ftnoir_tracker_pt | |
| parent | 8adf6b1650af6027f28db12ca2b4de92a3fac11d (diff) | |
Just put everything new in. Conflict resolution will be later
Diffstat (limited to 'ftnoir_tracker_pt')
| -rw-r--r-- | ftnoir_tracker_pt/Resources/icon.ico | bin | 0 -> 4286 bytes | |||
| -rw-r--r-- | ftnoir_tracker_pt/camera.cpp | 58 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/camera.h | 20 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/ftnoir_pt_controls.ui | 21 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 82 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt.h | 28 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp | 11 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.h | 6 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt_dll.cpp | 8 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt_dll.h | 7 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/point_extractor.cpp | 15 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/point_tracker.cpp | 22 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/point_tracker.h | 4 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/timer.cpp | 3 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/video_widget.cpp | 60 | ||||
| -rw-r--r-- | ftnoir_tracker_pt/video_widget.h | 17 | 
16 files changed, 196 insertions, 166 deletions
diff --git a/ftnoir_tracker_pt/Resources/icon.ico b/ftnoir_tracker_pt/Resources/icon.ico Binary files differnew file mode 100644 index 00000000..c4b2aedc --- /dev/null +++ b/ftnoir_tracker_pt/Resources/icon.ico diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index fc11c738..96ba3b89 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -68,45 +68,33 @@ bool Camera::get_frame(float dt, cv::Mat* frame)  }
  // ----------------------------------------------------------------------------
 -/*
  void CVCamera::start()
  {
 -	cap = cvCreateCameraCapture(desired_index);
 -	// extract camera info
 -	if (cap)
 -	{
 -		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);
 -	}
 +	cap = new VideoCapture(desired_index);
 +// extract camera info
 +    active = true;
 +    active_index = desired_index;
 +    cam_info.res_x = cap->get(CV_CAP_PROP_FRAME_WIDTH);
 +    cam_info.res_y = cap->get(CV_CAP_PROP_FRAME_HEIGHT);
  }
  void CVCamera::stop()
  {
 -	if (cap) cvReleaseCapture(&cap);
 +	if (cap) {
 +        cap->release();
 +        delete cap;
 +        cap = NULL;
 +    }
  	active = false;
  }
  bool CVCamera::_get_frame(Mat* frame)
  {
 -    if (cap && cvGrabFrame(cap) != 0)
 -	{
 -		// 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;
 -		}
 -	}
 -	return false;
 +    Mat tmp;
 +    bool ret = cap->read(tmp);
 +    if (ret)
 +        flip(tmp, *frame, 0);
 +    return ret;
  }
  void CVCamera::_set_index()
 @@ -121,21 +109,21 @@ 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);
  	}
  }
 -*/
 +#if 0
  // ----------------------------------------------------------------------------
  VICamera::VICamera() : frame_buffer(NULL)
  {
 @@ -223,4 +211,4 @@ void VICamera::_set_res()  {
  	if (active) restart();
  }
 -
 +#endif
 diff --git a/ftnoir_tracker_pt/camera.h b/ftnoir_tracker_pt/camera.h index cd1f0842..9977431b 100644 --- a/ftnoir_tracker_pt/camera.h +++ b/ftnoir_tracker_pt/camera.h @@ -9,7 +9,7 @@  #define CAMERA_H
  #include <opencv2/opencv.hpp>
 -#include "videoInput/videoInput.h"
 +//#include "videoInput/videoInput.h"
  // ----------------------------------------------------------------------------
  struct CamInfo
 @@ -27,7 +27,7 @@ struct CamInfo  class Camera
  {
  public:
 -	Camera() : dt_valid(0), dt_mean(0), desired_index(0), active_index(-1), active(false) {}
 +    Camera() : desired_index(0), active_index(-1), active(false), dt_valid(0), dt_mean(0) {}
  	virtual ~Camera() {}
  	// start/stop capturing
 @@ -57,19 +57,19 @@ protected:  	virtual void _set_fps() = 0;
  	virtual void _set_res() = 0;
 +    int desired_index;
 +    int active_index;
  	bool active;
 -	int desired_index;
 -	int active_index;
 +    float dt_valid;
 +    float dt_mean;
  	CamInfo cam_info;
  	CamInfo cam_desired;
 -	float dt_valid;
 -	float dt_mean;
  };
  // ----------------------------------------------------------------------------
  // OpenCV camera
 -/*
 +
  class CVCamera : public Camera
  {
  public:
 @@ -86,12 +86,13 @@ protected:  	void _set_fps();
  	void _set_res();
 -	CvCapture* cap;
 +	cv::VideoCapture* cap;
  };
 -*/
 +
  // ----------------------------------------------------------------------------
  // videoInput camera
 +#if 0
  class VICamera : public Camera
  {
  public:
 @@ -112,5 +113,6 @@ protected:  	cv::Mat new_frame;
  	unsigned char* frame_buffer;
  };
 +#endif
  #endif //CAMERA_H
 diff --git a/ftnoir_tracker_pt/ftnoir_pt_controls.ui b/ftnoir_tracker_pt/ftnoir_pt_controls.ui index 0174df23..0934a4fb 100644 --- a/ftnoir_tracker_pt/ftnoir_pt_controls.ui +++ b/ftnoir_tracker_pt/ftnoir_pt_controls.ui @@ -9,7 +9,7 @@     <rect>
      <x>0</x>
      <y>0</y>
 -    <width>405</width>
 +    <width>451</width>
      <height>489</height>
     </rect>
    </property>
 @@ -23,8 +23,8 @@     <string>PointTracker Settings</string>
    </property>
    <property name="windowIcon">
 -   <iconset resource="ftnoir_tracker_pt.qrc">
 -    <normaloff>:/Resources/icon.ico</normaloff>:/Resources/icon.ico</iconset>
 +   <iconset>
 +    <normaloff>:/Resources/icon.png</normaloff>:/Resources/icon.png</iconset>
    </property>
    <property name="layoutDirection">
     <enum>Qt::LeftToRight</enum>
 @@ -54,7 +54,7 @@        <locale language="English" country="UnitedStates"/>
       </property>
       <property name="currentIndex">
 -      <number>0</number>
 +      <number>1</number>
       </property>
       <widget class="QWidget" name="tab">
        <attribute name="title">
 @@ -561,6 +561,9 @@                  <property name="toolTip">
                   <string>Desired capture framerate</string>
                  </property>
 +                <property name="maximum">
 +                 <number>300</number>
 +                </property>
                 </widget>
                </item>
               </layout>
 @@ -959,7 +962,7 @@                    <string/>
                   </property>
                   <property name="pixmap">
 -                  <pixmap resource="ftnoir_tracker_pt.qrc">:/Resources/clip_side.png</pixmap>
 +                  <pixmap resource="ftnoir_tracker_pt.qrc">:/resources/clip_side.png</pixmap>
                   </property>
                  </widget>
                  <widget class="QSpinBox" name="clip_theight_spin">
 @@ -1082,7 +1085,7 @@                    <string/>
                   </property>
                   <property name="pixmap">
 -                  <pixmap resource="ftnoir_tracker_pt.qrc">:/Resources/clip_front.png</pixmap>
 +                  <pixmap resource="ftnoir_tracker_pt.qrc">:/resources/clip_front.png</pixmap>
                   </property>
                  </widget>
                  <widget class="QLabel" name="label_53">
 @@ -1137,7 +1140,7 @@                    <string/>
                   </property>
                   <property name="pixmap">
 -                  <pixmap resource="ftnoir_tracker_pt.qrc">:/Resources/cap_side.png</pixmap>
 +                  <pixmap resource="ftnoir_tracker_pt.qrc">:/resources/cap_side.png</pixmap>
                   </property>
                  </widget>
                  <widget class="QSpinBox" name="cap_height_spin">
 @@ -1247,7 +1250,7 @@                    <string/>
                   </property>
                   <property name="pixmap">
 -                  <pixmap resource="ftnoir_tracker_pt.qrc">:/Resources/cap_front.png</pixmap>
 +                  <pixmap resource="ftnoir_tracker_pt.qrc">:/resources/cap_front.png</pixmap>
                   </property>
                  </widget>
                  <widget class="QSpinBox" name="cap_width_spin">
 @@ -1656,7 +1659,7 @@          <string/>
         </property>
         <property name="pixmap">
 -        <pixmap resource="ftnoir_tracker_pt.qrc">:/Resources/Logo_IR.png</pixmap>
 +        <pixmap resource="ftnoir_tracker_pt.qrc">:/resources/logo_ir.png</pixmap>
         </property>
        </widget>
       </widget>
 diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index 5b77da69..db863e3a 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -11,23 +11,22 @@  #include <QDebug>
  #include <QFile>
  #include <QCoreApplication>
 +#include "facetracknoir/global-settings.h"
  using namespace std;
  using namespace cv;
 -using namespace boost;
  //#define PT_PERF_LOG	//log performance
  //-----------------------------------------------------------------------------
  Tracker::Tracker()
 -	: frame_count(0), commands(0), video_widget(NULL), tracking_valid(false)
 +    : tracking_valid(false), frame_count(0), commands(0), video_widget(NULL), fresh(false)
  {
 +    should_quit = false;
  	qDebug()<<"Tracker::Tracker";
  	TrackerSettings settings;
 -	settings.load_ini();
 +    settings.load_ini();
  	apply(settings);
 -	camera.start();
 -	start();
  }
  Tracker::~Tracker()
 @@ -66,8 +65,12 @@ void Tracker::run()  	forever
  	{
  		{	
 +            
 +            refreshVideo();
  			QMutexLocker lock(&mutex);
 -			
 +            if (should_quit)
 +                break;
 +
  			if (commands & ABORT) break;
  			if (commands & PAUSE) continue;
  			commands = 0;
 @@ -105,7 +108,7 @@ void Tracker::apply(const TrackerSettings& settings)  	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.point_model = std::auto_ptr<PointModel>(new PointModel(settings.M01, settings.M02));
  	point_tracker.dynamic_pose_resolution = settings.dyn_pose_res;
  	sleep_time = settings.sleep_time;
  	point_tracker.dt_reset = settings.reset_time / 1000.0;
 @@ -138,57 +141,60 @@ void Tracker::center()  	X_CH_0 = X_CM_0 * X_MH;
  }
 -//-----------------------------------------------------------------------------
 -// ITracker interface
 -void Tracker::Initialize(QFrame *videoframe)
 -{
 -	const int VIDEO_FRAME_WIDTH = 252;
 -	const int VIDEO_FRAME_HEIGHT = 189;
 -
 -	qDebug("Tracker::Initialize");
 -	// setup video frame
 -	videoframe->setAttribute(Qt::WA_NativeWindow);
 -	videoframe->show();
 -	video_widget = new VideoWidget(videoframe);
 -	QHBoxLayout* layout = new QHBoxLayout();
 -	layout->setContentsMargins(0, 0, 0, 0);
 -	layout->addWidget(video_widget);
 -	if (videoframe->layout()) delete videoframe->layout();
 -	videoframe->setLayout(layout);
 -	video_widget->resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT);
 -}
 -
  void Tracker::refreshVideo()
  {	
  	if (video_widget)
  	{
  		Mat frame_copy;
 -		shared_ptr< vector<Vec2f> > points;
 +		std::auto_ptr< vector<Vec2f> > points;
  		{
  			QMutexLocker lock(&mutex);
  			if (!draw_frame || frame.empty()) return;
  			// copy the frame and points from the tracker thread
  			frame_copy = frame.clone();
 -			points = shared_ptr< vector<Vec2f> >(new vector<Vec2f>(point_extractor.get_points()));
 +			points = std::auto_ptr< vector<Vec2f> >(new vector<Vec2f>(point_extractor.get_points()));
  		}
 -		video_widget->update(frame_copy, points);
 +		video_widget->update_image(frame_copy, points);
 +        fresh = true;
  	}
  }
 -void Tracker::StartTracker(HWND parent_window)
 +void Tracker::StartTracker(QFrame* videoframe)
  {
 +    const int VIDEO_FRAME_WIDTH = 252;
 +    const int VIDEO_FRAME_HEIGHT = 189;
 +    TrackerSettings settings;
 +    settings.load_ini();
 +    apply(settings);
 +    camera.start();
 +    start();
 +    qDebug("Tracker::Initialize");
 +    // setup video frame
 +    video_widget = new VideoWidget(videoframe);
 +    QHBoxLayout* layout = new QHBoxLayout();
 +    layout->setContentsMargins(0, 0, 0, 0);
 +    layout->addWidget(video_widget);
 +    if (videoframe->layout()) delete videoframe->layout();
 +    videoframe->setLayout(layout);
 +    video_widget->resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT);
 +    videoframe->show();
  	reset_command(PAUSE);
 +    connect(&timer, SIGNAL(timeout()), this, SLOT(paint_widget()), Qt::QueuedConnection);
 +    timer.start(40);
  }
 -void Tracker::StopTracker(bool exit)
 -{
 -	set_command(PAUSE);
 +void Tracker::paint_widget() {
 +    if (fresh) {
 +        fresh = false;
 +        video_widget->update();
 +    }
  }
  bool Tracker::GiveHeadPoseData(THeadPoseData *data)
  {
 +    refreshVideo();
  	const float rad2deg = 180.0/3.14159265;
  	const float deg2rad = 1.0/rad2deg;
  	{
 @@ -249,9 +255,9 @@ bool Tracker::GiveHeadPoseData(THeadPoseData *data)  }
  //-----------------------------------------------------------------------------
 -#pragma comment(linker, "/export:GetTracker=_GetTracker@0")
 +//#pragma comment(linker, "/export:GetTracker=_GetTracker@0")
 -FTNOIR_TRACKER_BASE_EXPORT ITrackerPtr __stdcall GetTracker()
 +extern "C" FTNOIR_TRACKER_BASE_EXPORT void* CALLING_CONVENTION GetConstructor()
  {
 -	return new Tracker;
 -}
\ No newline at end of file +    return (ITracker*) new Tracker;
 +}
 diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.h b/ftnoir_tracker_pt/ftnoir_tracker_pt.h index 2533a39b..49881b69 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.h @@ -8,7 +8,7 @@  #ifndef FTNOIR_TRACKER_PT_H
  #define FTNOIR_TRACKER_PT_H
 -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h"
 +#include "ftnoir_tracker_base/ftnoir_tracker_base.h"
  #include "ftnoir_tracker_pt_settings.h"
  #include "camera.h"
  #include "point_extractor.h"
 @@ -20,18 +20,19 @@  #include <QMutex>
  #include <QTime>
  #include <opencv2/opencv.hpp>
 +#include <QFrame>
 +#include <QTimer>
  //-----------------------------------------------------------------------------
 -class Tracker : public ITracker, QThread
 +class Tracker : public QThread, public ITracker
  {
 +    Q_OBJECT
  public:
  	Tracker();
  	~Tracker();
  	// ITracker interface
 -	void Initialize(QFrame *videoframe);
 -	void StartTracker(HWND parent_window);
 -	void StopTracker(bool exit);
 +    void StartTracker(QFrame* videoFrame);
  	bool GiveHeadPoseData(THeadPoseData *data);
  	void refreshVideo();
 @@ -40,6 +41,10 @@ public:  	void center();
  	void reset();	// reset the trackers internal state variables
  	void run();
 +    void WaitForExit() {
 +        should_quit = true;
 +        wait();
 +    }
  	void get_pose(FrameTrafo* X_CM) { QMutexLocker lock(&mutex); *X_CM = point_tracker.get_pose(); }
  	int get_n_points() { QMutexLocker lock(&mutex); return point_extractor.get_points().size(); }
 @@ -47,8 +52,6 @@ public:  protected:	
  	FrameTrafo X_CH_0; // for centering
 -
 -	QMutex mutex;
  	cv::Mat frame;	// the output frame for display
  	enum Command {
 @@ -57,9 +60,8 @@ protected:  	};
  	void set_command(Command command);
  	void reset_command(Command command);
 -	int commands;
 -	VICamera camera;
 +    CVCamera camera;
  	PointExtractor point_extractor;
  	PointTracker point_tracker;
  	bool tracking_valid;
 @@ -78,9 +80,17 @@ protected:  	bool bEnableZ;
  	long frame_count;
 +    int commands;
  	VideoWidget* video_widget;
  	Timer time;
 +    QMutex mutex;
 +    volatile bool should_quit;
 +    volatile bool fresh;
 +    QTimer timer;
 +    
 +protected slots:
 +    void paint_widget();
  };
  #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 a1531dd7..c1067ba7 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp @@ -9,10 +9,11 @@  #include <QMessageBox>
  #include <QDebug>
 +#include "facetracknoir/global-settings.h"
  //-----------------------------------------------------------------------------
  TrackerDialog::TrackerDialog()
 -	: settings_dirty(false), tracker(NULL), timer(this), trans_calib_running(false)
 +    : settings_dirty(false), tracker(NULL), trans_calib_running(false), timer(this)
  {
  	qDebug()<<"TrackerDialog::TrackerDialog";
  	setAttribute(Qt::WA_DeleteOnClose, false);
 @@ -328,9 +329,9 @@ void TrackerDialog::unRegisterTracker()  }
  //-----------------------------------------------------------------------------
 -#pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0")
 +//#pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0")
 -FTNOIR_TRACKER_BASE_EXPORT ITrackerDialogPtr __stdcall GetTrackerDialog( )
 +extern "C" FTNOIR_TRACKER_BASE_EXPORT void* CALLING_CONVENTION GetDialog( )
  {
 -	return new TrackerDialog;
 -}
\ No newline at end of file +    return (ITrackerDialog*) new TrackerDialog;
 +}
 diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.h b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.h index 0f836dfe..28120692 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.h @@ -8,10 +8,10 @@  #ifndef FTNOIR_TRACKER_PT_DIALOG_H
  #define FTNOIR_TRACKER_PT_DIALOG_H
 -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h"
 +#include "ftnoir_tracker_base/ftnoir_tracker_base.h"
  #include "ftnoir_tracker_pt_settings.h"
  #include "ftnoir_tracker_pt.h"
 -#include "ui_FTNoIR_PT_Controls.h"
 +#include "ui_ftnoir_pt_controls.h"
  #include "trans_calib.h"
  #include <QTimer>
 @@ -99,4 +99,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 7f58d77d..22c4a33d 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_dll.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_dll.cpp @@ -6,8 +6,8 @@   */
  #include "ftnoir_tracker_pt_dll.h"
 -
  #include <QIcon>
 +#include "facetracknoir/global-settings.h"
  //-----------------------------------------------------------------------------
  void TrackerDll::getFullName(QString *strToBeFilled)
 @@ -27,14 +27,14 @@ void TrackerDll::getDescription(QString *strToBeFilled)  void TrackerDll::getIcon(QIcon *icon)
  {
 -	*icon = QIcon(":/Resources/icon.ico");
 +    *icon = QIcon(":/resources/icon.png");
  }
  //-----------------------------------------------------------------------------
 -#pragma comment(linker, "/export:GetTrackerDll=_GetTrackerDll@0")
 +//#pragma comment(linker, "/export:GetTrackerDll=_GetTrackerDll@0")
 -FTNOIR_TRACKER_BASE_EXPORT ITrackerDllPtr __stdcall GetTrackerDll()
 +extern "C" FTNOIR_TRACKER_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata()
  {
  	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..f684c55b 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_dll.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_dll.h @@ -5,10 +5,11 @@   * copyright notice and this permission notice appear in all copies.
   */
 -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h"
 +#include "ftnoir_tracker_base/ftnoir_tracker_base.h"
 +#include "facetracknoir/global-settings.h"
  //-----------------------------------------------------------------------------
 -class TrackerDll : public ITrackerDll
 +class TrackerDll : public Metadata
  {
  	// ITrackerDll interface
  	void Initialize() {}
 @@ -16,4 +17,4 @@ class TrackerDll : public ITrackerDll  	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 4aa1a658..b6e9ad3a 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -11,6 +11,14 @@  using namespace cv;
  using namespace std;
 +struct BlobInfo
 +{
 +    BlobInfo() : m00(0), m10(0), m01(0) {}
 +    long m00;
 +    long m10;
 +    long m01;
 +};
 +
  // ----------------------------------------------------------------------------
  const vector<Vec2f>& PointExtractor::extract_points(Mat frame, float dt, bool draw_output)
  {
 @@ -39,13 +47,6 @@ const vector<Vec2f>& PointExtractor::extract_points(Mat frame, float dt, bool dr  	// find connected components...
  	// extract blobs with floodfill
 -	struct BlobInfo
 -	{
 -		BlobInfo() : m00(0), m10(0), m01(0) {}
 -		long m00;
 -		long m10;
 -		long m01;
 -	};
  	vector<BlobInfo> blobs;
      int blob_count = 1;
 diff --git a/ftnoir_tracker_pt/point_tracker.cpp b/ftnoir_tracker_pt/point_tracker.cpp index d617de19..c08d6d83 100644 --- a/ftnoir_tracker_pt/point_tracker.cpp +++ b/ftnoir_tracker_pt/point_tracker.cpp @@ -14,7 +14,6 @@  #include <QDebug>
  using namespace cv;
 -using namespace boost;
  using namespace std;
  const float PI = 3.14159265358979323846f;
 @@ -68,26 +67,27 @@ PointModel::PointModel(Vec3f M01, Vec3f M02)  	get_d_order(points, d_order);
  }
 +static bool d_vals_sort(const pair<float,int> a, const pair<float,int> b)
 +{
 +    return a.first < b.first;
 +}
 +
  void PointModel::get_d_order(const std::vector<cv::Vec2f>& points, int d_order[]) const
  {
  	// get sort indices with respect to d scalar product
  	vector< pair<float,int> > d_vals;
 -	for (int i = 0; i<points.size(); ++i)
 +    for (int i = 0; i<(int)points.size(); ++i)
  		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);
 +    sort(d_vals.begin(), d_vals.end(), d_vals_sort);
 -	for (int i = 0; i<points.size(); ++i)
 +    for (int i = 0; i<(int)points.size(); ++i)
  		d_order[i] = d_vals[i].second;
  }
  // ----------------------------------------------------------------------------
 -PointTracker::PointTracker() : init_phase(true), dt_valid(0), dt_reset(1), v_t(0,0,0), v_r(0,0,0), dynamic_pose_resolution(true)
 +PointTracker::PointTracker() : dynamic_pose_resolution(true), dt_reset(1), init_phase(true), dt_valid(0), v_t(0,0,0), v_r(0,0,0)
  {
  	X_CM.t[2] = 1000;	// default position: 1 m away from cam;
  }
 @@ -120,7 +120,7 @@ bool PointTracker::track(const vector<Vec2f>& points, float f, float dt)  	}
  	// if there is a pointtracking problem, reset the velocities
 -	if (!point_model || points.size() != PointModel::N_POINTS) 
 +    if (!point_model.get() || (int) points.size() != PointModel::N_POINTS)
  	{
  		//qDebug()<<"Wrong number of points!";
  		reset_velocities();
 @@ -141,7 +141,7 @@ bool PointTracker::track(const vector<Vec2f>& points, float f, float dt)  		return false;
  	}
 -	int n_iter = POSIT(f);
 +    (void) POSIT(f);
  	//qDebug()<<"Number of POSIT iterations: "<<n_iter;
  	if (!init_phase)
 diff --git a/ftnoir_tracker_pt/point_tracker.h b/ftnoir_tracker_pt/point_tracker.h index 21baad19..7eee580d 100644 --- a/ftnoir_tracker_pt/point_tracker.h +++ b/ftnoir_tracker_pt/point_tracker.h @@ -8,8 +8,8 @@  #ifndef POINTTRACKER_H
  #define POINTTRACKER_H
 +#include <memory>
  #include <opencv2/opencv.hpp>
 -#include <boost/shared_ptr.hpp>
  #include <list>
  // ----------------------------------------------------------------------------
 @@ -76,7 +76,7 @@ public:  	// f : (focal length)/(sensor width)
  	// dt : time since last call
  	bool track(const std::vector<cv::Vec2f>& points, float f, float dt);
 -	boost::shared_ptr<PointModel> point_model;
 +	std::auto_ptr<PointModel> point_model;
  	bool dynamic_pose_resolution;
  	float dt_reset;
 diff --git a/ftnoir_tracker_pt/timer.cpp b/ftnoir_tracker_pt/timer.cpp index 363b5b09..9e6ca8b8 100644 --- a/ftnoir_tracker_pt/timer.cpp +++ b/ftnoir_tracker_pt/timer.cpp @@ -55,8 +55,7 @@ double Timer::elapsed()      startTime = startCount.QuadPart * (1e3 / frequency.QuadPart);
      endTime = endCount.QuadPart * (1e3 / frequency.QuadPart);
  #else
 -    if(!stopped)
 -        gettimeofday(&endCount, NULL);
 +	(void) gettimeofday(&endCount, NULL);
      startTime = (startCount.tv_sec * 1e3) + startCount.tv_usec;
      endTime = (endCount.tv_sec * 1e3) + endCount.tv_usec;
 diff --git a/ftnoir_tracker_pt/video_widget.cpp b/ftnoir_tracker_pt/video_widget.cpp index c2b41da1..c297c455 100644 --- a/ftnoir_tracker_pt/video_widget.cpp +++ b/ftnoir_tracker_pt/video_widget.cpp @@ -3,8 +3,6 @@   * Permission to use, copy, modify, and/or distribute this software for any
   * purpose with or without fee is hereby granted, provided that the above
   * copyright notice and this permission notice appear in all copies.
 - *
 - * 20130312, WVR: Add 7 lines to resizeGL after resize_frame. This should lower CPU-load.
   */
  #include "video_widget.h"
 @@ -13,7 +11,6 @@  using namespace cv;
  using namespace std;
 -using namespace boost;
  // ----------------------------------------------------------------------------
  void VideoWidget::initializeGL()
 @@ -31,21 +28,20 @@ void VideoWidget::resizeGL(int w, int h)  	glLoadIdentity();
  	glOrtho(0, w, 0, h, -1, 1);
  	resize_frame();
 -	glDisable(GL_DEPTH_TEST);
 -	glBegin(GL_QUADS);
 -	glVertex2f(0,0);
 -	glVertex2f(1,0);
 -	glVertex2f(1,1);
 -	glVertex2f(0,1);
 -	glEnd(); 
 +    glDisable(GL_DEPTH_TEST);
 +    glBegin(GL_QUADS);
 +    glVertex2f(0,0);
 +    glVertex2f(1,0);
 +    glVertex2f(1,1);
 +    glVertex2f(0,1);
 +    glEnd();
  }
  void VideoWidget::paintGL()
  {
 -	glClear(GL_COLOR_BUFFER_BIT);
 -	if (!resized_qframe.isNull())
 -	{
 -		glDrawPixels(resized_qframe.width(), resized_qframe.height(), GL_RGBA, GL_UNSIGNED_BYTE, resized_qframe.bits());
 +    QMutexLocker lck(&mtx);
 +    if (resized_qframe.size() == size() || (resized_qframe.width() <= width() && resized_qframe.height() <= height())) {
 +        glDrawPixels(resized_qframe.width(), resized_qframe.height(), GL_RGB, GL_UNSIGNED_BYTE, resized_qframe.bits());
  		const int crosshair_radius = 10;
  		const int crosshair_thickness = 1;
 @@ -69,30 +65,44 @@ void VideoWidget::paintGL()  			glVertex2i(x, y+crosshair_radius);
  			glEnd();
  		}
 -	}
 -	glFlush();
 +
 +    } else {
 +        glClear(GL_DEPTH_BUFFER_BIT);
 +    }
 +    glFlush();
  }
  void VideoWidget::resize_frame()
  {
 -	if (!qframe.isNull())
 -		resized_qframe = qframe.scaled(this->size(), Qt::KeepAspectRatio);
 +    QMutexLocker lck(&mtx);
 +#ifdef _WIN32
 +    if (qframe.size() == size() || (qframe.width() <= width() && qframe.height() <= height()))
 +        resized_qframe = qframe.mirrored();
 +    else
 +        resized_qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation).mirrored();
 +#else
 +    if (qframe.size() == size() || (qframe.width() <= width() && qframe.height() <= height()))
 +        resized_qframe = qframe.copy();
 +    else
 +        resized_qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
 +#endif
  }
 +void VideoWidget::update()
 +{
 +    updateGL();
 +}
 -void VideoWidget::update(Mat frame, shared_ptr< vector<Vec2f> > points)
 +void VideoWidget::update_image(Mat frame, std::auto_ptr< vector<Vec2f> > points)
  {
  	this->frame = frame;
  	this->points = points;
 -	// convert to QImage
 +	// convert to QImage 
  	if (frame.channels() == 3)
 -		qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.step, QImage::Format_RGB888).rgbSwapped();
 +		qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.cols * 3, QImage::Format_RGB888).rgbSwapped();
  	else if (frame.channels() == 1)
 -		qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.step, QImage::Format_Indexed8);
 -	qframe = QGLWidget::convertToGLFormat(qframe);
 -
 +		qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.cols, QImage::Format_Indexed8);
  	resize_frame();
 -	updateGL();
  }
 diff --git a/ftnoir_tracker_pt/video_widget.h b/ftnoir_tracker_pt/video_widget.h index f49fef18..2425603b 100644 --- a/ftnoir_tracker_pt/video_widget.h +++ b/ftnoir_tracker_pt/video_widget.h @@ -11,7 +11,10 @@  #include <QGLWidget>
  #include <QTime>
  #include <opencv2/opencv.hpp>
 -#include <boost/shared_ptr.hpp>
 +#include <memory>
 +#include <QWidget>
 +#include <QMutex>
 +#include <QMutexLocker>
  // ----------------------------------------------------------------------------
  class VideoWidget : public QGLWidget
 @@ -19,13 +22,18 @@ class VideoWidget : public QGLWidget  	Q_OBJECT
  public:
 -	VideoWidget(QWidget *parent) : QGLWidget(parent) {}
 +    VideoWidget(QWidget *parent) : QGLWidget(parent) {
 +#if !defined(_WIN32)
 +        setAttribute(Qt::WA_NativeWindow, true);
 +#endif
 +	}
  	void initializeGL();
  	void resizeGL(int w, int h);
  	void paintGL();
 -	void update(cv::Mat frame, boost::shared_ptr< std::vector<cv::Vec2f> > points);
 +    void update_image(cv::Mat frame, std::auto_ptr< std::vector<cv::Vec2f> > points);
 +    void update();
  private:
  	void resize_frame();
 @@ -34,7 +42,8 @@ private:  	QImage qframe;
  	QImage resized_qframe;
 -	boost::shared_ptr< std::vector<cv::Vec2f> > points;
 +    std::auto_ptr< std::vector<cv::Vec2f> > points;
 +    QMutex mtx;
  };
  #endif // VIDEOWIDGET_H
  | 
