10
10
11
11
using namespace roboticslab ;
12
12
13
+ template <>
14
+ void KinectFusionImpl<cv::colored_kinfu::ColoredKinFu>::getCloud(yarp::sig::PointCloudXYZNormalRGBA & cloudWithNormals) const
15
+ {
16
+ cv::Mat points, normals, colors;
17
+
18
+ mtx.lock ();
19
+ handle->getCloud (points, normals, colors);
20
+ mtx.unlock ();
21
+
22
+ cloudWithNormals.resize (points.rows );
23
+
24
+ for (auto i = 0 ; i < points.rows ; i++)
25
+ {
26
+ using color_t = unsigned char ;
27
+ const auto & point = points.at <cv::Vec4f>(i);
28
+ const auto & normal = normals.at <cv::Vec4f>(i);
29
+ const auto & color = colors.at <cv::Vec4f>(i);
30
+
31
+ cloudWithNormals (i) = {
32
+ {point[0 ], point[1 ], point[2 ]},
33
+ {normal [0 ], normal [1 ], normal [2 ]},
34
+ {static_cast <color_t >(color[0 ]), static_cast <color_t >(color[1 ]), static_cast <color_t >(color[2 ]), static_cast <color_t >(color[3 ])}
35
+ };
36
+ }
37
+ }
38
+
13
39
template <>
14
40
bool KinectFusionImpl<cv::colored_kinfu::ColoredKinFu>::update(const yarp::sig::ImageOf<yarp::sig::PixelFloat> & depthFrame,
15
- const yarp::sig::FlexImage & rgbFrame )
41
+ const yarp::sig::FlexImage & colorFrame )
16
42
{
17
43
// Cast away constness so that toCvMat accepts the YARP image. This function
18
44
// does not alter the inner structure of PixelFloat images anyway.
19
45
auto & nonConstDepthFrame = const_cast <yarp::sig::ImageOf<yarp::sig::PixelFloat> &>(depthFrame);
20
46
cv::Mat depthMat = yarp::cv::toCvMat (nonConstDepthFrame);
21
47
22
48
yarp::sig::ImageOf<yarp::sig::PixelBgr> bgrFrame;
23
- bgrFrame.copy (rgbFrame);
49
+ bgrFrame.copy (colorFrame); // convert to BGR (probably from RGB)
24
50
cv::Mat bgrMat = yarp::cv::toCvMat (bgrFrame);
25
51
26
52
cv::UMat depthUmat;
27
53
depthMat.convertTo (depthUmat, depthMat.type (), 1000.0 ); // OpenCV uses milimeters
54
+
55
+ std::lock_guard<std::mutex> lock (mtx);
28
56
return handle->update (depthUmat, bgrMat);
29
57
}
30
58
@@ -42,9 +70,9 @@ namespace roboticslab
42
70
43
71
std::unique_ptr<KinectFusion> makeColoredKinFu (const yarp::os::Searchable & config,
44
72
const yarp::sig::IntrinsicParams & depthIntrinsic,
45
- const yarp::sig::IntrinsicParams & rgbIntrinsic ,
73
+ const yarp::sig::IntrinsicParams & colorIntrinsic ,
46
74
int depthWidth, int depthHeight,
47
- int rgbWidth , int rgbHeight )
75
+ int colorWidth , int colorHeight )
48
76
{
49
77
using Params = cv::colored_kinfu::Params;
50
78
@@ -65,20 +93,20 @@ std::unique_ptr<KinectFusion> makeColoredKinFu(const yarp::os::Searchable & conf
65
93
yCInfo (KINFU) << " principal point (X):" << depthIntrinsic.principalPointX ;
66
94
yCInfo (KINFU) << " principal point (Y):" << depthIntrinsic.principalPointY ;
67
95
68
- yCInfo (KINFU) << " --- CAMERA PARAMETERS (RGB ) ---" ;
96
+ yCInfo (KINFU) << " --- CAMERA PARAMETERS (color ) ---" ;
69
97
70
- params->rgb_frameSize = cv::Size (rgbWidth, rgbHeight );
71
- yCInfo (KINFU) << " width:" << rgbWidth ;
72
- yCInfo (KINFU) << " height:" << rgbHeight ;
98
+ params->rgb_frameSize = cv::Size (colorWidth, colorHeight );
99
+ yCInfo (KINFU) << " width:" << colorWidth ;
100
+ yCInfo (KINFU) << " height:" << colorHeight ;
73
101
74
- params->rgb_intr = cv::Matx33f (rgbIntrinsic .focalLengthX , 0 , rgbIntrinsic .principalPointX ,
75
- 0 , rgbIntrinsic .focalLengthY , rgbIntrinsic .principalPointY ,
76
- 0 , 0 , 1 );
102
+ params->rgb_intr = cv::Matx33f (colorIntrinsic .focalLengthX , 0 , colorIntrinsic .principalPointX ,
103
+ 0 , colorIntrinsic .focalLengthY , colorIntrinsic .principalPointY ,
104
+ 0 , 0 , 1 );
77
105
78
- yCInfo (KINFU) << " focal length (X):" << rgbIntrinsic .focalLengthX ;
79
- yCInfo (KINFU) << " focal length (Y):" << rgbIntrinsic .focalLengthY ;
80
- yCInfo (KINFU) << " principal point (X):" << rgbIntrinsic .principalPointX ;
81
- yCInfo (KINFU) << " principal point (Y):" << rgbIntrinsic .principalPointY ;
106
+ yCInfo (KINFU) << " focal length (X):" << colorIntrinsic .focalLengthX ;
107
+ yCInfo (KINFU) << " focal length (Y):" << colorIntrinsic .focalLengthY ;
108
+ yCInfo (KINFU) << " principal point (X):" << colorIntrinsic .principalPointX ;
109
+ yCInfo (KINFU) << " principal point (Y):" << colorIntrinsic .principalPointY ;
82
110
83
111
yCInfo (KINFU) << " --- ALGORITHM PARAMETERS ---" ;
84
112
@@ -203,7 +231,7 @@ std::unique_ptr<KinectFusion> makeColoredKinFu(const yarp::os::Searchable & conf
203
231
yCInfo (KINFU) << " volumePoseTransl (DEFAULT):" << transl[0 ] << transl[1 ] << transl[2 ];
204
232
}
205
233
206
- if (config.check (" volumeType" , " type of voxel volume (tsdf, hashtsdf)" ))
234
+ if (config.check (" volumeType" , " type of voxel volume (tsdf, hashtsdf, coloredtsdf )" ))
207
235
{
208
236
std::string volumeType = config.find (" volumeType" ).asString ();
209
237
0 commit comments