ObjectLearningByPushingDefinitions.h
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
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 // defines which camera is used
26 //#define OLP_USE_XB3
27 //#define OLP_USE_KAHEAD
28 //#define OLP_USE_DBVISION
29 #define OLP_USE_ARMAR3
30 //#define OLP_USE_ARMAR3_ARMAR3_4
31 
32 //// camera calibration file
33 //#if defined OLP_USE_XB3
34 // #define OLP_CAMERA_CALIBRATION_FILE "C:/Users/Lovov/My Documents/Visual Studio 2008/Projects/SiftFeaturePlaneFinder2/SiftFeaturePlaneFinder/cameras-David7.txt"
35 //#elif defined OLP_USE_KAHEAD
36 // //#define OLP_CAMERA_CALIBRATION_FILE "C:/img/Experiments with Armar/camera_armar3b_640x480_wide-exp8-10.txt"
37 // //#define OLP_CAMERA_CALIBRATION_FILE "C:/img/Experiments with Armar/camera_armar3b_640x480_wide-exp1-7.txt"
38 // #define OLP_CAMERA_CALIBRATION_FILE "C:/Users/Lovov/My Documents/Visual Studio 2008/Projects/SiftFeaturePlaneFinder2/SiftFeaturePlaneFinder/cameras-Head3.txt"
39 // //#define OLP_CAMERA_CALIBRATION_FILE "C:/Users/Lovov/My Documents/Visual Studio 2008/Projects/SiftFeaturePlaneFinder2/SiftFeaturePlaneFinder/cameras-Kyoto1.txt"
40 //#elif defined OLP_USE_DBVISION
41 // #define OLP_CAMERA_CALIBRATION_FILE "params/StereoParametersIVT.cf"
42 //#elif defined OLP_USE_ARMAR3_ARMAR3_4
43 // //#define OLP_CAMERA_CALIBRATION_FILE "/localhome/armar-user/armar-user_test3_mca2.4/david_mca2.4/armar3/robot_interface/files/camera_armar3a_640x480_wide.txt"
44 // #define OLP_CAMERA_CALIBRATION_FILE "/localhome/armar-user/armar-user_test3_mca2.4/armar3/robot_interface/files/camera_armar3a_640x480_wide.txt"
45 //#elif defined OLP_USE_ARMAR3
46 // #define OLP_CAMERA_CALIBRATION_FILE "/common/homes/staff/schieben/home/mca2.4/projects/armar3/robot_interface/files/camera_armar3a_640x480_wide.txt"
47 // //#define OLP_CAMERA_CALIBRATION_FILE "/home/staff/schieben/mca2.4-3b/projects/armar3b/robot_interface/files/camera_armar3b_640x480_wide.txt"
48 //#endif
49 
50 // defines image sizes
51 #if defined OLP_USE_XB3
52 #define OLP_IMG_WIDTH_CAM 1280
53 #define OLP_IMG_HEIGHT_CAM 960
54 #elif defined OLP_USE_KAHEAD
55 #define OLP_IMG_WIDTH_CAM 640
56 #define OLP_IMG_HEIGHT_CAM 480
57 #elif defined OLP_USE_DBVISION
58 #define OLP_IMG_WIDTH_CAM 640 // <- enter the resolution of the camera images here
59 #define OLP_IMG_HEIGHT_CAM 480
60 #elif defined OLP_USE_ARMAR3
61 #define OLP_IMG_WIDTH_CAM 640
62 #define OLP_IMG_HEIGHT_CAM 480
63 #else
64 #define OLP_IMG_WIDTH_CAM 640
65 #define OLP_IMG_HEIGHT_CAM 480
66 #endif
67 
68 #define OLP_IMG_WIDTH 640
69 #define OLP_IMG_HEIGHT 480
70 
71 
72 // define if a human executes the pushing
73 //#define OLP_HUMAN_PUSHES
74 // defines which robot is used for pushing
75 //#define OLP_USE_KUKA_ARMS
76 //#define OLP_USE_ATR_ROBOT
77 
78 // operating system
79 //#define WIN32
80 #define LINUX
81 
82 // influences the computational effort, e.g. the number of iterations of RANSAC
83 #if defined _DEBUG
84 #define OLP_EFFORT_MODIFICATOR 0.5f
85 #else
86 #define OLP_EFFORT_MODIFICATOR 1.0f
87 #endif
88 
89 
90 // modifies the tolerance for points lying on planes and cylinders, can be reduced
91 // for good or increased for bad stereo calibrations
92 #if defined OLP_USE_XB3
93 #define OLP_TOLERANCE_MODIFICATOR 0.9f
94 #elif defined OLP_USE_KAHEAD
95 #define OLP_TOLERANCE_MODIFICATOR 1.5f
96 #elif defined OLP_USE_DBVISION
97 #define OLP_TOLERANCE_MODIFICATOR 1.5f
98 #elif defined OLP_USE_ARMAR3
99 #define OLP_TOLERANCE_MODIFICATOR 1.5f
100 #else
101 #define OLP_TOLERANCE_MODIFICATOR 1.0f
102 #endif
103 
104 
105 // the maximal allowed distance of an object from the camera, in mm
106 #define OLP_MAX_OBJECT_DISTANCE 1500.0f // 1200
107 
108 // minimal number of feature points for a hypothesis
109 #define OLP_MIN_NUM_FEATURES 30 // 25
110 
111 // maximal number of initial hypotheses that will be generated
112 #define OLP_MAX_NUM_HYPOTHESES 80 // 120
113 
114 // influences how many clusters are created when applying x-means to the generated initial hypotheses
115 // a bigger factor leads to more clusters
116 #define OLP_CLUSTERING_FACTOR_PLANES 2.5f
117 // maximal number of parts into which the object may be divided by clustering
118 #define OLP_MAX_NUM_CLUSTERING_PARTS 6 // 6
119 
120 
121 // number of parallel threads if OpenMP is used. If undefined, the number of threads will be set to the number of CPUs
122 #ifdef OLP_USE_ARMAR3_ARMAR3_4
123 #define OMP_NUM_THREADS 2
124 #else
125 //#define OMP_NUM_THREADS 1
126 #endif
127 
128 
129 // decide if classes of known objects will be loaded
130 //#define OLP_LOAD_KNOWN_OBJECTS false
131 
132 
133 // decide if a new visual vocabulary will be learned (may take around 1 hour!)
134 //#define OLP_LEARN_NEW_VISUAL_VOCABULARY false
135 
136 // for the point/komma problem
137 #define OLP_KOMMA
138 
139 // directories and files for object recognition
140 #if defined OLP_USE_ARMAR3_ARMAR3_4
141 #define OLP_OBJECT_LEARNING_DIR \
142  "/localhome/armar-user/armar-user_test3_mca2.4/david_mca2.4/OLP/data/"
143 #define OLP_HISTOGRAM_DIR \
144  "/localhome/armar-user/armar-user_test3_mca2.4/david_mca2.4/OLP/data/Histograms-punkt/"
145 #define OLP_OBJECT_NAMES_FILE \
146  "/localhome/armar-user/armar-user_test3_mca2.4/david_mca2.4/OLP/data/Histograms-punkt/" \
147  "ObjectNames.txt"
148 #define OLP_VOCABULARY_FILE \
149  "/localhome/armar-user/armar-user_test3_mca2.4/david_mca2.4/OLP/data/" \
150  "VisualVocabulary1000d.txt"
151 #define OLP_ADDITIONAL_OBJECT_IMAGES_DIR \
152  "/localhome/armar-user/armar-user_test3_mca2.4/david_mca2.4/OLP/data/objects/"
153 #define OLP_NEW_VOCABULARY_FILE \
154  "/localhome/armar-user/armar-user_test3_mca2.4/david_mca2.4/OLP/data/" \
155  "VisualVocabulary1000e.txt"
156 #define OLP_NEW_VOCABULARY_TRAINING_IMAGES \
157  "/localhome/armar-user/armar-user_test3_mca2.4/david_mca2.4/OLP/data/objects/" \
158  "MoreObjects000.bmp"
159 #elif defined OLP_USE_ARMAR3
160 #ifdef OLP_KOMMA
161 //#define OLP_HISTOGRAM_DIR "/common/homes/staff/schieben/home/OLP/data/Histograms-komma/"
162 //#define OLP_OBJECT_NAMES_FILE "/common/homes/staff/schieben/home/OLP/data/Histograms-komma/ObjectNames.txt"
163 //#define OLP_VOCABULARY_FILE "/common/homes/staff/schieben/home/OLP/data/VisualVocabulary1000d-komma.txt"
164 //#define OLP_VOCABULARY_FILE "/home/mobiletamer/OLP/data/VisualVocabulary1000d-komma.txt"
165 #else
166 #define OLP_HISTOGRAM_DIR "/common/homes/staff/schieben/home/OLP/data/Histograms-punkt/"
167 #define OLP_OBJECT_NAMES_FILE \
168  "/common/homes/staff/schieben/home/OLP/data/Histograms-punkt/ObjectNames.txt"
169 #define OLP_VOCABULARY_FILE \
170  "/common/homes/staff/schieben/home/OLP/data/VisualVocabulary1000d-punkt.txt"
171 //#define OLP_VOCABULARY_FILE "/home/mobiletamer/OLP/data/VisualVocabulary1000d.txt"
172 #endif
173 //#define OLP_OBJECT_LEARNING_DIR "/home/staff/schieben/OLP/data/LearnedObjects/"
174 // #define OLP_OBJECT_LEARNING_DIR "/common/homes/staff/schieben/home/datalog/LearnedObjects/temp/"
175 #define OLP_OBJECT_LEARNING_DIR "/common/homes/students/haas/OLP/temp/"
176 
177 //#define OLP_ADDITIONAL_OBJECT_IMAGES_DIR "/common/homes/staff/schieben/home/OLP/data/objects/"
178 //#define OLP_NEW_VOCABULARY_FILE "/common/homes/staff/schieben/home/OLP/data/VisualVocabulary1000e.txt"
179 //#define OLP_NEW_VOCABULARY_TRAINING_IMAGES "/common/homes/staff/schieben/home/OLP/data/objects/MoreObjects000.bmp"
180 #elif defined OLP_USE_DBVISION
181 #define OLP_OBJECT_LEARNING_DIR "params/ObjectLearning/"
182 #define OLP_HISTOGRAM_DIR "params/ObjectLearning/HistogramsE/"
183 #define OLP_OBJECT_NAMES_FILE "params/ObjectLearning/HistogramsE/ObjectNames.txt"
184 #define OLP_VOCABULARY_FILE "params/ObjectLearning/VisualVocabulary1000d.txt"
185 #define OLP_ADDITIONAL_OBJECT_IMAGES_DIR "params/ObjectLearning/objects/"
186 #define OLP_NEW_VOCABULARY_FILE "params/ObjectLearning/objects/VisualVocabulary1000e.txt"
187 #define OLP_NEW_VOCABULARY_TRAINING_IMAGES \
188  "params/ObjectLearning/objects/MoreObjects000.bmp" // <- names have to end on 000, 001, 002 etc.
189 #else
190 #define OLP_OBJECT_LEARNING_DIR "c:/img/"
191 #define OLP_HISTOGRAM_DIR "c:/img/HistogramsE/"
192 #define OLP_OBJECT_NAMES_FILE "c:/img/HistogramsE/ObjectNames.txt"
193 #define OLP_VOCABULARY_FILE "c:/img/VisualVocabulary1000d.txt"
194 #define OLP_ADDITIONAL_OBJECT_IMAGES_DIR "c:/img/objects/"
195 #define OLP_NEW_VOCABULARY_FILE "c:/img/VisualVocabulary1000e.txt"
196 #define OLP_NEW_VOCABULARY_TRAINING_IMAGES \
197  "c:/img/objects/MoreObjects000.bmp" // <- names have to end on 000, 001, 002 etc.
198 #endif
199 //#define OLP_NEW_VOCABULARY_NUMBER_OF_TRAINING_IMAGES 20
200 
201 
202 // define if images should be shown in OpenCV windows
203 #ifndef OLP_USE_ARMAR3_ARMAR3_4
204 #define OLP_SHOW_RESULT_IMAGES
205 #endif
206 // waiting time for the visualization (in ms)
207 #define OLP_WAITING_TIME_VISUALISATION 400
208 
209 // screenshots
210 #ifdef OLP_USE_ARMAR3_ARMAR3_4
211 #define OLP_MAKE_RESULT_SCREENSHOTS false
212 #define OLP_MAKE_INTERMEDIATE_SCREENSHOTS false
213 #define OLP_SAVE_COMPLETE_POINTCLOUD false
214 #define OLP_SAVE_CONFIRMED_OBJECT false
215 #else
216 #define OLP_MAKE_RESULT_SCREENSHOTS true
217 #define OLP_MAKE_INTERMEDIATE_SCREENSHOTS true
218 #define OLP_SAVE_COMPLETE_POINTCLOUD true
219 #define OLP_SAVE_CONFIRMED_OBJECT true
220 #endif
221 #define OLP_SCREENSHOT_PATH OLP_OBJECT_LEARNING_DIR
222 //#define OLP_SCREENSHOT_PATH "/homes/staff/schieben/datalog/YCB/Head/temp/"
223 
224 
225 // scaling factor for the image before being fouriertransformed
226 #define OLP_FOURIER_TRANSFORM_SCALING_FACTOR 0.5
227 
228 
229 // size of the MSER color histogram
230 #define OLP_SIZE_MSER_HISTOGRAM 64
231 // number of SIFT descriptors per point
232 //#define OLP_NUM_DESCRIPTORS_PER_POINT 9
233 // size of the hue histogram for object recognition
234 #define OLP_SIZE_OBJECT_HUE_HISTOGRAM 64
235 
236 
237 // tolerance for the validation if a point moved concurrently (in mm)
238 #define OLP_TOLERANCE_CONCURRENT_MOTION 80.0f // 70
239 // minimal necessary motion for a hypothesis to be validated (in mm)
240 #define OLP_MINIMAL_MOTION_MEASURE 30.0f // 50
241 // when using RGBD: maximal distance (in px) from next confirmed point for being added as a new candidate (if point is also in changed image area)
242 #define OLP_MAX_DISTANCE_FOR_ADDING_FOREGROUND_CANDIDATE_2D 40
243 // when using RGBD: maximal distance (in mm) from next confirmed point for being added as a new candidate (if point is also in changed image area)
244 #define OLP_MAX_DISTANCE_FOR_ADDING_FOREGROUND_CANDIDATE_3D 70
245 // generate a segmentation image region from the confirmed points, and add all scene points in that region to the confirmed points
246 #define OLP_ADD_POINTS_FROM_SEGMENTED_REGION
247 // threshold to decide whether a pixel changed or not
248 #define OLP_FOREGROUND_THRESHOLD 50 //50
249 
250 
251 // for color ICP: weight of the color distance to the cartesian distance (maximal color distance = x mm)
252 #define OLP_ICP_COLOR_DISTANCE_WEIGHT 40.0f
253 // for color ICP: point correspondences with a bigger distance than this will not be used
254 #define OLP_ICP_CUTOFF_DISTANCE 3 * OLP_TOLERANCE_CONCURRENT_MOTION // FLT_MAX
255 
256 
257 // set minimal distance between Harris Interest Points that will be detected (in pixels)
258 #define OLP_HARRIS_POINT_DISTANCE 3.0f
259 // set minimal relative saliency of Harris Interest Points (smaller -> more points)
260 #define OLP_HARRIS_POINT_QUALITY 0.0001f // 0.001
261 
262 // define to calculate and use MSERs
263 #define OLP_USE_MSERS
264 
265 
266 // define to use points from the depth map
267 #define OLP_USE_DEPTH_MAP
268 // distance between depth map pixels that will be used
269 #define OLP_DEPTH_MAP_PIXEL_DISTANCE 3 // 3
270 // effort for relocalizing a hypothesis after pushing
271 #ifdef OLP_USE_ARMAR3_ARMAR3_4
272 #define OLP_EFFORT_POINTCLOUD_MATCHING 1
273 #else
274 #define OLP_EFFORT_POINTCLOUD_MATCHING 3 // 3
275 #endif
276 // factor for clustering the changed points after the first push to create foreground hypotheses (bigger->more hypotheses)
277 #define OLP_CLUSTERING_FACTOR_FOREGROUND_HYPOTHESES 10.0f
278 // clustering of promising regions for object re-localization (bigger->more promising positions will be tested)
279 #define OLP_CLUSTERING_FACTOR_OBJECT_LOCALIZATION 2.5f // 1.5
280 
281 #ifdef OLP_USE_DEPTH_MAP
282 // create hypotheses from large color MSERs
283 #define OLP_FIND_UNICOLORED_HYPOTHESES // <--
284 // minimal size for an MSER to be used for creating a hypothesis (in pixels)
285 #define OLP_MSER_HYPOTHESIS_MIN_SIZE 225
286 // maximal size for an MSER to be used for creating a hypothesis (in pixels)
287 #define OLP_MSER_HYPOTHESIS_MAX_SIZE (OLP_IMG_WIDTH * OLP_IMG_HEIGHT / 100)
288 // create planar hypotheses
289 #define OLP_FIND_PLANES // <--
290 // create cylindrical hypotheses
291 //#define OLP_FIND_CYLINDERS
292 // create spherical hypotheses
293 //#define OLP_FIND_SPHERES
294 // create hypotheses from clusters of points that just lie close to each other, but not on a plane/cylinder/sphere
295 //#define OLP_FIND_IRREGULAR_CLUSTERS
296 // generate hypotheses from not-yet-covered salient regions
297 #define OLP_FIND_SALIENCY_HYPOTHESES // <--
298 // use the LCCP segmentation to generate hypotheses
299 //#define OLP_USE_LCCP
300 #define OLP_MIN_SIZE_LCCP_SEGMENT OLP_MIN_NUM_FEATURES
301 #define OLP_MAX_SIZE_LCCP_SEGMENT (OLP_IMG_WIDTH * OLP_IMG_HEIGHT / 100)
302 //#define OLP_MAKE_LCCP_SEG_IMAGES
303 #else
304 // create planar hypotheses
305 //#define OLP_FIND_PLANES
306 // create cylindrical hypotheses
307 //#define OLP_FIND_CYLINDERS
308 // create spherical hypotheses
309 //#define OLP_FIND_SPHERES
310 // create hypotheses from clusters of points that just lie close to each other, but not on a plane/cylinder/sphere
311 //#define OLP_FIND_IRREGULAR_CLUSTERS
312 #endif
313 
314 
315 // define this to keep only those initial hypotheses that are local maxima (with relation to their height)
316 #ifdef OLP_USE_DEPTH_MAP
317 #define OLP_FILTER_INITIAL_HYPOTHESES_WITH_MAXIMUMNESS
318 #endif
319 
320 // no SIFT points with x coordinate in image smaller than this value will be used, so that the
321 // resulting hypotheses can get a correct maximumness rating
322 #ifdef OLP_FILTER_INITIAL_HYPOTHESES_WITH_MAXIMUMNESS
323 #define OLP_MIN_X_VALUE_SIFT_POINTS 120
324 #else
325 #define OLP_MIN_X_VALUE_SIFT_POINTS 0
326 #endif
327 
328 
329 // a central position in front of the robot. The hypothesis closest to this position is chosen for pushing,
330 // and the object is always pushed towards this point
331 #define OLP_CENTRAL_POSITION_FOR_PUSHING_X 0
332 #define OLP_CENTRAL_POSITION_FOR_PUSHING_Y 500
333 #define OLP_CENTRAL_POSITION_FOR_PUSHING_Z 1100
334 
335 
336 // define if using OpenCV version >= 2.3
337 #define OLP_USE_NEW_OPENCV