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
31namespace visionx
32{
33
34 void
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 void
44 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(
66 "/homes/staff/schieben/datalog/YCB/Head/09-Frenchs-Mustard/snapshot_left_0000.bmp");
67 imageFilePathsRight.push_back(
68 "/homes/staff/schieben/datalog/YCB/Head/09-Frenchs-Mustard/snapshot_right_0000.bmp");
69 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/11-Banana/snapshot_left_0000.bmp");
70 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/11-Banana/snapshot_right_0000.bmp");
71
72 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/14-Lemon/snapshot_left_0000.bmp");
73 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/14-Lemon/snapshot_right_0000.bmp");
74 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/17-Orange/snapshot_left_0000.bmp");
75 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/17-Orange/snapshot_right_0000.bmp");
76 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/22-Pitcher/snapshot_left_0000.bmp");
77 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/22-Pitcher/snapshot_right_0000.bmp");
78 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/25-Bowl/snapshot_left_0000.bmp");
79 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/25-Bowl/snapshot_right_0000.bmp");
80 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/31-Mug/snapshot_left_0000.bmp");
81 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/31-Mug/snapshot_right_0000.bmp");
82
83 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/36-Marker/snapshot_left_0000.bmp");
84 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/36-Marker/snapshot_right_0000.bmp");
85 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/39-Padlock/snapshot_left_0000.bmp");
86 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/39-Padlock/snapshot_right_0000.bmp");
87 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/42-Screwdriver/snapshot_left_0000.bmp");
88 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/42-Screwdriver/snapshot_right_0000.bmp");
89 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/46-Clamp/snapshot_left_0000.bmp"); //<-----
90 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/46-Clamp/snapshot_right_0000.bmp"); //<-----
91 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/53-Mini-Soccer-Ball/snapshot_left_0000.bmp");
92 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/53-Mini-Soccer-Ball/snapshot_right_0000.bmp");
93
94 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/55-Tennis-Ball/snapshot_left_0000.bmp"); //<-----
95 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/55-Tennis-Ball/snapshot_right_0000.bmp"); //<-----
96 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/58-Marbles/snapshot_left_0000.bmp");
97 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/58-Marbles/snapshot_right_0000.bmp");
98 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/62-Cup-Lila/snapshot_left_0000.bmp");
99 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/62-Cup-Lila/snapshot_right_0000.bmp");
100 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/66-Rope/snapshot_left_0000.bmp");
101 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/66-Rope/snapshot_right_0000.bmp");
102 // imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/70-Colored-Wood-Blocks/snapshot_left_0000.bmp");
103 // imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/70-Colored-Wood-Blocks/snapshot_right_0000.bmp");
104
105 //imageFilePathsLeft.push_back("/homes/staff/schieben/datalog/YCB/Head/76-Timer/snapshot_left_0000.bmp");
106 //imageFilePathsRight.push_back("/homes/staff/schieben/datalog/YCB/Head/76-Timer/snapshot_right_0000.bmp");
107
108
109 if (testRecognition)
110 {
111 ARMARX_IMPORTANT_S << "Starting recognition evaluation";
112
113 imageFilePathsLeft.clear();
114 imageFilePathsLeft.push_back(
115 "/homes/staff/schieben/datalog/YCB/Head/reco-test/img_pos/snapshot_left_0000.bmp");
116 imageFilePathsRight.push_back(
117 "/homes/staff/schieben/datalog/YCB/Head/reco-test/img_pos/snapshot_right_0000.bmp");
118
119 std::vector<std::string> objectNames;
120 objectNames.push_back("Orange");
121
122 for (size_t objectNumber = 0; objectNumber < imageFilePathsLeft.size(); objectNumber++)
123 {
124 p->imageProviderProxy->setImageFilePath(imageFilePathsLeft.at(objectNumber),
125 imageFilePathsRight.at(objectNumber));
126
127 usleep(5000000);
128
129 for (int i = 0; i < 6; i++)
130 {
131 p->olpProxy->recognizeObject(objectNames.at(objectNumber));
132
133 usleep(1000000);
134 ARMARX_INFO_S << "Loading image number " << i + 1;
135 p->imageProviderProxy->loadNextImage();
136 usleep(3000000);
137 }
138 }
139
140 ARMARX_IMPORTANT_S << "Finished recognition evaluation";
141 }
142 else
143 {
144 ARMARX_IMPORTANT_S << "Starting segmentation evaluation";
145
146 for (size_t objectNumber = 0; objectNumber < imageFilePathsLeft.size(); objectNumber++)
147 {
148 p->imageProviderProxy->setImageFilePath(imageFilePathsLeft.at(objectNumber),
149 imageFilePathsRight.at(objectNumber));
150
151 usleep(5000000);
152
153 int olpStatus = 0;
154
155 // create initial hypotheses
156
157 p->olpProxy->CreateInitialObjectHypotheses();
158
159 usleep(1000000);
160 p->imageProviderProxy->loadNextImage();
161 usleep(3000000);
162
163 do
164 {
165 usleep(100000);
166 olpStatus = p->olpObserverProxy
167 ->getDataField(new armarx::DataFieldIdentifierBase(
168 "ObjectLearningByPushingObserver",
169 "objectHypotheses",
170 "initialHypothesesCreated"))
171 ->getInt();
172 } while (olpStatus == 0);
173
174 if (olpStatus == -1)
175 {
177 << "Creation of initial hypotheses failed, skipping this object";
178 continue;
179 }
180
181 // only for LCCP evaluation
182 //ARMARX_IMPORTANT_S << "Skipping and continuing with next scene for LCCP evaluation";
183 //continue;
184
185
186 // validate initial hypotheses
187
188 p->olpProxy->ValidateInitialObjectHypotheses();
189
190 usleep(1000000);
191 p->imageProviderProxy->loadNextImage();
192 usleep(3000000);
193
194 do
195 {
196 usleep(100000);
197 olpStatus = p->olpObserverProxy
198 ->getDataField(new armarx::DataFieldIdentifierBase(
199 "ObjectLearningByPushingObserver",
200 "objectHypotheses",
201 "hypothesesValidated"))
202 ->getInt();
203 } while (olpStatus == 0);
204
205 if (olpStatus == -1)
206 {
208 << "Validation of initial hypotheses failed, skipping this object";
209 continue;
210 }
211
212
213 // revalidate hypotheses
214
215 for (int i = 2; i <= 5; i++)
216 {
217 ARMARX_INFO_S << "Loading image number " << i;
218
219 p->olpProxy->RevalidateConfirmedObjectHypotheses();
220
221 usleep(1000000);
222 p->imageProviderProxy->loadNextImage();
223 usleep(3000000);
224
225 do
226 {
227 usleep(100000);
228 olpStatus = p->olpObserverProxy
229 ->getDataField(new armarx::DataFieldIdentifierBase(
230 "ObjectLearningByPushingObserver",
231 "objectHypotheses",
232 "hypothesesValidated"))
233 ->getInt();
234 } while (olpStatus == 0);
235
236 if (olpStatus == -1)
237 {
238 ARMARX_WARNING_S << "Validation of hypotheses failed, skipping this object";
239 break;
240 }
241 }
242
243 ARMARX_IMPORTANT_S << "Finished segmentation of object " << objectNumber + 1
244 << " of " << imageFilePathsLeft.size();
245 }
246
247 ARMARX_IMPORTANT_S << "Finished segmenting all objects";
248 }
249 }
250
251 void
253 {
255 getProperty<std::string>("OLPName").getValue());
257 getProperty<std::string>("OLPObserverName").getValue());
259 getProperty<std::string>("ImageProviderName").getValue());
261 getProperty<std::string>("KinematicUnitName").getValue());
262 bool testRecognition = getProperty<bool>("TestRecognition").getValue();
263
264 std::thread t([=, this]() { evaluateOLP(this, testRecognition); });
265 t.detach();
266 }
267
268 void
272
273 void
277
284} // namespace visionx
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
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)