Go to the documentation of this file.00001
00002 #include <blort/ThreadObject/RecognizerThread.h>
00003 #include <stdexcept>
00004 #include <opencv2/legacy/compat.hpp>
00005
00006 using namespace std;
00007
00008 CRecognizerThread::CRecognizerThread(const blortRecognizer::CameraParameter& params, std::string config_root)
00009 {
00010 m_mutex.Lock();
00011 m_quit = false;
00012 m_params = params;
00013 this->config_root = config_root;
00014 cmd = IDLE;
00015 m_image = cvCreateImage( cvSize(params.w, params.h), 8, 3 );
00016 m_mutex.Unlock();
00017
00018 }
00019
00020 CRecognizerThread::~CRecognizerThread()
00021 {
00022 m_mutex.Lock();
00023 m_quit = true;
00024 m_mutex.Unlock();
00025
00026 m_evCmd.Set();
00027 m_evData.Set();
00028
00029 m_running.Wait();
00030
00031 }
00032
00033 void CRecognizerThread::Recognize(IplImage* image, TomGine::tgPose& pose, float& conf)
00034 {
00035 m_mutex.Lock();
00036 cvCopyImage(image, m_image);
00037 m_pose = pose;
00038 cmd = RECOGNIZE;
00039 m_mutex.Unlock();
00040
00041 m_evCmd.Set();
00042 m_evData.Wait(); m_evData.Reset();
00043
00044 m_mutex.Lock();
00045 pose = m_pose;
00046 conf = m_conf;
00047 m_mutex.Unlock();
00048 }
00049
00050 void CRecognizerThread::LearnSifts(IplImage* image, TomGine::tgModel &model, TomGine::tgPose& pose)
00051 {
00052 m_mutex.Lock();
00053 cvCopyImage(image, m_image);
00054 m_pose = pose;
00055 m_model = model;
00056 cmd = LEARN;
00057 m_mutex.Unlock();
00058
00059 m_evCmd.Set();
00060 m_evData.Wait(); m_evData.Reset();
00061 }
00062
00063 void CRecognizerThread::LoadSiftModel(const std::string sift_file)
00064 {
00065 m_mutex.Lock();
00066 m_sift_file = string(sift_file);
00067 cmd = LOAD;
00068 m_mutex.Unlock();
00069
00070 m_evCmd.Set();
00071 m_evData.Wait(); m_evData.Reset();
00072 }
00073
00074 void CRecognizerThread::SaveSiftModel(const std::string sift_file)
00075 {
00076 m_mutex.Lock();
00077 m_sift_file = string(sift_file);
00078 cmd = SAVE;
00079 m_mutex.Unlock();
00080
00081 m_evCmd.Set();
00082 m_evData.Wait(); m_evData.Reset();
00083 }
00084
00085 void CRecognizerThread::GetSifts(std::vector<blortRecognizer::Siftex>& sl)
00086 {
00087 m_mutex.Lock();
00088 cmd = GETSIFT;
00089 m_mutex.Unlock();
00090
00091 m_evCmd.Set();
00092 m_evData.Wait(); m_evData.Reset();
00093
00094 m_mutex.Lock();
00095 sl = m_siftexlist;
00096 m_mutex.Unlock();
00097 }
00098
00099 void CRecognizerThread::GetLastSifts(std::vector<blortRecognizer::Siftex>& sl)
00100 {
00101 m_mutex.Lock();
00102 cmd = GETLASTSIFT;
00103 m_mutex.Unlock();
00104
00105 m_evCmd.Set();
00106 m_evData.Wait(); m_evData.Reset();
00107
00108 m_mutex.Lock();
00109 sl = m_lastsiftexlist;
00110 m_mutex.Unlock();
00111 }
00112
00113 BOOL CRecognizerThread::OnTask()
00114 {
00115 m_running.Lock();
00116
00117
00118 blortRecognizer::Recognizer3D m_recognizer(m_params, config_root, true);
00119
00120
00121 while(!m_quit)
00122 {
00123 switch(cmd)
00124 {
00125
00126 case RECOGNIZE:
00127 m_mutex.Lock();
00128 m_recognizer.recognize(m_image, m_pose, m_conf);
00129 result = m_recognizer.getImage();
00130 m_evData.Set();
00131 cmd = IDLE;
00132 m_mutex.Unlock();
00133 break;
00134
00135 case LEARN:
00136 m_mutex.Lock();
00137 m_recognizer.learnSifts(m_image, m_model, m_pose);
00138 m_evData.Set();
00139 cmd = IDLE;
00140 m_mutex.Unlock();
00141 break;
00142
00143 case LOAD:
00144 m_mutex.Lock();
00145 m_recognizer.loadModelFromFile(m_sift_file.c_str());
00146 m_evData.Set();
00147 cmd = IDLE;
00148 m_mutex.Unlock();
00149 break;
00150
00151 case SAVE:
00152 m_mutex.Lock();
00153 m_recognizer.saveModelToFile(m_sift_file.c_str());
00154 m_evData.Set();
00155 cmd = IDLE;
00156 m_mutex.Unlock();
00157 break;
00158
00159 case GETSIFT:
00160 m_mutex.Lock();
00161 m_recognizer.getSifts(m_siftexlist);
00162 m_evData.Set();
00163 cmd = IDLE;
00164 m_mutex.Unlock();
00165 break;
00166
00167 case GETLASTSIFT:
00168 m_mutex.Lock();
00169 m_recognizer.getLastSifts(m_lastsiftexlist);
00170 m_evData.Set();
00171 cmd = IDLE;
00172 m_mutex.Unlock();
00173 break;
00174
00175 case IDLE:
00176 default:
00177 m_evCmd.Wait(); m_evCmd.Reset();
00178 break;
00179 }
00180 }
00181
00182 m_running.Unlock();
00183 return TRUE;
00184 }
00185
00186
00187
00188
blort
Author(s): Michael Zillich,
Thomas Mörwald,
Johann Prankl,
Andreas Richtsfeld,
Bence Magyar (ROS version)
autogenerated on Thu Jan 2 2014 11:38:25