Go to the documentation of this file.00001
00002 #include <blort/Tracker/TrackerThread.h>
00003 #include <blort/Tracker/TextureTracker.h>
00004 #include <blort/GLWindow/GLWindow.h>
00005 #include <blort/Tracker/CameraThread.h>
00006 #include <stdexcept>
00007
00008 using namespace Tracking;
00009 using namespace std;
00010
00011 TrackerThread::TrackerThread()
00012 {
00013 m_mutex.Lock();
00014 m_quit = false;
00015 cmd = IDLE;
00016 m_mutex.Unlock();
00017 }
00018
00019 TrackerThread::~TrackerThread()
00020 {
00021 m_mutex.Lock();
00022 m_quit = true;
00023 m_mutex.Unlock();
00024
00025 m_evCmd.Set();
00026 m_evData.Set();
00027
00028 m_running.Wait();
00029 }
00030
00031 void TrackerThread::init(const Tracking::Tracker::Parameter ¶ms)
00032 {
00033 m_mutex.Lock();
00034 m_params = params;
00035 cmd = INIT;
00036 m_mutex.Unlock();
00037 m_evCmd.Set();
00038 m_evData.Wait(); m_evData.Reset();
00039 }
00040
00041 int TrackerThread::addModelFromFile(const char* ply_file, TomGine::tgPose& pose, std::string label, bool bfc)
00042 {
00043 int id;
00044 m_mutex.Lock();
00045 m_ply_file = std::string(ply_file);
00046 m_pose = pose;
00047 m_model_label = std::string(label);
00048 m_bfc = bfc;
00049 cmd = ADD_MODEL_FROM_FILE;
00050 m_mutex.Unlock();
00051
00052 m_evCmd.Set();
00053 m_evData.Wait(); m_evData.Reset();
00054
00055 m_mutex.Lock();
00056 id = m_model_id;
00057 m_mutex.Unlock();
00058
00059 return id;
00060 }
00061
00062 BOOL TrackerThread::OnTask()
00063 {
00064 m_running.Lock();
00065 unsigned w,h;
00066
00067 IplImage* image = 0;
00068
00069 blortGLWindow::GLWindow* window = 0;
00070 Tracking::Tracker* tracker = 0;
00071 CameraThread* camera = 0;
00072
00073 while(!m_quit)
00074 {
00075 switch(cmd)
00076 {
00077 case INIT:
00078 w = m_params.camPar.width;
00079 h = m_params.camPar.height;
00080 if(!camera){
00081 image = cvCreateImage( cvSize(w, h), 8, 3 );
00082 camera = new CameraThread(0, w, h);
00083 camera->SetThreadType(ThreadTypeIntervalDriven,0);
00084 }
00085 if(!window)
00086 window = new blortGLWindow::GLWindow(w, h, "Tracker");
00087 if(!tracker){
00088 tracker = new Tracking::TextureTracker();
00089 tracker->init(m_params);
00090 }
00091 m_mutex.Lock();
00092 m_evData.Set();
00093 cmd = IDLE;
00094 m_mutex.Unlock();
00095 break;
00096 case ADD_MODEL_FROM_FILE:
00097 if(tracker){
00098 m_model_id = tracker->addModelFromFile(m_ply_file.c_str(), m_pose, m_model_label.c_str(), m_bfc);
00099 m_mutex.Lock();
00100 m_evData.Set();
00101 cmd = TRACK;
00102 m_mutex.Unlock();
00103 }else{
00104 m_mutex.Lock();
00105 m_evData.Set();
00106 cmd = IDLE;
00107 m_mutex.Unlock();
00108 }
00109 break;
00110 case TRACK:
00111 if(tracker && camera && window && image){
00112 camera->GetImage(image);
00113 tracker->image_processing((unsigned char*)image->imageData);
00114 tracker->track();
00115 tracker->drawResult();
00116 tracker->drawCoordinates();
00117 window->Update();
00118 }
00119 break;
00120 case IDLE:
00121 default:
00122 m_evCmd.Wait(); m_evCmd.Reset();
00123 break;
00124 }
00125
00126 }
00127
00128 if(camera) delete(camera);
00129 if(tracker) delete(tracker);
00130 if(window) delete(window);
00131 if(image) cvReleaseImage(&image);
00132
00133 m_running.Unlock();
00134 return TRUE;
00135 }
00136
00137
00138
00139
blort
Author(s): Michael Zillich,
Thomas Mörwald,
Johann Prankl,
Andreas Richtsfeld,
Bence Magyar (ROS version)
autogenerated on Thu Jan 2 2014 11:38:26