从一个点云里面创建一个深度图
這次,我們將顯示如何從一個點云和一個給定的傳感器來創(chuàng)造深度圖。下面的代碼,創(chuàng)建了一個在觀察者前面的矩形。
#include <pcl/range_image/range_image.h>int main (int argc, char** argv) {pcl::PointCloud<pcl::PointXYZ> pointCloud;// Generate the datafor (float y=-0.5f; y<=0.5f; y+=0.01f) {for (float z=-0.5f; z<=0.5f; z+=0.01f) {pcl::PointXYZ point;point.x = 2.0f - y;point.y = y;point.z = z;pointCloud.points.push_back(point);}}pointCloud.width = (uint32_t) pointCloud.points.size();pointCloud.height = 1;// We now want to create a range image from the above point cloud, with a 1deg angular resolutionfloat angularResolution = (float) ( 1.0f * (M_PI/180.0f)); // 1.0 degree in radiansfloat maxAngleWidth = (float) (360.0f * (M_PI/180.0f)); // 360.0 degree in radiansfloat maxAngleHeight = (float) (180.0f * (M_PI/180.0f)); // 180.0 degree in radiansEigen::Affine3f sensorPose = (Eigen::Affine3f)Eigen::Translation3f(0.0f, 0.0f, 0.0f);pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;float noiseLevel=0.00;float minRange = 0.0f;int borderSize = 1;pcl::RangeImage rangeImage;rangeImage.createFromPointCloud(pointCloud, angularResolution, maxAngleWidth, maxAngleHeight,sensorPose, coordinate_frame, noiseLevel, minRange, borderSize);std::cout << rangeImage << "\n"; }下面是代碼解釋:
#include <pcl/range_image/range_image.h>int main (int argc, char** argv) {pcl::PointCloud<pcl::PointXYZ> pointCloud;// Generate the datafor (float y=-0.5f; y<=0.5f; y+=0.01f) {for (float z=-0.5f; z<=0.5f; z+=0.01f) {pcl::PointXYZ point;point.x = 2.0f - y;point.y = y;point.z = z;pointCloud.points.push_back(point);}}pointCloud.width = (uint32_t) pointCloud.points.size();pointCloud.height = 1;上面包含了點云的頭文件,并生成了一個矩形的點云數(shù)據(jù)
float angularResolution = (float) ( 1.0f * (M_PI/180.0f)); // 1.0 degree in radiansfloat maxAngleWidth = (float) (360.0f * (M_PI/180.0f)); // 360.0 degree in radiansfloat maxAngleHeight = (float) (180.0f * (M_PI/180.0f)); // 180.0 degree in radiansEigen::Affine3f sensorPose = (Eigen::Affine3f)Eigen::Translation3f(0.0f, 0.0f, 0.0f);pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;float noiseLevel=0.00;float minRange = 0.0f;int borderSize = 1;上面那個部分定義了我們想去創(chuàng)建的深度圖的參數(shù)。
角度分辨率是1度,意味著光線將以一度來區(qū)別近鄰的像素點。maxAngleWidth=360和maxAngleHeight=190意味著我們模擬的深度圖傳感器有一個360度環(huán)繞的效果。你可以總是使用這些設(shè)置,因為深度圖將被裁剪成自動觀察的區(qū)域。你可以節(jié)省計算通過減少值。對于一個180度的激光雷達(dá),后面的點將看不見,msxAngleWidth=180就夠了。
sensorPose定義了6DOF視覺傳感器的位置,以roll=pitch=yaw=0這個位置為原點的。
coordinate_frame=CAMERA_FRAME告訴我們x是朝右的,y是朝下的,z是朝前的。一個可選的參數(shù)是LASER_FRAME,x是朝前的,y是朝左的,z是朝下的。
對于noiseLevel=0來說,深度圖通過一個normal z-buffer來創(chuàng)建的。
如果minRange比0要大,那么靠得很近的點就會被忽略。
borderSize比0大的話,將會在裁剪的時候留下一邊框的未觀察到的點。
pcl::RangeImage rangeImage;rangeImage.createFromPointCloud(pointCloud, angularResolution, maxAngleWidth, maxAngleHeight,sensorPose, coordinate_frame, noiseLevel, minRange, borderSize);std::cout << rangeImage << "\n";上面的這個代碼從點云里面創(chuàng)建了深度圖。
深度圖是繼承PointCloud這個類,這個點有x,y,z和深度。這里有3種點。有效的點的深度都是大于0的,無法觀察到的點如x=y=z=NAN和深度=-INFINITY。很遠(yuǎn)的點x=y=z=NAN深度=INFINITY
運(yùn)行結(jié)果
range image of size 42x36 with angular resolution 1deg/pixel and 1512 points?
?
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的从一个点云里面创建一个深度图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【课题总结】OpenCV 抠图项目实战(
- 下一篇: 心脏遥测监控系统服务器,基于ARM7的心