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
27#include <thread>
28
30
32
33namespace visionx
34{
35
36 void
38 {
39 usingProxy(getProperty<std::string>("OLPName").getValue());
40 usingProxy(getProperty<std::string>("OLPObserverName").getValue());
41 usingProxy(getProperty<std::string>("ImageProviderName").getValue());
42 usingProxy(getProperty<std::string>("KinematicUnitName").getValue());
43 }
44
45 void
46 evaluateOLP(OLPEvaluation* p, bool testRecognition)
47 {
48 usleep(500000);
49
50 armarx::NameControlModeMap controlMode;
51 controlMode["Neck_1_Pitch"] = armarx::ePositionControl;
52 controlMode["Cameras"] = armarx::ePositionControl;
53 p->kinematicUnitProxy->switchControlMode(controlMode);
54 armarx::NameValueMap jointValues;
55 jointValues["Neck_1_Pitch"] = 0.3;
56 jointValues["Cameras"] = -0.3;
57 p->kinematicUnitProxy->setJointAngles(jointValues);
58
59 std::vector<std::string> imageFilePathsLeft, imageFilePathsRight;
60
61 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/01-Cheez-It/snapshot_left_0000.bmp");
62 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/01-Cheez-It/snapshot_right_0000.bmp");
63 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/06-Master-Chef/snapshot_left_0000.bmp");
64 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/06-Master-Chef/snapshot_right_0000.bmp");
65 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/08a-Pringles-standing/snapshot_left_0000.bmp");
66 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/08a-Pringles-standing/snapshot_right_0000.bmp");
67 imageFilePathsLeft.push_back(
68 "/homes/staff/schieben/datalog/YCB/Head/09-Frenchs-Mustard/snapshot_left_0000.bmp");
69 imageFilePathsRight.push_back(
70 "/homes/staff/schieben/datalog/YCB/Head/09-Frenchs-Mustard/snapshot_right_0000.bmp");
71 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/11-Banana/snapshot_left_0000.bmp");
72 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/11-Banana/snapshot_right_0000.bmp");
73
74 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/14-Lemon/snapshot_left_0000.bmp");
75 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/14-Lemon/snapshot_right_0000.bmp");
76 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/17-Orange/snapshot_left_0000.bmp");
77 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/17-Orange/snapshot_right_0000.bmp");
78 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/22-Pitcher/snapshot_left_0000.bmp");
79 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/22-Pitcher/snapshot_right_0000.bmp");
80 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/25-Bowl/snapshot_left_0000.bmp");
81 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/25-Bowl/snapshot_right_0000.bmp");
82 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/31-Mug/snapshot_left_0000.bmp");
83 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/31-Mug/snapshot_right_0000.bmp");
84
85 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/36-Marker/snapshot_left_0000.bmp");
86 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/36-Marker/snapshot_right_0000.bmp");
87 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/39-Padlock/snapshot_left_0000.bmp");
88 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/39-Padlock/snapshot_right_0000.bmp");
89 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/42-Screwdriver/snapshot_left_0000.bmp");
90 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/42-Screwdriver/snapshot_right_0000.bmp");
91 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/46-Clamp/snapshot_left_0000.bmp"); //<-----
92 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/46-Clamp/snapshot_right_0000.bmp"); //<-----
93 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/53-Mini-Soccer-Ball/snapshot_left_0000.bmp");
94 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/53-Mini-Soccer-Ball/snapshot_right_0000.bmp");
95
96 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/55-Tennis-Ball/snapshot_left_0000.bmp"); //<-----
97 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/55-Tennis-Ball/snapshot_right_0000.bmp"); //<-----
98 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/58-Marbles/snapshot_left_0000.bmp");
99 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/58-Marbles/snapshot_right_0000.bmp");
100 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/62-Cup-Lila/snapshot_left_0000.bmp");
101 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/62-Cup-Lila/snapshot_right_0000.bmp");
102 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/66-Rope/snapshot_left_0000.bmp");
103 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/66-Rope/snapshot_right_0000.bmp");
104 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/70-Colored-Wood-Blocks/snapshot_left_0000.bmp");
105 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/70-Colored-Wood-Blocks/snapshot_right_0000.bmp");
106
107 //imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/76-Timer/snapshot_left_0000.bmp");
108 //imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/76-Timer/snapshot_right_0000.bmp");
109
110
111 if (testRecognition)
112 {
113 ARMARX_IMPORTANT_S << "Starting recognition evaluation";
114
115 imageFilePathsLeft.clear();
116 imageFilePathsLeft.push_back(
117 "/homes/staff/schieben/datalog/YCB/Head/reco-test/img_pos/snapshot_left_0000.bmp");
118 imageFilePathsRight.push_back(
119 "/homes/staff/schieben/datalog/YCB/Head/reco-test/img_pos/snapshot_right_0000.bmp");
120
121 std::vector<std::string> objectNames;
122 objectNames.push_back("Orange");
123
124 for (size_t objectNumber = 0; objectNumber < imageFilePathsLeft.size(); objectNumber++)
125 {
126 p->imageProviderProxy->setImageFilePath(imageFilePathsLeft.at(objectNumber),
127 imageFilePathsRight.at(objectNumber));
128
129 usleep(5000000);
130
131 for (int i = 0; i < 6; i++)
132 {
133 p->olpProxy->recognizeObject(objectNames.at(objectNumber));
134
135 usleep(1000000);
136 ARMARX_INFO_S << "Loading image number " << i + 1;
137 p->imageProviderProxy->loadNextImage();
138 usleep(3000000);
139 }
140 }
141
142 ARMARX_IMPORTANT_S << "Finished recognition evaluation";
143 }
144 else
145 {
146 ARMARX_IMPORTANT_S << "Starting segmentation evaluation";
147
148 for (size_t objectNumber = 0; objectNumber < imageFilePathsLeft.size(); objectNumber++)
149 {
150 p->imageProviderProxy->setImageFilePath(imageFilePathsLeft.at(objectNumber),
151 imageFilePathsRight.at(objectNumber));
152
153 usleep(5000000);
154
155 int olpStatus = 0;
156
157 // create initial hypotheses
158
159 p->olpProxy->CreateInitialObjectHypotheses();
160
161 usleep(1000000);
162 p->imageProviderProxy->loadNextImage();
163 usleep(3000000);
164
165 do
166 {
167 usleep(100000);
168 olpStatus = p->olpObserverProxy
169 ->getDataField(new armarx::DataFieldIdentifierBase(
170 "ObjectLearningByPushingObserver",
171 "objectHypotheses",
172 "initialHypothesesCreated"))
173 ->getInt();
174 } while (olpStatus == 0);
175
176 if (olpStatus == -1)
177 {
179 << "Creation of initial hypotheses failed, skipping this object";
180 continue;
181 }
182
183 // only for LCCP evaluation
184 //ARMARX_IMPORTANT_S << "Skipping and continuing with next scene for LCCP evaluation";
185 //continue;
186
187
188 // validate initial hypotheses
189
190 p->olpProxy->ValidateInitialObjectHypotheses();
191
192 usleep(1000000);
193 p->imageProviderProxy->loadNextImage();
194 usleep(3000000);
195
196 do
197 {
198 usleep(100000);
199 olpStatus = p->olpObserverProxy
200 ->getDataField(new armarx::DataFieldIdentifierBase(
201 "ObjectLearningByPushingObserver",
202 "objectHypotheses",
203 "hypothesesValidated"))
204 ->getInt();
205 } while (olpStatus == 0);
206
207 if (olpStatus == -1)
208 {
210 << "Validation of initial hypotheses failed, skipping this object";
211 continue;
212 }
213
214
215 // revalidate hypotheses
216
217 for (int i = 2; i <= 5; i++)
218 {
219 ARMARX_INFO_S << "Loading image number " << i;
220
221 p->olpProxy->RevalidateConfirmedObjectHypotheses();
222
223 usleep(1000000);
224 p->imageProviderProxy->loadNextImage();
225 usleep(3000000);
226
227 do
228 {
229 usleep(100000);
230 olpStatus = p->olpObserverProxy
231 ->getDataField(new armarx::DataFieldIdentifierBase(
232 "ObjectLearningByPushingObserver",
233 "objectHypotheses",
234 "hypothesesValidated"))
235 ->getInt();
236 } while (olpStatus == 0);
237
238 if (olpStatus == -1)
239 {
240 ARMARX_WARNING_S << "Validation of hypotheses failed, skipping this object";
241 break;
242 }
243 }
244
245 ARMARX_IMPORTANT_S << "Finished segmentation of object " << objectNumber + 1
246 << " of " << imageFilePathsLeft.size();
247 }
248
249 ARMARX_IMPORTANT_S << "Finished segmenting all objects";
250 }
251 }
252
253 void
255 {
257 getProperty<std::string>("OLPName").getValue());
259 getProperty<std::string>("OLPObserverName").getValue());
261 getProperty<std::string>("ImageProviderName").getValue());
263 getProperty<std::string>("KinematicUnitName").getValue());
264 bool testRecognition = getProperty<bool>("TestRecognition").getValue();
265
266 std::thread t([=, this]() { evaluateOLP(this, testRecognition); });
267 t.detach();
268 }
269
270 void
274
275 void
279
287
288} // namespace visionx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Brief description of class OLPEvaluation.
void onInitComponent() override
ObjectLearningByPushingInterfacePrx olpProxy
ImageFileSequenceProviderInterfacePrx imageProviderProxy
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
static std::string GetDefaultName()
ObjectLearningByPushingListenerPrx olpObserverProxy
void onExitComponent() override
armarx::KinematicUnitInterfacePrx kinematicUnitProxy
#define ARMARX_INFO_S
Definition Logging.h:202
#define ARMARX_IMPORTANT_S
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:210
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.
void evaluateOLP(OLPEvaluation *p, bool testRecognition)