OLPEvaluation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX::ArmarXObjects::OLPEvaluation
19  * @author David ( david dot schiebener at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "OLPEvaluation.h"
26 
28 
29 #include <thread>
30 
31 
32 namespace visionx
33 {
34 
36  {
37  usingProxy(getProperty<std::string>("OLPName").getValue());
38  usingProxy(getProperty<std::string>("OLPObserverName").getValue());
39  usingProxy(getProperty<std::string>("ImageProviderName").getValue());
40  usingProxy(getProperty<std::string>("KinematicUnitName").getValue());
41  }
42 
43 
44  void evaluateOLP(OLPEvaluation* p, bool testRecognition)
45  {
46  usleep(500000);
47 
48  armarx::NameControlModeMap controlMode;
49  controlMode["Neck_1_Pitch"] = armarx::ePositionControl;
50  controlMode["Cameras"] = armarx::ePositionControl;
51  p->kinematicUnitProxy->switchControlMode(controlMode);
52  armarx::NameValueMap jointValues;
53  jointValues["Neck_1_Pitch"] = 0.3;
54  jointValues["Cameras"] = -0.3;
55  p->kinematicUnitProxy->setJointAngles(jointValues);
56 
57  std::vector<std::string> imageFilePathsLeft, imageFilePathsRight;
58 
59  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/01-Cheez-It/snapshot_left_0000.bmp");
60  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/01-Cheez-It/snapshot_right_0000.bmp");
61  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/06-Master-Chef/snapshot_left_0000.bmp");
62  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/06-Master-Chef/snapshot_right_0000.bmp");
63  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/08a-Pringles-standing/snapshot_left_0000.bmp");
64  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/08a-Pringles-standing/snapshot_right_0000.bmp");
65  imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/09-Frenchs-Mustard/snapshot_left_0000.bmp");
66  imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/09-Frenchs-Mustard/snapshot_right_0000.bmp");
67  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/11-Banana/snapshot_left_0000.bmp");
68  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/11-Banana/snapshot_right_0000.bmp");
69 
70  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/14-Lemon/snapshot_left_0000.bmp");
71  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/14-Lemon/snapshot_right_0000.bmp");
72  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/17-Orange/snapshot_left_0000.bmp");
73  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/17-Orange/snapshot_right_0000.bmp");
74  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/22-Pitcher/snapshot_left_0000.bmp");
75  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/22-Pitcher/snapshot_right_0000.bmp");
76  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/25-Bowl/snapshot_left_0000.bmp");
77  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/25-Bowl/snapshot_right_0000.bmp");
78  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/31-Mug/snapshot_left_0000.bmp");
79  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/31-Mug/snapshot_right_0000.bmp");
80 
81  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/36-Marker/snapshot_left_0000.bmp");
82  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/36-Marker/snapshot_right_0000.bmp");
83  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/39-Padlock/snapshot_left_0000.bmp");
84  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/39-Padlock/snapshot_right_0000.bmp");
85  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/42-Screwdriver/snapshot_left_0000.bmp");
86  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/42-Screwdriver/snapshot_right_0000.bmp");
87  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/46-Clamp/snapshot_left_0000.bmp"); //<-----
88  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/46-Clamp/snapshot_right_0000.bmp"); //<-----
89  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/53-Mini-Soccer-Ball/snapshot_left_0000.bmp");
90  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/53-Mini-Soccer-Ball/snapshot_right_0000.bmp");
91 
92  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/55-Tennis-Ball/snapshot_left_0000.bmp"); //<-----
93  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/55-Tennis-Ball/snapshot_right_0000.bmp"); //<-----
94  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/58-Marbles/snapshot_left_0000.bmp");
95  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/58-Marbles/snapshot_right_0000.bmp");
96  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/62-Cup-Lila/snapshot_left_0000.bmp");
97  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/62-Cup-Lila/snapshot_right_0000.bmp");
98  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/66-Rope/snapshot_left_0000.bmp");
99  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/66-Rope/snapshot_right_0000.bmp");
100  // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/70-Colored-Wood-Blocks/snapshot_left_0000.bmp");
101  // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/70-Colored-Wood-Blocks/snapshot_right_0000.bmp");
102 
103  //imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/76-Timer/snapshot_left_0000.bmp");
104  //imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/76-Timer/snapshot_right_0000.bmp");
105 
106 
107 
108  if (testRecognition)
109  {
110  ARMARX_IMPORTANT_S << "Starting recognition evaluation";
111 
112  imageFilePathsLeft.clear();
113  imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/reco-test/img_pos/snapshot_left_0000.bmp");
114  imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/reco-test/img_pos/snapshot_right_0000.bmp");
115 
116  std::vector<std::string> objectNames;
117  objectNames.push_back("Orange");
118 
119  for (size_t objectNumber = 0; objectNumber < imageFilePathsLeft.size(); objectNumber++)
120  {
121  p->imageProviderProxy->setImageFilePath(imageFilePathsLeft.at(objectNumber), imageFilePathsRight.at(objectNumber));
122 
123  usleep(5000000);
124 
125  for (int i = 0; i < 6; i++)
126  {
127  p->olpProxy->recognizeObject(objectNames.at(objectNumber));
128 
129  usleep(1000000);
130  ARMARX_INFO_S << "Loading image number " << i + 1;
131  p->imageProviderProxy->loadNextImage();
132  usleep(3000000);
133  }
134  }
135 
136  ARMARX_IMPORTANT_S << "Finished recognition evaluation";
137  }
138  else
139  {
140  ARMARX_IMPORTANT_S << "Starting segmentation evaluation";
141 
142  for (size_t objectNumber = 0; objectNumber < imageFilePathsLeft.size(); objectNumber++)
143  {
144  p->imageProviderProxy->setImageFilePath(imageFilePathsLeft.at(objectNumber), imageFilePathsRight.at(objectNumber));
145 
146  usleep(5000000);
147 
148  int olpStatus = 0;
149 
150  // create initial hypotheses
151 
152  p->olpProxy->CreateInitialObjectHypotheses();
153 
154  usleep(1000000);
155  p->imageProviderProxy->loadNextImage();
156  usleep(3000000);
157 
158  do
159  {
160  usleep(100000);
161  olpStatus = p->olpObserverProxy->getDataField(new armarx::DataFieldIdentifierBase("ObjectLearningByPushingObserver", "objectHypotheses", "initialHypothesesCreated"))->getInt();
162  }
163  while (olpStatus == 0);
164 
165  if (olpStatus == -1)
166  {
167  ARMARX_WARNING_S << "Creation of initial hypotheses failed, skipping this object";
168  continue;
169  }
170 
171  // only for LCCP evaluation
172  //ARMARX_IMPORTANT_S << "Skipping and continuing with next scene for LCCP evaluation";
173  //continue;
174 
175 
176  // validate initial hypotheses
177 
178  p->olpProxy->ValidateInitialObjectHypotheses();
179 
180  usleep(1000000);
181  p->imageProviderProxy->loadNextImage();
182  usleep(3000000);
183 
184  do
185  {
186  usleep(100000);
187  olpStatus = p->olpObserverProxy->getDataField(new armarx::DataFieldIdentifierBase("ObjectLearningByPushingObserver", "objectHypotheses", "hypothesesValidated"))->getInt();
188  }
189  while (olpStatus == 0);
190 
191  if (olpStatus == -1)
192  {
193  ARMARX_WARNING_S << "Validation of initial hypotheses failed, skipping this object";
194  continue;
195  }
196 
197 
198  // revalidate hypotheses
199 
200  for (int i = 2; i <= 5; i++)
201  {
202  ARMARX_INFO_S << "Loading image number " << i;
203 
204  p->olpProxy->RevalidateConfirmedObjectHypotheses();
205 
206  usleep(1000000);
207  p->imageProviderProxy->loadNextImage();
208  usleep(3000000);
209 
210  do
211  {
212  usleep(100000);
213  olpStatus = p->olpObserverProxy->getDataField(new armarx::DataFieldIdentifierBase("ObjectLearningByPushingObserver", "objectHypotheses", "hypothesesValidated"))->getInt();
214  }
215  while (olpStatus == 0);
216 
217  if (olpStatus == -1)
218  {
219  ARMARX_WARNING_S << "Validation of hypotheses failed, skipping this object";
220  break;
221  }
222  }
223 
224  ARMARX_IMPORTANT_S << "Finished segmentation of object " << objectNumber + 1 << " of " << imageFilePathsLeft.size();
225  }
226 
227  ARMARX_IMPORTANT_S << "Finished segmenting all objects";
228  }
229  }
230 
231 
233  {
234  olpProxy = getProxy<ObjectLearningByPushingInterfacePrx>(getProperty<std::string>("OLPName").getValue());
235  olpObserverProxy = getProxy<ObjectLearningByPushingListenerPrx>(getProperty<std::string>("OLPObserverName").getValue());
236  imageProviderProxy = getProxy<ImageFileSequenceProviderInterfacePrx>(getProperty<std::string>("ImageProviderName").getValue());
237  kinematicUnitProxy = getProxy<armarx::KinematicUnitInterfacePrx>(getProperty<std::string>("KinematicUnitName").getValue());
238  bool testRecognition = getProperty<bool>("TestRecognition").getValue();
239 
240  std::thread t([ =, this ]()
241  {
242  evaluateOLP(this, testRecognition);
243  });
244  t.detach();
245  }
246 
247 
249  {
250 
251  }
252 
253 
255  {
256 
257  }
258 
259 
261  {
263  }
264 }
visionx::evaluateOLP
void evaluateOLP(OLPEvaluation *p, bool testRecognition)
Definition: OLPEvaluation.cpp:44
ARMARX_IMPORTANT_S
#define ARMARX_IMPORTANT_S
Definition: Logging.h:203
visionx::OLPEvaluation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: OLPEvaluation.cpp:260
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::OLPEvaluation::imageProviderProxy
ImageFileSequenceProviderInterfacePrx imageProviderProxy
Definition: OLPEvaluation.h:109
visionx::OLPEvaluation::onExitComponent
void onExitComponent() override
Definition: OLPEvaluation.cpp:254
visionx::OLPEvaluation::onDisconnectComponent
void onDisconnectComponent() override
Definition: OLPEvaluation.cpp:248
visionx::OLPEvaluation::kinematicUnitProxy
armarx::KinematicUnitInterfacePrx kinematicUnitProxy
Definition: OLPEvaluation.h:110
visionx::OLPEvaluationPropertyDefinitions
Definition: OLPEvaluation.h:42
visionx::OLPEvaluation::olpObserverProxy
ObjectLearningByPushingListenerPrx olpObserverProxy
Definition: OLPEvaluation.h:108
ObserverObjectFactories.h
OLPEvaluation.h
visionx::OLPEvaluation::onConnectComponent
void onConnectComponent() override
Definition: OLPEvaluation.cpp:232
visionx::OLPEvaluation
Brief description of class OLPEvaluation.
Definition: OLPEvaluation.h:68
visionx::OLPEvaluation::olpProxy
ObjectLearningByPushingInterfacePrx olpProxy
Definition: OLPEvaluation.h:107
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:91
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
IceUtil::Handle< class PropertyDefinitionContainer >
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
visionx::OLPEvaluation::onInitComponent
void onInitComponent() override
Definition: OLPEvaluation.cpp:35