35
35
36
36
#include " test_precomp.hpp"
37
37
#include < opencv2/rgbd.hpp>
38
+ #include < opencv2/calib3d.hpp>
38
39
39
40
namespace cv
40
41
{
@@ -77,7 +78,7 @@ void TickMeter::stop()
77
78
return ;
78
79
79
80
++counter;
80
-
81
+
81
82
sumTime += ( time - startTime );
82
83
startTime = 0 ;
83
84
}
@@ -129,6 +130,35 @@ float cy = H / 2.f + 0.5f;
129
130
Mat K = (Mat_<double >(3 , 3 ) << focal_length, 0 , cx, 0 , focal_length, cy, 0 , 0 , 1 );
130
131
Mat Kinv = K.inv();
131
132
133
+ void points3dToDepth16U (const Mat_<Vec3f>& points3d, Mat& depthMap);
134
+
135
+ void points3dToDepth16U (const Mat_<Vec3f>& points3d, Mat& depthMap)
136
+ {
137
+ std::vector<Point3f> points3dvec;
138
+ for (int i = 0 ; i < H; i++)
139
+ for (int j = 0 ; j < W; j++)
140
+ points3dvec.push_back (Point3f (points3d (i,j)[0 ], points3d (i,j)[1 ], points3d (i,j)[2 ]));
141
+
142
+ std::vector<Point2f> img_points;
143
+ depthMap = Mat::zeros (H, W, CV_32F);
144
+ Vec3f R (0.0 ,0.0 ,0.0 );
145
+ Vec3f T (0.0 ,0.0 ,0.0 );
146
+ cv::projectPoints (points3dvec, R, T, K, Mat (), img_points);
147
+
148
+ int index = 0 ;
149
+ for (int i = 0 ; i < H; i++)
150
+ {
151
+
152
+ for (int j = 0 ; j < W; j++)
153
+ {
154
+ float value = (points3d.at <Vec3f>(i, j))[2 ]; // value is the z
155
+ depthMap.at <float >(cvRound (img_points[index].y ), cvRound (img_points[index].x )) = value;
156
+ index++;
157
+ }
158
+ }
159
+ depthMap.convertTo (depthMap, CV_16U, 1000 );
160
+ }
161
+
132
162
static RNG rng;
133
163
struct Plane
134
164
{
@@ -224,8 +254,8 @@ class CV_RgbdNormalsTest: public cvtest::BaseTest
224
254
// inner vector: whether it's 1 plane or 3 planes
225
255
// outer vector: float or double
226
256
std::vector<std::vector<float > > errors (2 );
227
- errors[0 ].resize (2 );
228
- errors[1 ].resize (2 );
257
+ errors[0 ].resize (4 );
258
+ errors[1 ].resize (4 );
229
259
switch (i)
230
260
{
231
261
case 0 :
@@ -241,8 +271,13 @@ class CV_RgbdNormalsTest: public cvtest::BaseTest
241
271
std::cout << std::endl << " *** LINEMOD" << std::endl;
242
272
errors[0 ][0 ] = 0 .04f ;
243
273
errors[0 ][1 ] = 0 .07f ;
274
+ errors[0 ][2 ] = 0 .04f ; // depth 16U 1 plane
275
+ errors[0 ][3 ] = 0 .07f ; // depth 16U 3 planes
276
+
244
277
errors[1 ][0 ] = 0 .05f ;
245
278
errors[1 ][1 ] = 0 .08f ;
279
+ errors[1 ][2 ] = 0 .05f ; // depth 16U 1 plane
280
+ errors[1 ][3 ] = 0 .08f ; // depth 16U 3 planes
246
281
break ;
247
282
case 2 :
248
283
method = RgbdNormals::RGBD_NORMALS_METHOD_SRI;
@@ -252,9 +287,9 @@ class CV_RgbdNormalsTest: public cvtest::BaseTest
252
287
errors[1 ][0 ] = 0 .02f ;
253
288
errors[1 ][1 ] = 0 .04f ;
254
289
break ;
255
- default :
256
- method = (RgbdNormals::RGBD_NORMALS_METHOD)-1 ;
257
- CV_Error (0 , " " );
290
+ default :
291
+ method = (RgbdNormals::RGBD_NORMALS_METHOD)-1 ;
292
+ CV_Error (0 , " " );
258
293
}
259
294
260
295
for (unsigned char j = 0 ; j < 2 ; ++j)
@@ -271,7 +306,7 @@ class CV_RgbdNormalsTest: public cvtest::BaseTest
271
306
std::vector<Plane> plane_params;
272
307
Mat points3d, ground_normals;
273
308
// 1 plane, continuous scene, very low error..
274
- std::cout << " 1 plane" << std::endl;
309
+ std::cout << " 1 plane - input 3d points " << std::endl;
275
310
float err_mean = 0 ;
276
311
for (int ii = 0 ; ii < 5 ; ++ii)
277
312
{
@@ -291,6 +326,34 @@ class CV_RgbdNormalsTest: public cvtest::BaseTest
291
326
}
292
327
std::cout << " mean diff: " << (err_mean / 5 ) << std::endl;
293
328
EXPECT_LE (err_mean/5 , errors[j][1 ])<< " mean diff: " << (err_mean/5 ) << " thresh: " << errors[j][1 ] << std::endl;
329
+
330
+ if (method == RgbdNormals::RGBD_NORMALS_METHOD_LINEMOD)
331
+ {
332
+ // depth 16U test
333
+ std::cout << " ** depth 16U - 1 plane" << std::endl;
334
+ err_mean = 0 ;
335
+ for (int ii = 0 ; ii < 5 ; ++ii)
336
+ {
337
+ gen_points_3d (plane_params, plane_mask, points3d, ground_normals, 1 );
338
+ Mat depthMap;
339
+ points3dToDepth16U (points3d, depthMap);
340
+ err_mean += testit (depthMap, ground_normals, normals_computer);
341
+ }
342
+ std::cout << " mean diff: " << (err_mean / 5 ) << std::endl;
343
+ EXPECT_LE (err_mean/5 , errors[j][2 ])<< " thresh: " << errors[j][2 ] << std::endl;
344
+
345
+ std::cout << " ** depth 16U - 3 plane" << std::endl;
346
+ err_mean = 0 ;
347
+ for (int ii = 0 ; ii < 5 ; ++ii)
348
+ {
349
+ gen_points_3d (plane_params, plane_mask, points3d, ground_normals, 3 );
350
+ Mat depthMap;
351
+ points3dToDepth16U (points3d, depthMap);
352
+ err_mean += testit (depthMap, ground_normals, normals_computer);
353
+ }
354
+ std::cout << " mean diff: " << (err_mean / 5 ) << std::endl;
355
+ EXPECT_LE (err_mean/5 , errors[j][3 ])<< " mean diff: " << (err_mean/5 ) << " thresh: " << errors[j][3 ] << std::endl;
356
+ }
294
357
}
295
358
}
296
359
@@ -309,7 +372,7 @@ class CV_RgbdNormalsTest: public cvtest::BaseTest
309
372
TickMeter tm;
310
373
tm.start ();
311
374
Mat in_normals;
312
- if (normals_computer.getMethod () == RgbdNormals::RGBD_NORMALS_METHOD_LINEMOD)
375
+ if (normals_computer.getMethod () == RgbdNormals::RGBD_NORMALS_METHOD_LINEMOD && points3d. channels () == 3 )
313
376
{
314
377
std::vector<Mat> channels;
315
378
split (points3d, channels);
@@ -450,7 +513,7 @@ class CV_RgbdPlaneTest: public cvtest::BaseTest
450
513
451
514
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
452
515
453
- TEST (DISABLED_Rgbd_Normals , compute)
516
+ TEST (Rgbd_Normals , compute)
454
517
{
455
518
cv::rgbd::CV_RgbdNormalsTest test;
456
519
test.safe_run ();
0 commit comments