Changeset 233
- Timestamp:
- 11/16/2009 12:06:57 PM (10 years ago)
- Location:
- level2/competencies/FaceClassifier/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
level2/competencies/FaceClassifier/src/App.cpp
r207 r233 36 36 m_FaceNum(1), 37 37 m_Learn(true), 38 m_Idle(false), 38 39 frame(NULL), 39 40 frame_copy(NULL), … … 139 140 case 'c': m_FaceBank->Clear(); break; 140 141 } 141 142 vector<Rect> rects = m_FaceFinder.Find(camera,m_Learn);143 for(vector<Rect>::iterator i = rects.begin(); i!=rects.end(); i++ )144 {145 unsigned int ID=999;146 int imagenum=-1;147 float confidence=0;148 // get the face area as a sub image149 Image face = camera.SubImage(*i);150 142 151 //face.SubMean(); 152 //camera.Blit(face.Scale(w,h).RGB2GRAY(),100,100); 153 154 // pass it into the face bank 155 if (m_Learn) 156 { 157 confidence=m_FaceBank->Suggest(face,m_FaceNum); 158 ID=m_FaceNum; 159 } 160 else 161 { 162 confidence=m_FaceBank->Identify(face,ID,imagenum); 163 } 164 165 // if it's recognised the face (should really check the confidence) 166 if (ID!=999) 167 { 168 char s[32]; 169 map<int,string>::iterator d = m_DebugNames.find(ID); 170 if (d!=m_DebugNames.end()) 143 144 /////////////////////////////////// 145 // read from yarp 146 147 Bottle *b=m_CtrlPort.read(false); 148 if (b!=NULL) 149 { 150 if (b->get(0).asString()=="train") 151 { 152 m_FaceNum=b->get(1).asInt(); 153 m_Learn=true; 154 m_Idle=false; 155 } 156 if (b->get(0).asString()=="idle") 157 { 158 m_FaceNum=b->get(1).asInt(); 159 m_Idle=true; 160 } 161 else if (b->get(0).asString()=="clear") 162 { 163 m_FaceBank->Clear(); 164 } 165 else if (b->get(0).asString()=="detect") 166 { 167 m_Learn=false; 168 m_Idle=false; 169 } 170 else if (b->get(0).asString()=="load") 171 { 172 m_FaceBank->Load(b->get(1).asString().c_str()); 173 } 174 else if (b->get(0).asString()=="save") 175 { 176 m_FaceBank->Save(b->get(1).asString().c_str()); 177 } 178 else if (b->get(0).asString()=="errorthresh") 179 { 180 m_FaceBank->SetErrorThresh(b->get(1).asDouble()); 181 } 182 } 183 184 if (m_Idle) 185 { 186 // idling, so free up some cpu 187 #ifdef WIN32 188 Sleep(2000); 189 #else 190 usleep(200000); 191 #endif 192 } 193 else 194 { 195 vector<Rect> rects = m_FaceFinder.Find(camera,m_Learn); 196 for(vector<Rect>::iterator i = rects.begin(); i!=rects.end(); i++ ) 197 { 198 unsigned int ID=999; 199 int imagenum=-1; 200 float confidence=0; 201 // get the face area as a sub image 202 Image face = camera.SubImage(*i); 203 204 //face.SubMean(); 205 //camera.Blit(face.Scale(w,h).RGB2GRAY(),100,100); 206 207 // pass it into the face bank 208 if (m_Learn) 171 209 { 172 sprintf(s,"%s",d->second.c_str()); 210 confidence=m_FaceBank->Suggest(face,m_FaceNum); 211 ID=m_FaceNum; 173 212 } 174 213 else 214 { 215 confidence=m_FaceBank->Identify(face,ID,imagenum); 216 } 217 218 // if it's recognised the face (should really check the confidence) 219 if (ID!=999) 175 220 { 176 sprintf(s,"%d",ID); 221 char s[32]; 222 map<int,string>::iterator d = m_DebugNames.find(ID); 223 if (d!=m_DebugNames.end()) 224 { 225 sprintf(s,"%s",d->second.c_str()); 226 } 227 else 228 { 229 sprintf(s,"%d",ID); 230 } 231 232 cvPutText(camera.m_Image, s, cvPoint(i->x,i->y+i->h-5), &m_LargeFont, colors[ID]); 233 234 if (!m_Learn) 235 { 236 m_SceneState.AddPresent(ID, SceneState::User(confidence)); 237 } 177 238 } 178 179 cvPutText(camera.m_Image, s, cvPoint(i->x,i->y+i->h-5), &m_LargeFont, colors[ID]); 180 181 if (!m_Learn) 239 240 cvRectangle(camera.m_Image, cvPoint(i->x,i->y), cvPoint(i->x+i->w,i->y+i->h), colors[0]); 241 } 242 243 char info[256]; 244 if (m_Learn) 245 { 246 snprintf(info,256,"Learning user :%d",m_FaceNum); 247 248 PCAClassifier *c = static_cast<PCAClassifier*>(m_FaceBank->GetClassifier()); 249 if (c->GroupExists(m_FaceNum)) 182 250 { 183 m_SceneState.AddPresent(ID, SceneState::User(confidence)); 251 Vector<float> p = c->GetGroupMean(m_FaceNum); 252 Vector<float> r = c->GetPCA().Synth(p); 253 camera.Blit(Image(w,h,1,r),0,100); 184 254 } 185 255 } 186 187 cvRectangle(camera.m_Image, cvPoint(i->x,i->y), cvPoint(i->x+i->w,i->y+i->h), colors[0]); 188 } 189 190 char info[256]; 191 if (m_Learn) 192 { 193 snprintf(info,256,"Learning user :%d",m_FaceNum); 194 195 PCAClassifier *c = static_cast<PCAClassifier*>(m_FaceBank->GetClassifier()); 196 if (c->GroupExists(m_FaceNum)) 197 { 198 Vector<float> p = c->GetGroupMean(m_FaceNum); 199 Vector<float> r = c->GetPCA().Synth(p); 200 camera.Blit(Image(w,h,1,r),0,100); 201 } 202 } 203 else 204 { 205 snprintf(info,256,"Detecting users"); 206 } 207 208 cvPutText(camera.m_Image, info, cvPoint(10,10), &m_Font, colors[0]); 209 210 m_SceneState.Update(); 211 256 else 257 { 258 snprintf(info,256,"Detecting users"); 259 } 260 261 cvPutText(camera.m_Image, info, cvPoint(10,10), &m_Font, colors[0]); 262 263 m_SceneState.Update(); 264 } 265 212 266 } 213 267 -
level2/competencies/FaceClassifier/src/App.h
r113 r233 49 49 int m_FaceNum; 50 50 bool m_Learn; 51 bool m_Idle; 51 52 CvFont m_Font; 52 53 CvFont m_LargeFont; -
level2/competencies/FaceClassifier/src/SceneState.cpp
r94 r233 23 23 { 24 24 cerr<<"connecting to yarp..."<<endl; 25 m_YarpPort.open("/face ident");25 m_YarpPort.open("/faceclassifier"); 26 26 } 27 27
Note: See TracChangeset
for help on using the changeset viewer.