38 #include <pcl/io/pcd_io.h> 39 #include <pcl/io/ply_io.h> 40 #include <pcl/common/transforms.h> 41 #include <pcl/common/common.h> 42 #include <opencv2/imgproc/imgproc.hpp> 43 #include <opencv2/imgproc/types_c.h> 51 cv::Mat
bgrFromCloud(
const pcl::PointCloud<pcl::PointXYZRGBA> & cloud,
bool bgrOrder)
53 cv::Mat frameBGR = cv::Mat(cloud.height,cloud.width,CV_8UC3);
55 for(
unsigned int h = 0; h < cloud.height; h++)
57 for(
unsigned int w = 0; w < cloud.width; w++)
61 frameBGR.at<cv::Vec3b>(h,w)[0] = cloud.at(h*cloud.width + w).b;
62 frameBGR.at<cv::Vec3b>(h,w)[1] = cloud.at(h*cloud.width + w).g;
63 frameBGR.at<cv::Vec3b>(h,w)[2] = cloud.at(h*cloud.width + w).r;
67 frameBGR.at<cv::Vec3b>(h,w)[0] = cloud.at(h*cloud.width + w).r;
68 frameBGR.at<cv::Vec3b>(h,w)[1] = cloud.at(h*cloud.width + w).g;
69 frameBGR.at<cv::Vec3b>(h,w)[2] = cloud.at(h*cloud.width + w).b;
78 const pcl::PointCloud<pcl::PointXYZRGBA> & cloud,
83 cv::Mat frameDepth = cv::Mat(cloud.height,cloud.width,depth16U?CV_16UC1:CV_32FC1);
86 for(
unsigned int h = 0; h < cloud.height; h++)
88 for(
unsigned int w = 0; w < cloud.width; w++)
90 float depth = cloud.at(h*cloud.width + w).z;
94 unsigned short depthMM = 0;
95 if(depth <= (
float)USHRT_MAX)
97 depthMM = (
unsigned short)depth;
99 frameDepth.at<
unsigned short>(h,w) = depthMM;
103 frameDepth.at<
float>(h,w) = depth;
108 uIsFinite(cloud.at(h*cloud.width + w).x) &&
110 w != cloud.width/2 &&
113 fx = cloud.at(h*cloud.width + w).x / ((float(w) - float(cloud.width)/2.0f) * depth);
120 uIsFinite(cloud.at(h*cloud.width + w).y) &&
122 h != cloud.height/2 &&
125 fy = cloud.at(h*cloud.width + w).y / ((float(h) - float(cloud.height)/2.0f) * depth);
139 cv::Mat & frameDepth,
145 frameDepth = cv::Mat(cloud.height,cloud.width,depth16U?CV_16UC1:CV_32FC1);
146 frameBGR = cv::Mat(cloud.height,cloud.width,CV_8UC3);
150 for(
unsigned int h = 0; h < cloud.height; h++)
152 for(
unsigned int w = 0; w < cloud.width; w++)
157 frameBGR.at<cv::Vec3b>(h,w)[0] = cloud.at(h*cloud.width + w).b;
158 frameBGR.at<cv::Vec3b>(h,w)[1] = cloud.at(h*cloud.width + w).g;
159 frameBGR.at<cv::Vec3b>(h,w)[2] = cloud.at(h*cloud.width + w).r;
163 frameBGR.at<cv::Vec3b>(h,w)[0] = cloud.at(h*cloud.width + w).r;
164 frameBGR.at<cv::Vec3b>(h,w)[1] = cloud.at(h*cloud.width + w).g;
165 frameBGR.at<cv::Vec3b>(h,w)[2] = cloud.at(h*cloud.width + w).b;
169 float depth = cloud.at(h*cloud.width + w).z;
173 unsigned short depthMM = 0;
174 if(depth <= (
float)USHRT_MAX)
176 depthMM = (
unsigned short)depth;
178 frameDepth.at<
unsigned short>(h,w) = depthMM;
182 frameDepth.at<
float>(h,w) = depth;
187 uIsFinite(cloud.at(h*cloud.width + w).x) &&
189 w != cloud.width/2 &&
192 fx = 1.0f/(cloud.at(h*cloud.width + w).x / ((float(w) - float(cloud.width)/2.0f) * depth));
199 uIsFinite(cloud.at(h*cloud.width + w).y) &&
201 h != cloud.height/2 &&
204 fy = 1.0f/(cloud.at(h*cloud.width + w).y / ((float(h) - float(cloud.height)/2.0f) * depth));
215 const cv::Mat & depthImage,
220 float depthErrorRatio)
222 UASSERT(depthImage.type() == CV_16UC1 || depthImage.type() == CV_32FC1);
226 float depth =
util2d::getDepth(depthImage, x, y, smoothing, depthErrorRatio);
230 cx = cx > 0.0f ? cx : float(depthImage.cols/2) - 0.5f;
231 cy = cy > 0.0f ? cy : float(depthImage.rows/2) - 0.5f;
234 pt.x = (x - cx) * depth / fx;
235 pt.y = (y - cy) * depth / fy;
240 pt.x = pt.y = pt.z = std::numeric_limits<float>::quiet_NaN();
246 const cv::Size & imageSize,
254 cx = cx > 0.0f ? cx : float(imageSize.width/2) - 0.5f;
255 cy = cy > 0.0f ? cy : float(imageSize.height/2) - 0.5f;
258 ray[0] = (x - cx) / fx;
259 ray[1] = (y - cy) / fy;
266 const cv::Mat & imageDepth,
272 std::vector<int> * validIndices)
275 return cloudFromDepth(imageDepth, model, decimation, maxDepth, minDepth, validIndices);
279 const cv::Mat & imageDepthIn,
284 std::vector<int> * validIndices)
286 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
291 float rgbToDepthFactorX = 1.0f;
292 float rgbToDepthFactorY = 1.0f;
295 UASSERT(!imageDepthIn.empty() && (imageDepthIn.type() == CV_16UC1 || imageDepthIn.type() == CV_32FC1));
297 cv::Mat imageDepth = imageDepthIn;
304 UDEBUG(
"Decimation from model (%d)", decimation);
307 UERROR(
"Decimation is not valid for current image size (model.imageHeight()=%d decimation=%d). The cloud is not created.", model.
imageHeight(), decimation);
312 UERROR(
"Decimation is not valid for current image size (model.imageWidth()=%d decimation=%d). The cloud is not created.", model.
imageWidth(), decimation);
317 decimation = -1*decimation;
320 if(targetSize > imageDepthIn.rows)
322 UDEBUG(
"Depth interpolation factor=%d", targetSize/imageDepthIn.rows);
326 else if(targetSize == imageDepthIn.rows)
332 UASSERT(imageDepthIn.rows % targetSize == 0);
333 decimation = imageDepthIn.rows / targetSize;
338 if(imageDepthIn.rows % decimation != 0)
340 UERROR(
"Decimation is not valid for current image size (imageDepth.rows=%d decimation=%d). The cloud is not created.", imageDepthIn.rows, decimation);
343 if(imageDepthIn.cols % decimation != 0)
345 UERROR(
"Decimation is not valid for current image size (imageDepth.cols=%d decimation=%d). The cloud is not created.", imageDepthIn.cols, decimation);
350 rgbToDepthFactorX = 1.0f/float((model.
imageWidth() / imageDepth.cols));
351 rgbToDepthFactorY = 1.0f/float((model.
imageHeight() / imageDepth.rows));
355 decimation =
abs(decimation);
356 UASSERT_MSG(imageDepth.rows % decimation == 0,
uFormat(
"rows=%d decimation=%d", imageDepth.rows, decimation).c_str());
357 UASSERT_MSG(imageDepth.cols % decimation == 0,
uFormat(
"cols=%d decimation=%d", imageDepth.cols, decimation).c_str());
361 cloud->height = imageDepth.rows/decimation;
362 cloud->width = imageDepth.cols/decimation;
363 cloud->is_dense =
false;
364 cloud->resize(cloud->height * cloud->width);
367 validIndices->resize(cloud->size());
370 float depthFx = model.
fx() * rgbToDepthFactorX;
371 float depthFy = model.
fy() * rgbToDepthFactorY;
372 float depthCx = model.
cx() * rgbToDepthFactorX;
373 float depthCy = model.
cy() * rgbToDepthFactorY;
375 UDEBUG(
"depth=%dx%d fx=%f fy=%f cx=%f cy=%f (depth factors=%f %f) decimation=%d",
376 imageDepth.cols, imageDepth.rows,
377 model.
fx(), model.
fy(), model.
cx(), model.
cy(),
383 for(
int h = 0; h < imageDepth.rows && h/decimation < (int)cloud->height; h+=decimation)
385 for(
int w = 0; w < imageDepth.cols && w/decimation < (int)cloud->width; w+=decimation)
387 pcl::PointXYZ & pt = cloud->at((h/decimation)*cloud->width + (w/decimation));
389 pcl::PointXYZ ptXYZ =
projectDepthTo3D(imageDepth, w, h, depthCx, depthCy, depthFx, depthFy,
false);
390 if(
pcl::isFinite(ptXYZ) && ptXYZ.z>=minDepth && (maxDepth<=0.0f || ptXYZ.z <= maxDepth))
397 validIndices->at(oi++) = (h/decimation)*cloud->width + (w/decimation);
402 pt.x = pt.y = pt.z = std::numeric_limits<float>::quiet_NaN();
409 validIndices->resize(oi);
416 const cv::Mat & imageRgb,
417 const cv::Mat & imageDepth,
423 std::vector<int> * validIndices)
426 return cloudFromDepthRGB(imageRgb, imageDepth, model, decimation, maxDepth, minDepth, validIndices);
430 const cv::Mat & imageRgb,
431 const cv::Mat & imageDepthIn,
436 std::vector<int> * validIndices)
438 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZRGB>);
450 UASSERT(!imageDepthIn.empty() && (imageDepthIn.type() == CV_16UC1 || imageDepthIn.type() == CV_32FC1));
453 if(imageRgb.rows % decimation != 0 || imageRgb.cols % decimation != 0)
455 int oldDecimation = decimation;
456 while(decimation <= -1)
458 if(imageRgb.rows % decimation == 0 && imageRgb.cols % decimation == 0)
465 if(imageRgb.rows % oldDecimation != 0 || imageRgb.cols % oldDecimation != 0)
467 UWARN(
"Decimation (%d) is not valid for current image size (rgb=%dx%d). Highest compatible decimation used=%d.", oldDecimation, imageRgb.cols, imageRgb.rows, decimation);
473 if(imageDepthIn.rows % decimation != 0 || imageDepthIn.cols % decimation != 0)
475 int oldDecimation = decimation;
476 while(decimation >= 1)
478 if(imageDepthIn.rows % decimation == 0 && imageDepthIn.cols % decimation == 0)
485 if(imageDepthIn.rows % oldDecimation != 0 || imageDepthIn.cols % oldDecimation != 0)
487 UWARN(
"Decimation (%d) is not valid for current image size (depth=%dx%d). Highest compatible decimation used=%d.", oldDecimation, imageDepthIn.cols, imageDepthIn.rows, decimation);
492 cv::Mat imageDepth = imageDepthIn;
495 UDEBUG(
"Decimation from RGB image (%d)", decimation);
497 decimation = -1*decimation;
499 int targetSize = imageRgb.rows / decimation;
500 if(targetSize > imageDepthIn.rows)
502 UDEBUG(
"Depth interpolation factor=%d", targetSize/imageDepthIn.rows);
506 else if(targetSize == imageDepthIn.rows)
512 UASSERT(imageDepthIn.rows % targetSize == 0);
513 decimation = imageDepthIn.rows / targetSize;
518 if(imageRgb.channels() == 3)
522 else if(imageRgb.channels() == 1)
532 cloud->height = imageDepth.rows/decimation;
533 cloud->width = imageDepth.cols/decimation;
534 cloud->is_dense =
false;
535 cloud->resize(cloud->height * cloud->width);
538 validIndices->resize(cloud->size());
541 float rgbToDepthFactorX = float(imageRgb.cols) / float(imageDepth.cols);
542 float rgbToDepthFactorY = float(imageRgb.rows) / float(imageDepth.rows);
543 float depthFx = model.
fx() / rgbToDepthFactorX;
544 float depthFy = model.
fy() / rgbToDepthFactorY;
545 float depthCx = model.
cx() / rgbToDepthFactorX;
546 float depthCy = model.
cy() / rgbToDepthFactorY;
548 UDEBUG(
"rgb=%dx%d depth=%dx%d fx=%f fy=%f cx=%f cy=%f (depth factors=%f %f) decimation=%d",
549 imageRgb.cols, imageRgb.rows,
550 imageDepth.cols, imageDepth.rows,
551 model.
fx(), model.
fy(), model.
cx(), model.
cy(),
557 for(
int h = 0; h < imageDepth.rows && h/decimation < (int)cloud->height; h+=decimation)
559 for(
int w = 0; w < imageDepth.cols && w/decimation < (int)cloud->width; w+=decimation)
561 pcl::PointXYZRGB & pt = cloud->at((h/decimation)*cloud->width + (w/decimation));
563 int x = int(w*rgbToDepthFactorX);
564 int y = int(h*rgbToDepthFactorY);
565 UASSERT(x >=0 && x<imageRgb.cols && y >=0 && y<imageRgb.rows);
568 const unsigned char * bgr = imageRgb.ptr<
unsigned char>(y,x);
575 unsigned char v = imageRgb.at<
unsigned char>(y,x);
581 pcl::PointXYZ ptXYZ =
projectDepthTo3D(imageDepth, w, h, depthCx, depthCy, depthFx, depthFy,
false);
582 if (
pcl::isFinite(ptXYZ) && ptXYZ.z >= minDepth && (maxDepth <= 0.0f || ptXYZ.z <= maxDepth))
589 validIndices->at(oi) = (h / decimation)*cloud->width + (w / decimation);
595 pt.x = pt.y = pt.z = std::numeric_limits<float>::quiet_NaN();
601 validIndices->resize(oi);
605 UWARN(
"Cloud with only NaN values created!");
612 const cv::Mat & imageDisparity,
617 std::vector<int> * validIndices)
619 UASSERT(imageDisparity.type() == CV_32FC1 || imageDisparity.type()==CV_16SC1);
622 if(imageDisparity.rows % decimation != 0 || imageDisparity.cols % decimation != 0)
624 int oldDecimation = decimation;
625 while(decimation >= 1)
627 if(imageDisparity.rows % decimation == 0 && imageDisparity.cols % decimation == 0)
634 if(imageDisparity.rows % oldDecimation != 0 || imageDisparity.cols % oldDecimation != 0)
636 UWARN(
"Decimation (%d) is not valid for current image size (depth=%dx%d). Highest compatible decimation used=%d.", oldDecimation, imageDisparity.cols, imageDisparity.rows, decimation);
640 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
643 cloud->height = imageDisparity.rows/decimation;
644 cloud->width = imageDisparity.cols/decimation;
645 cloud->is_dense =
false;
646 cloud->resize(cloud->height * cloud->width);
649 validIndices->resize(cloud->size());
653 if(imageDisparity.type()==CV_16SC1)
655 for(
int h = 0; h < imageDisparity.rows && h/decimation < (int)cloud->height; h+=decimation)
657 for(
int w = 0; w < imageDisparity.cols && w/decimation < (int)cloud->width; w+=decimation)
659 float disp = float(imageDisparity.at<
short>(h,w))/16.0f;
661 if(pt.z >= minDepth && (maxDepth <= 0.0f || pt.z <= maxDepth))
663 cloud->at((h/decimation)*cloud->width + (w/decimation)) = pcl::PointXYZ(pt.x, pt.y, pt.z);
666 validIndices->at(oi++) = (h/decimation)*cloud->width + (w/decimation);
671 cloud->at((h/decimation)*cloud->width + (w/decimation)) = pcl::PointXYZ(
672 std::numeric_limits<float>::quiet_NaN(),
673 std::numeric_limits<float>::quiet_NaN(),
674 std::numeric_limits<float>::quiet_NaN());
681 for(
int h = 0; h < imageDisparity.rows && h/decimation < (int)cloud->height; h+=decimation)
683 for(
int w = 0; w < imageDisparity.cols && w/decimation < (int)cloud->width; w+=decimation)
685 float disp = imageDisparity.at<
float>(h,w);
687 if(pt.z > minDepth && (maxDepth <= 0.0f || pt.z <= maxDepth))
689 cloud->at((h/decimation)*cloud->width + (w/decimation)) = pcl::PointXYZ(pt.x, pt.y, pt.z);
692 validIndices->at(oi++) = (h/decimation)*cloud->width + (w/decimation);
697 cloud->at((h/decimation)*cloud->width + (w/decimation)) = pcl::PointXYZ(
698 std::numeric_limits<float>::quiet_NaN(),
699 std::numeric_limits<float>::quiet_NaN(),
700 std::numeric_limits<float>::quiet_NaN());
707 validIndices->resize(oi);
713 const cv::Mat & imageRgb,
714 const cv::Mat & imageDisparity,
719 std::vector<int> * validIndices)
721 UASSERT(!imageRgb.empty() && !imageDisparity.empty());
722 UASSERT(imageRgb.rows == imageDisparity.rows &&
723 imageRgb.cols == imageDisparity.cols &&
724 (imageDisparity.type() == CV_32FC1 || imageDisparity.type()==CV_16SC1));
725 UASSERT(imageRgb.channels() == 3 || imageRgb.channels() == 1);
728 if(imageDisparity.rows % decimation != 0 || imageDisparity.cols % decimation != 0)
730 int oldDecimation = decimation;
731 while(decimation >= 1)
733 if(imageDisparity.rows % decimation == 0 && imageDisparity.cols % decimation == 0)
740 if(imageDisparity.rows % oldDecimation != 0 || imageDisparity.cols % oldDecimation != 0)
742 UWARN(
"Decimation (%d) is not valid for current image size (depth=%dx%d). Highest compatible decimation used=%d.", oldDecimation, imageDisparity.cols, imageDisparity.rows, decimation);
746 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZRGB>);
749 if(imageRgb.channels() == 3)
759 cloud->height = imageRgb.rows/decimation;
760 cloud->width = imageRgb.cols/decimation;
761 cloud->is_dense =
false;
762 cloud->resize(cloud->height * cloud->width);
765 validIndices->resize(cloud->size());
769 for(
int h = 0; h < imageRgb.rows && h/decimation < (int)cloud->height; h+=decimation)
771 for(
int w = 0; w < imageRgb.cols && w/decimation < (int)cloud->width; w+=decimation)
773 pcl::PointXYZRGB & pt = cloud->at((h/decimation)*cloud->width + (w/decimation));
776 pt.b = imageRgb.at<cv::Vec3b>(h,w)[0];
777 pt.g = imageRgb.at<cv::Vec3b>(h,w)[1];
778 pt.r = imageRgb.at<cv::Vec3b>(h,w)[2];
782 unsigned char v = imageRgb.at<
unsigned char>(h,w);
788 float disp = imageDisparity.type()==CV_16SC1?float(imageDisparity.at<
short>(h,w))/16.0f:imageDisparity.at<
float>(h,w);
790 if(
util3d::isFinite(ptXYZ) && ptXYZ.z >= minDepth && (maxDepth<=0.0f || ptXYZ.z <= maxDepth))
797 validIndices->at(oi++) = (h/decimation)*cloud->width + (w/decimation);
802 pt.x = pt.y = pt.z = std::numeric_limits<float>::quiet_NaN();
808 validIndices->resize(oi);
814 const cv::Mat & imageLeft,
815 const cv::Mat & imageRight,
820 std::vector<int> * validIndices,
823 UASSERT(!imageLeft.empty() && !imageRight.empty());
824 UASSERT(imageRight.type() == CV_8UC1);
825 UASSERT(imageLeft.channels() == 3 || imageLeft.channels() == 1);
826 UASSERT(imageLeft.rows == imageRight.rows &&
827 imageLeft.cols == imageRight.cols);
830 cv::Mat leftColor = imageLeft;
831 cv::Mat rightMono = imageRight;
834 if(leftColor.channels() == 3)
836 cv::cvtColor(leftColor, leftMono, CV_BGR2GRAY);
840 leftMono = leftColor;
858 std::vector<int> * validIndices,
860 const std::vector<float> & roiRatios)
867 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
874 for(
unsigned int i=0; i<sensorData.
cameraModels().size(); ++i)
878 cv::Mat depth = cv::Mat(sensorData.
depthRaw(), cv::Rect(subImageWidth*i, 0, subImageWidth, sensorData.
depthRaw().rows));
880 if( roiRatios.size() == 4 &&
881 (roiRatios[0] > 0.0f ||
882 roiRatios[1] > 0.0f ||
883 roiRatios[2] > 0.0f ||
884 roiRatios[3] > 0.0f))
892 if( roiDepth.width%decimation==0 &&
893 roiDepth.height%decimation==0 &&
894 (roiRgb.width != 0 ||
895 (roiRgb.width%decimation==0 &&
896 roiRgb.height%decimation==0)))
898 depth = cv::Mat(depth, roiDepth);
905 model = model.
roi(roiDepth);
910 UERROR(
"Cannot apply ROI ratios [%f,%f,%f,%f] because resulting " 911 "dimension (depth=%dx%d rgb=%dx%d) cannot be divided exactly " 912 "by decimation parameter (%d). Ignoring ROI ratios...",
953 UERROR(
"Camera model %d is invalid", i);
963 if(sensorData.
imageRaw().channels() == 3)
965 cv::cvtColor(sensorData.
imageRaw(), leftMono, CV_BGR2GRAY);
979 cv::Mat left(leftMono, cv::Rect(subImageWidth*i, 0, subImageWidth, leftMono.rows));
980 cv::Mat right(sensorData.
rightRaw(), cv::Rect(subImageWidth*i, 0, subImageWidth, sensorData.
rightRaw().rows));
982 if( roiRatios.size() == 4 &&
983 ((roiRatios[0] > 0.0f && roiRatios[0] <= 1.0f) ||
984 (roiRatios[1] > 0.0
f && roiRatios[1] <= 1.0
f) ||
985 (roiRatios[2] > 0.0f && roiRatios[2] <= 1.0f) ||
986 (roiRatios[3] > 0.0
f && roiRatios[3] <= 1.0
f)))
989 if( roi.width%decimation==0 &&
990 roi.height%decimation==0)
992 left = cv::Mat(left, roi);
993 right = cv::Mat(right, roi);
998 UERROR(
"Cannot apply ROI ratios [%f,%f,%f,%f] because resulting " 999 "dimension (left=%dx%d) cannot be divided exactly " 1000 "by decimation parameter (%d). Ignoring ROI ratios...",
1039 UERROR(
"Stereo camera model %d is invalid", i);
1044 if(!cloud->empty() && cloud->is_dense && validIndices)
1047 validIndices->resize(cloud->size());
1048 for(
unsigned int i=0; i<cloud->size(); ++i)
1050 validIndices->at(i) = i;
1061 std::vector<int> * validIndices,
1063 const std::vector<float> & roiRatios)
1070 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZRGB>);
1083 for(
unsigned int i=0; i<sensorData.
cameraModels().size(); ++i)
1085 if(sensorData.
cameraModels()[i].isValidForProjection())
1087 cv::Mat rgb(sensorData.
imageRaw(), cv::Rect(subRGBWidth*i, 0, subRGBWidth, sensorData.
imageRaw().rows));
1088 cv::Mat depth(sensorData.
depthRaw(), cv::Rect(subDepthWidth*i, 0, subDepthWidth, sensorData.
depthRaw().rows));
1090 if( roiRatios.size() == 4 &&
1091 ((roiRatios[0] > 0.0f && roiRatios[0] <= 1.0f) ||
1092 (roiRatios[1] > 0.0
f && roiRatios[1] <= 1.0
f) ||
1093 (roiRatios[2] > 0.0f && roiRatios[2] <= 1.0f) ||
1094 (roiRatios[3] > 0.0
f && roiRatios[3] <= 1.0
f)))
1098 if( roiDepth.width%decimation==0 &&
1099 roiDepth.height%decimation==0 &&
1100 roiRgb.width%decimation==0 &&
1101 roiRgb.height%decimation==0)
1103 depth = cv::Mat(depth, roiDepth);
1104 rgb = cv::Mat(rgb, roiRgb);
1105 model = model.
roi(roiRgb);
1109 UERROR(
"Cannot apply ROI ratios [%f,%f,%f,%f] because resulting " 1110 "dimension (depth=%dx%d rgb=%dx%d) cannot be divided exactly " 1111 "by decimation parameter (%d). Ignoring ROI ratios...",
1153 UERROR(
"Camera model %d is invalid", i);
1169 cv::Mat left(sensorData.
imageRaw(), cv::Rect(subImageWidth*i, 0, subImageWidth, sensorData.
imageRaw().rows));
1170 cv::Mat right(sensorData.
rightRaw(), cv::Rect(subImageWidth*i, 0, subImageWidth, sensorData.
rightRaw().rows));
1172 if( roiRatios.size() == 4 &&
1173 ((roiRatios[0] > 0.0f && roiRatios[0] <= 1.0f) ||
1174 (roiRatios[1] > 0.0
f && roiRatios[1] <= 1.0
f) ||
1175 (roiRatios[2] > 0.0f && roiRatios[2] <= 1.0f) ||
1176 (roiRatios[3] > 0.0
f && roiRatios[3] <= 1.0
f)))
1179 if( roi.width%decimation==0 &&
1180 roi.height%decimation==0)
1182 left = cv::Mat(left, roi);
1183 right = cv::Mat(right, roi);
1188 UERROR(
"Cannot apply ROI ratios [%f,%f,%f,%f] because resulting " 1189 "dimension (left=%dx%d) cannot be divided exactly " 1190 "by decimation parameter (%d). Ignoring ROI ratios...",
1231 UERROR(
"Stereo camera model %d is invalid", i);
1236 if(cloud->is_dense && validIndices)
1239 validIndices->resize(cloud->size());
1240 for(
unsigned int i=0; i<cloud->size(); ++i)
1242 validIndices->at(i) = i;
1250 const cv::Mat & depthImage,
1259 UASSERT(depthImage.type() == CV_16UC1 || depthImage.type() == CV_32FC1);
1262 pcl::PointCloud<pcl::PointXYZ> scan;
1263 int middle = depthImage.rows/2;
1266 scan.resize(depthImage.cols);
1268 for(
int i=depthImage.cols-1; i>=0; --i)
1271 if(
pcl::isFinite(pt) && pt.z >= minDepth && (maxDepth == 0 || pt.z < maxDepth))
1286 const cv::Mat & depthImages,
1287 const std::vector<CameraModel> & cameraModels,
1291 pcl::PointCloud<pcl::PointXYZ> scan;
1292 UASSERT(
int((depthImages.cols/cameraModels.size())*cameraModels.size()) == depthImages.cols);
1293 int subImageWidth = depthImages.cols/cameraModels.size();
1294 for(
int i=(
int)cameraModels.size()-1; i>=0; --i)
1296 if(cameraModels[i].isValidForProjection())
1298 cv::Mat depth = cv::Mat(depthImages, cv::Rect(subImageWidth*i, 0, subImageWidth, depthImages.rows));
1302 cameraModels[i].fx(),
1303 cameraModels[i].fy(),
1304 cameraModels[i].cx(),
1305 cameraModels[i].cy(),
1308 cameraModels[i].localTransform());
1312 UERROR(
"Camera model %d is invalid", i);
1326 Eigen::Affine3f transform3f = transform.
toEigen3f();
1330 laserScan = cv::Mat(1, (
int)indices->size(), CV_32FC3);
1331 for(
unsigned int i=0; i<indices->size(); ++i)
1333 int index = indices->at(i);
1336 float * ptr = laserScan.ptr<
float>(0, oi++);
1346 ptr[0] = cloud.at(index).x;
1347 ptr[1] = cloud.at(index).y;
1348 ptr[2] = cloud.at(index).z;
1355 laserScan = cv::Mat(1, (
int)cloud.size(), CV_32FC3);
1356 for(
unsigned int i=0; i<cloud.size(); ++i)
1360 float * ptr = laserScan.ptr<
float>(0, oi++);
1370 ptr[0] = cloud.at(i).x;
1371 ptr[1] = cloud.at(i).y;
1372 ptr[2] = cloud.at(i).z;
1395 laserScan = cv::Mat(1, (
int)indices->size(), CV_32FC(6));
1396 for(
unsigned int i=0; i<indices->size(); ++i)
1398 int index = indices->at(i);
1404 float * ptr = laserScan.ptr<
float>(0, oi++);
1411 ptr[3] = pt.normal_x;
1412 ptr[4] = pt.normal_y;
1413 ptr[5] = pt.normal_z;
1417 ptr[0] = cloud.at(index).x;
1418 ptr[1] = cloud.at(index).y;
1419 ptr[2] = cloud.at(index).z;
1420 ptr[3] = cloud.at(index).normal_x;
1421 ptr[4] = cloud.at(index).normal_y;
1422 ptr[5] = cloud.at(index).normal_z;
1429 laserScan = cv::Mat(1, (
int)cloud.size(), CV_32FC(6));
1430 for(
unsigned int i=0; i<cloud.size(); ++i)
1437 float * ptr = laserScan.ptr<
float>(0, oi++);
1444 ptr[3] = pt.normal_x;
1445 ptr[4] = pt.normal_y;
1446 ptr[5] = pt.normal_z;
1450 ptr[0] = cloud.at(i).x;
1451 ptr[1] = cloud.at(i).y;
1452 ptr[2] = cloud.at(i).z;
1453 ptr[3] = cloud.at(i).normal_x;
1454 ptr[4] = cloud.at(i).normal_y;
1455 ptr[5] = cloud.at(i).normal_z;
1469 UASSERT(cloud.size() == normals.size());
1470 cv::Mat laserScan = cv::Mat(1, (
int)cloud.size(), CV_32FC(6));
1473 for(
unsigned int i=0; i<cloud.size(); ++i)
1477 float * ptr = laserScan.ptr<
float>(0, oi++);
1480 pcl::PointNormal pt;
1481 pt.x = cloud.at(i).x;
1482 pt.y = cloud.at(i).y;
1483 pt.z = cloud.at(i).z;
1484 pt.normal_x = normals.at(i).normal_x;
1485 pt.normal_y = normals.at(i).normal_y;
1486 pt.normal_z = normals.at(i).normal_z;
1491 ptr[3] = pt.normal_x;
1492 ptr[4] = pt.normal_y;
1493 ptr[5] = pt.normal_z;
1497 ptr[0] = cloud.at(i).x;
1498 ptr[1] = cloud.at(i).y;
1499 ptr[2] = cloud.at(i).z;
1500 ptr[3] = normals.at(i).normal_x;
1501 ptr[4] = normals.at(i).normal_y;
1502 ptr[5] = normals.at(i).normal_z;
1522 Eigen::Affine3f transform3f = transform.
toEigen3f();
1526 laserScan = cv::Mat(1, (
int)indices->size(), CV_32FC(4));
1527 for(
unsigned int i=0; i<indices->size(); ++i)
1529 int index = indices->at(i);
1532 float * ptr = laserScan.ptr<
float>(0, oi++);
1542 ptr[0] = cloud.at(index).x;
1543 ptr[1] = cloud.at(index).y;
1544 ptr[2] = cloud.at(index).z;
1546 int * ptrInt = (
int*)ptr;
1547 ptrInt[3] = int(cloud.at(index).b) | (
int(cloud.at(index).g) << 8) | (int(cloud.at(index).r) << 16);
1553 laserScan = cv::Mat(1, (
int)cloud.size(), CV_32FC(4));
1554 for(
unsigned int i=0; i<cloud.size(); ++i)
1558 float * ptr = laserScan.ptr<
float>(0, oi++);
1568 ptr[0] = cloud.at(i).x;
1569 ptr[1] = cloud.at(i).y;
1570 ptr[2] = cloud.at(i).z;
1572 int * ptrInt = (
int*)ptr;
1573 ptrInt[3] = int(cloud.at(i).b) | (
int(cloud.at(i).g) << 8) | (int(cloud.at(i).r) << 16);
1593 Eigen::Affine3f transform3f = transform.
toEigen3f();
1597 laserScan = cv::Mat(1, (
int)indices->size(), CV_32FC(4));
1598 for(
unsigned int i=0; i<indices->size(); ++i)
1600 int index = indices->at(i);
1603 float * ptr = laserScan.ptr<
float>(0, oi++);
1613 ptr[0] = cloud.at(index).x;
1614 ptr[1] = cloud.at(index).y;
1615 ptr[2] = cloud.at(index).z;
1617 ptr[3] = cloud.at(index).intensity;
1623 laserScan = cv::Mat(1, (
int)cloud.size(), CV_32FC(4));
1624 for(
unsigned int i=0; i<cloud.size(); ++i)
1628 float * ptr = laserScan.ptr<
float>(0, oi++);
1638 ptr[0] = cloud.at(i).x;
1639 ptr[1] = cloud.at(i).y;
1640 ptr[2] = cloud.at(i).z;
1642 ptr[3] = cloud.at(i).intensity;
1655 UASSERT(cloud.size() == normals.size());
1656 cv::Mat laserScan(1, (
int)cloud.size(), CV_32FC(7));
1659 for(
unsigned int i=0; i<cloud.size(); ++i)
1663 float * ptr = laserScan.ptr<
float>(0, oi++);
1666 pcl::PointXYZRGBNormal pt;
1667 pt.x = cloud.at(i).x;
1668 pt.y = cloud.at(i).y;
1669 pt.z = cloud.at(i).z;
1670 pt.normal_x = normals.at(i).normal_x;
1671 pt.normal_y = normals.at(i).normal_y;
1672 pt.normal_z = normals.at(i).normal_z;
1677 ptr[4] = pt.normal_x;
1678 ptr[5] = pt.normal_y;
1679 ptr[6] = pt.normal_z;
1683 ptr[0] = cloud.at(i).x;
1684 ptr[1] = cloud.at(i).y;
1685 ptr[2] = cloud.at(i).z;
1686 ptr[4] = normals.at(i).normal_x;
1687 ptr[5] = normals.at(i).normal_y;
1688 ptr[6] = normals.at(i).normal_z;
1690 int * ptrInt = (
int*)ptr;
1691 ptrInt[3] = int(cloud.at(i).b) | (
int(cloud.at(i).g) << 8) | (int(cloud.at(i).r) << 16);
1712 laserScan = cv::Mat(1, (
int)indices->size(), CV_32FC(7));
1713 for(
unsigned int i=0; i<indices->size(); ++i)
1715 int index = indices->at(i);
1721 float * ptr = laserScan.ptr<
float>(0, oi++);
1728 ptr[4] = pt.normal_x;
1729 ptr[5] = pt.normal_y;
1730 ptr[6] = pt.normal_z;
1734 ptr[0] = cloud.at(index).x;
1735 ptr[1] = cloud.at(index).y;
1736 ptr[2] = cloud.at(index).z;
1737 ptr[4] = cloud.at(index).normal_x;
1738 ptr[5] = cloud.at(index).normal_y;
1739 ptr[6] = cloud.at(index).normal_z;
1741 int * ptrInt = (
int*)ptr;
1742 ptrInt[3] = int(cloud.at(index).b) | (
int(cloud.at(index).g) << 8) | (int(cloud.at(index).r) << 16);
1748 laserScan = cv::Mat(1, (
int)cloud.size(), CV_32FC(7));
1749 for(
unsigned int i=0; i<cloud.size(); ++i)
1756 float * ptr = laserScan.ptr<
float>(0, oi++);
1763 ptr[4] = pt.normal_x;
1764 ptr[5] = pt.normal_y;
1765 ptr[6] = pt.normal_z;
1769 ptr[0] = cloud.at(i).x;
1770 ptr[1] = cloud.at(i).y;
1771 ptr[2] = cloud.at(i).z;
1772 ptr[4] = cloud.at(i).normal_x;
1773 ptr[5] = cloud.at(i).normal_y;
1774 ptr[6] = cloud.at(i).normal_z;
1776 int * ptrInt = (
int*)ptr;
1777 ptrInt[3] = int(cloud.at(i).b) | (
int(cloud.at(i).g) << 8) | (int(cloud.at(i).r) << 16);
1790 UASSERT(cloud.size() == normals.size());
1791 cv::Mat laserScan(1, (
int)cloud.size(), CV_32FC(7));
1794 for(
unsigned int i=0; i<cloud.size(); ++i)
1798 float * ptr = laserScan.ptr<
float>(0, oi++);
1801 pcl::PointXYZINormal pt;
1802 pt.x = cloud.at(i).x;
1803 pt.y = cloud.at(i).y;
1804 pt.z = cloud.at(i).z;
1805 pt.normal_x = normals.at(i).normal_x;
1806 pt.normal_y = normals.at(i).normal_y;
1807 pt.normal_z = normals.at(i).normal_z;
1812 ptr[4] = pt.normal_x;
1813 ptr[5] = pt.normal_y;
1814 ptr[6] = pt.normal_z;
1818 ptr[0] = cloud.at(i).x;
1819 ptr[1] = cloud.at(i).y;
1820 ptr[2] = cloud.at(i).z;
1821 ptr[4] = normals.at(i).normal_x;
1822 ptr[5] = normals.at(i).normal_y;
1823 ptr[6] = normals.at(i).normal_z;
1825 ptr[3] = cloud.at(i).intensity;
1846 laserScan = cv::Mat(1, (
int)indices->size(), CV_32FC(7));
1847 for(
unsigned int i=0; i<indices->size(); ++i)
1849 int index = indices->at(i);
1855 float * ptr = laserScan.ptr<
float>(0, oi++);
1862 ptr[4] = pt.normal_x;
1863 ptr[5] = pt.normal_y;
1864 ptr[6] = pt.normal_z;
1868 ptr[0] = cloud.at(index).x;
1869 ptr[1] = cloud.at(index).y;
1870 ptr[2] = cloud.at(index).z;
1871 ptr[4] = cloud.at(index).normal_x;
1872 ptr[5] = cloud.at(index).normal_y;
1873 ptr[6] = cloud.at(index).normal_z;
1875 ptr[3] = cloud.at(i).intensity;
1881 laserScan = cv::Mat(1, (
int)cloud.size(), CV_32FC(7));
1882 for(
unsigned int i=0; i<cloud.size(); ++i)
1889 float * ptr = laserScan.ptr<
float>(0, oi++);
1896 ptr[4] = pt.normal_x;
1897 ptr[5] = pt.normal_y;
1898 ptr[6] = pt.normal_z;
1902 ptr[0] = cloud.at(i).x;
1903 ptr[1] = cloud.at(i).y;
1904 ptr[2] = cloud.at(i).z;
1905 ptr[4] = cloud.at(i).normal_x;
1906 ptr[5] = cloud.at(i).normal_y;
1907 ptr[6] = cloud.at(i).normal_z;
1909 ptr[3] = cloud.at(i).intensity;
1922 cv::Mat laserScan(1, (
int)cloud.size(), CV_32FC2);
1923 bool nullTransform = transform.
isNull();
1924 Eigen::Affine3f transform3f = transform.
toEigen3f();
1926 for(
unsigned int i=0; i<cloud.size(); ++i)
1930 float * ptr = laserScan.ptr<
float>(0, oi++);
1939 ptr[0] = cloud.at(i).x;
1940 ptr[1] = cloud.at(i).y;
1954 cv::Mat laserScan(1, (
int)cloud.size(), CV_32FC3);
1955 bool nullTransform = transform.
isNull();
1956 Eigen::Affine3f transform3f = transform.
toEigen3f();
1958 for(
unsigned int i=0; i<cloud.size(); ++i)
1962 float * ptr = laserScan.ptr<
float>(0, oi++);
1968 ptr[2] = pt.intensity;
1972 ptr[0] = cloud.at(i).x;
1973 ptr[1] = cloud.at(i).y;
1974 ptr[2] = cloud.at(i).intensity;
1988 cv::Mat laserScan(1, (
int)cloud.size(), CV_32FC(5));
1989 bool nullTransform = transform.
isNull();
1991 for(
unsigned int i=0; i<cloud.size(); ++i)
1998 float * ptr = laserScan.ptr<
float>(0, oi++);
2004 ptr[2] = pt.normal_x;
2005 ptr[3] = pt.normal_y;
2006 ptr[4] = pt.normal_z;
2010 const pcl::PointNormal & pt = cloud.at(i);
2013 ptr[2] = pt.normal_x;
2014 ptr[3] = pt.normal_y;
2015 ptr[4] = pt.normal_z;
2028 UASSERT(cloud.size() == normals.size());
2029 cv::Mat laserScan(1, (
int)cloud.size(), CV_32FC(5));
2032 for(
unsigned int i=0; i<cloud.size(); ++i)
2036 float * ptr = laserScan.ptr<
float>(0, oi++);
2039 pcl::PointNormal pt;
2040 pt.x = cloud.at(i).x;
2041 pt.y = cloud.at(i).y;
2042 pt.z = cloud.at(i).z;
2043 pt.normal_x = normals.at(i).normal_x;
2044 pt.normal_y = normals.at(i).normal_y;
2045 pt.normal_z = normals.at(i).normal_z;
2049 ptr[2] = pt.normal_x;
2050 ptr[3] = pt.normal_y;
2051 ptr[4] = pt.normal_z;
2055 ptr[0] = cloud.at(i).x;
2056 ptr[1] = cloud.at(i).y;
2057 ptr[2] = normals.at(i).normal_x;
2058 ptr[3] = normals.at(i).normal_y;
2059 ptr[4] = normals.at(i).normal_z;
2072 cv::Mat laserScan(1, (
int)cloud.size(), CV_32FC(6));
2073 bool nullTransform = transform.
isNull();
2075 for(
unsigned int i=0; i<cloud.size(); ++i)
2082 float * ptr = laserScan.ptr<
float>(0, oi++);
2088 ptr[2] = pt.intensity;
2089 ptr[3] = pt.normal_x;
2090 ptr[4] = pt.normal_y;
2091 ptr[5] = pt.normal_z;
2095 const pcl::PointXYZINormal & pt = cloud.at(i);
2098 ptr[2] = pt.intensity;
2099 ptr[3] = pt.normal_x;
2100 ptr[4] = pt.normal_y;
2101 ptr[5] = pt.normal_z;
2114 UASSERT(cloud.size() == normals.size());
2115 cv::Mat laserScan(1, (
int)cloud.size(), CV_32FC(6));
2118 for(
unsigned int i=0; i<cloud.size(); ++i)
2122 float * ptr = laserScan.ptr<
float>(0, oi++);
2125 pcl::PointXYZINormal pt;
2126 pt.x = cloud.at(i).x;
2127 pt.y = cloud.at(i).y;
2128 pt.z = cloud.at(i).z;
2129 pt.normal_x = normals.at(i).normal_x;
2130 pt.normal_y = normals.at(i).normal_y;
2131 pt.normal_z = normals.at(i).normal_z;
2135 ptr[2] = pt.intensity;
2136 ptr[3] = pt.normal_x;
2137 ptr[4] = pt.normal_y;
2138 ptr[5] = pt.normal_z;
2142 ptr[0] = cloud.at(i).x;
2143 ptr[1] = cloud.at(i).y;
2144 ptr[2] = cloud.at(i).intensity;
2145 ptr[3] = normals.at(i).normal_x;
2146 ptr[4] = normals.at(i).normal_y;
2147 ptr[5] = normals.at(i).normal_z;
2160 pcl::PCLPointCloud2::Ptr cloud(
new pcl::PCLPointCloud2);
2192 UERROR(
"Unknown conversion from LaserScan format %d to PointCloud2.", laserScan.
format());
2199 pcl::PointCloud<pcl::PointXYZ>::Ptr output(
new pcl::PointCloud<pcl::PointXYZ>);
2200 output->resize(laserScan.
size());
2201 output->is_dense =
true;
2202 bool nullTransform = transform.
isNull();
2203 Eigen::Affine3f transform3f = transform.
toEigen3f();
2204 for(
int i=0; i<laserScan.
size(); ++i)
2217 pcl::PointCloud<pcl::PointNormal>::Ptr output(
new pcl::PointCloud<pcl::PointNormal>);
2218 output->resize(laserScan.
size());
2219 output->is_dense =
true;
2220 bool nullTransform = transform.
isNull();
2221 for(
int i=0; i<laserScan.
size(); ++i)
2234 pcl::PointCloud<pcl::PointXYZRGB>::Ptr output(
new pcl::PointCloud<pcl::PointXYZRGB>);
2235 output->resize(laserScan.
size());
2236 output->is_dense =
true;
2238 Eigen::Affine3f transform3f = transform.
toEigen3f();
2239 for(
int i=0; i<laserScan.
size(); ++i)
2252 pcl::PointCloud<pcl::PointXYZI>::Ptr output(
new pcl::PointCloud<pcl::PointXYZI>);
2253 output->resize(laserScan.
size());
2254 output->is_dense =
true;
2256 Eigen::Affine3f transform3f = transform.
toEigen3f();
2257 for(
int i=0; i<laserScan.
size(); ++i)
2270 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr output(
new pcl::PointCloud<pcl::PointXYZRGBNormal>);
2271 output->resize(laserScan.
size());
2272 output->is_dense =
true;
2274 for(
int i=0; i<laserScan.
size(); ++i)
2287 pcl::PointCloud<pcl::PointXYZINormal>::Ptr output(
new pcl::PointCloud<pcl::PointXYZINormal>);
2288 output->resize(laserScan.
size());
2289 output->is_dense =
true;
2291 for(
int i=0; i<laserScan.
size(); ++i)
2305 pcl::PointXYZ output;
2306 const float * ptr = laserScan.
data().ptr<
float>(0, index);
2309 if(!laserScan.
is2d())
2319 pcl::PointNormal output;
2320 const float * ptr = laserScan.
data().ptr<
float>(0, index);
2323 if(!laserScan.
is2d())
2330 output.normal_x = ptr[offset];
2331 output.normal_y = ptr[offset+1];
2332 output.normal_z = ptr[offset+2];
2340 pcl::PointXYZRGB output;
2341 const float * ptr = laserScan.
data().ptr<
float>(0, index);
2344 if(!laserScan.
is2d())
2351 int * ptrInt = (
int*)ptr;
2353 output.b = (
unsigned char)(ptrInt[indexRGB] & 0xFF);
2354 output.g = (
unsigned char)((ptrInt[indexRGB] >> 8) & 0xFF);
2355 output.r = (
unsigned char)((ptrInt[indexRGB] >> 16) & 0xFF);
2360 int * ptrInt = (
int*)ptr;
2362 output.r = (
unsigned char)(ptrInt[indexIntensity] & 0xFF);
2363 output.g = (
unsigned char)((ptrInt[indexIntensity] >> 8) & 0xFF);
2364 output.b = (
unsigned char)((ptrInt[indexIntensity] >> 16) & 0xFF);
2365 output.a = (
unsigned char)((ptrInt[indexIntensity] >> 24) & 0xFF);
2379 pcl::PointXYZI output;
2380 const float * ptr = laserScan.
data().ptr<
float>(0, index);
2383 if(!laserScan.
is2d())
2391 output.intensity = ptr[offset];
2395 output.intensity = intensity;
2404 pcl::PointXYZRGBNormal output;
2405 const float * ptr = laserScan.
data().ptr<
float>(0, index);
2408 if(!laserScan.
is2d())
2415 int * ptrInt = (
int*)ptr;
2417 output.b = (
unsigned char)(ptrInt[indexRGB] & 0xFF);
2418 output.g = (
unsigned char)((ptrInt[indexRGB] >> 8) & 0xFF);
2419 output.r = (
unsigned char)((ptrInt[indexRGB] >> 16) & 0xFF);
2423 int * ptrInt = (
int*)ptr;
2425 output.r = (
unsigned char)(ptrInt[indexIntensity] & 0xFF);
2426 output.g = (
unsigned char)((ptrInt[indexIntensity] >> 8) & 0xFF);
2427 output.b = (
unsigned char)((ptrInt[indexIntensity] >> 16) & 0xFF);
2428 output.a = (
unsigned char)((ptrInt[indexIntensity] >> 24) & 0xFF);
2440 output.normal_x = ptr[offset];
2441 output.normal_y = ptr[offset+1];
2442 output.normal_z = ptr[offset+2];
2451 pcl::PointXYZINormal output;
2452 const float * ptr = laserScan.
data().ptr<
float>(0, index);
2455 if(!laserScan.
is2d())
2463 output.intensity = ptr[offset];
2467 output.intensity = intensity;
2473 output.normal_x = ptr[offset];
2474 output.normal_y = ptr[offset+1];
2475 output.normal_z = ptr[offset+2];
2484 UASSERT(laserScan.type() == CV_32FC2 || laserScan.type() == CV_32FC3 || laserScan.type() == CV_32FC(4) || laserScan.type() == CV_32FC(5) || laserScan.type() == CV_32FC(6) || laserScan.type() == CV_32FC(7));
2486 const float * ptr = laserScan.ptr<
float>(0, 0);
2487 min.x = max.x = ptr[0];
2488 min.y = max.y = ptr[1];
2489 bool is3d = laserScan.channels() >= 3 && laserScan.channels() != 5;
2490 min.z = max.z = is3d?ptr[2]:0.0f;
2491 for(
int i=1; i<laserScan.cols; ++i)
2493 ptr = laserScan.ptr<
float>(0, i);
2495 if(ptr[0] < min.x) min.x = ptr[0];
2496 else if(ptr[0] > max.x) max.x = ptr[0];
2498 if(ptr[1] < min.y) min.y = ptr[1];
2499 else if(ptr[1] > max.y) max.y = ptr[1];
2503 if(ptr[2] < min.z) min.z = ptr[2];
2504 else if(ptr[2] > max.z) max.z = ptr[2];
2510 cv::Point3f minCV, maxCV;
2522 const cv::Point2f & pt,
2526 if(disparity > 0.0
f && model.
baseline() > 0.0f && model.
left().
fx() > 0.0f)
2534 float W = model.
baseline()/(disparity + c);
2535 return cv::Point3f((pt.x - model.
left().
cx())*W, (pt.y - model.
left().
cy())*W, model.
left().
fx()*W);
2537 float bad_point = std::numeric_limits<float>::quiet_NaN ();
2538 return cv::Point3f(bad_point, bad_point, bad_point);
2542 const cv::Point2f & pt,
2543 const cv::Mat & disparity,
2546 UASSERT(!disparity.empty() && (disparity.type() == CV_32FC1 || disparity.type() == CV_16SC1));
2547 int u = int(pt.x+0.5f);
2548 int v = int(pt.y+0.5f);
2549 float bad_point = std::numeric_limits<float>::quiet_NaN ();
2553 float d = disparity.type() == CV_16SC1?float(disparity.at<
short>(v,u))/16.0f:disparity.at<
float>(v,u);
2556 return cv::Point3f(bad_point, bad_point, bad_point);
2561 const cv::Size & imageSize,
2562 const cv::Mat & cameraMatrixK,
2563 const cv::Mat & laserScan,
2568 UASSERT(laserScan.type() == CV_32FC2 || laserScan.type() == CV_32FC3 || laserScan.type() == CV_32FC(4) || laserScan.type() == CV_32FC(5) || laserScan.type() == CV_32FC(6) || laserScan.type() == CV_32FC(7));
2569 UASSERT(cameraMatrixK.type() == CV_64FC1 && cameraMatrixK.cols == 3 && cameraMatrixK.cols == 3);
2571 float fx = cameraMatrixK.at<
double>(0,0);
2572 float fy = cameraMatrixK.at<
double>(1,1);
2573 float cx = cameraMatrixK.at<
double>(0,2);
2574 float cy = cameraMatrixK.at<
double>(1,2);
2576 cv::Mat registered = cv::Mat::zeros(imageSize, CV_32FC1);
2580 for(
int i=0; i<laserScan.cols; ++i)
2582 const float* ptr = laserScan.ptr<
float>(0, i);
2586 if(laserScan.type() == CV_32FC2 || laserScan.type() == CV_32FC(5))
2607 float invZ = 1.0f/z;
2608 float dx = (fx*ptScan.x)*invZ + cx;
2609 float dy = (fy*ptScan.y)*invZ + cy;
2612 int dx_high = dx + 0.5f;
2613 int dy_high = dy + 0.5f;
2617 float &zReg = registered.at<
float>(dy_low, dx_low);
2618 if(zReg == 0 || z < zReg)
2624 if((dx_low != dx_high || dy_low != dy_high) &&
2627 float &zReg = registered.at<
float>(dy_high, dx_high);
2628 if(zReg == 0 || z < zReg)
2640 UDEBUG(
"Points in camera=%d/%d", count, laserScan.cols);
2646 const cv::Size & imageSize,
2647 const cv::Mat & cameraMatrixK,
2648 const pcl::PointCloud<pcl::PointXYZ>::Ptr laserScan,
2653 UASSERT(cameraMatrixK.type() == CV_64FC1 && cameraMatrixK.cols == 3 && cameraMatrixK.cols == 3);
2655 float fx = cameraMatrixK.at<
double>(0,0);
2656 float fy = cameraMatrixK.at<
double>(1,1);
2657 float cx = cameraMatrixK.at<
double>(0,2);
2658 float cy = cameraMatrixK.at<
double>(1,2);
2660 cv::Mat registered = cv::Mat::zeros(imageSize, CV_32FC1);
2664 for(
int i=0; i<(int)laserScan->size(); ++i)
2667 pcl::PointXYZ ptScan = laserScan->at(i);
2675 float invZ = 1.0f/z;
2676 float dx = (fx*ptScan.x)*invZ + cx;
2677 float dy = (fy*ptScan.y)*invZ + cy;
2680 int dx_high = dx + 0.5f;
2681 int dy_high = dy + 0.5f;
2685 float &zReg = registered.at<
float>(dy_low, dx_low);
2686 if(zReg == 0 || z < zReg)
2691 if((dx_low != dx_high || dy_low != dy_high) &&
2695 float &zReg = registered.at<
float>(dy_high, dx_high);
2696 if(zReg == 0 || z < zReg)
2707 UDEBUG(
"Points in camera=%d/%d", count, (
int)laserScan->size());
2713 const cv::Size & imageSize,
2714 const cv::Mat & cameraMatrixK,
2715 const pcl::PCLPointCloud2::Ptr laserScan,
2719 UASSERT(!laserScan->data.empty());
2720 UASSERT(cameraMatrixK.type() == CV_64FC1 && cameraMatrixK.cols == 3 && cameraMatrixK.cols == 3);
2722 float fx = cameraMatrixK.at<
double>(0,0);
2723 float fy = cameraMatrixK.at<
double>(1,1);
2724 float cx = cameraMatrixK.at<
double>(0,2);
2725 float cy = cameraMatrixK.at<
double>(1,2);
2727 cv::Mat registered = cv::Mat::zeros(imageSize, CV_32FC1);
2730 pcl::MsgFieldMap field_map;
2731 pcl::createMapping<pcl::PointXYZ> (laserScan->fields, field_map);
2734 if(field_map.size() == 1)
2738 const uint8_t* row_data = &laserScan->data[
row * laserScan->row_step];
2741 const uint8_t* msg_data = row_data + col * laserScan->point_step;
2742 pcl::PointXYZ ptScan;
2743 memcpy (&ptScan, msg_data + field_map.front().serialized_offset, field_map.front().size);
2751 float invZ = 1.0f/z;
2752 float dx = (fx*ptScan.x)*invZ + cx;
2753 float dy = (fy*ptScan.y)*invZ + cy;
2756 int dx_high = dx + 0.5f;
2757 int dy_high = dy + 0.5f;
2761 float &zReg = registered.at<
float>(dy_low, dx_low);
2762 if(zReg == 0 || z < zReg)
2767 if((dx_low != dx_high || dy_low != dy_high) &&
2771 float &zReg = registered.at<
float>(dy_high, dx_high);
2772 if(zReg == 0 || z < zReg)
2787 UERROR(
"field map pcl::pointXYZ not found!");
2789 UDEBUG(
"Points in camera=%d/%d", count, (
int)laserScan->data.size());
2796 UASSERT(registeredDepth.type() == CV_32FC1);
2797 if(verticalDirection)
2800 for(
int x=0;
x<registeredDepth.cols; ++
x)
2802 float valueA = 0.0f;
2804 for(
int y=0; y<registeredDepth.rows; ++y)
2806 float v = registeredDepth.at<
float>(y,
x);
2807 if(fillToBorder && y == registeredDepth.rows-1 && v<=0.0f && indexA>=0)
2813 if(fillToBorder && indexA < 0)
2820 int range = y-indexA;
2823 float slope = (v-valueA)/(range);
2824 for(
int k=1; k<range; ++k)
2826 registeredDepth.at<
float>(indexA+k,
x) = valueA+slope*
float(k);
2839 for(
int y=0; y<registeredDepth.rows; ++y)
2841 float valueA = 0.0f;
2843 for(
int x=0;
x<registeredDepth.cols; ++
x)
2845 float v = registeredDepth.at<
float>(y,
x);
2846 if(fillToBorder &&
x == registeredDepth.cols-1 && v<=0.0f && indexA>=0)
2852 if(fillToBorder && indexA < 0)
2859 int range =
x-indexA;
2862 float slope = (v-valueA)/(range);
2863 for(
int k=1; k<range; ++k)
2865 registeredDepth.at<
float>(y,indexA+k) = valueA+slope*
float(k);
2894 template<
class Po
intT>
2896 const typename pcl::PointCloud<PointT> & cloud,
2897 const std::map<int, Transform> & cameraPoses,
2898 const std::map<
int, std::vector<CameraModel> > & cameraModels,
2901 const std::vector<float> & roiRatios,
2902 const cv::Mat & projMask,
2903 bool distanceToCamPolicy,
2906 UINFO(
"cloud=%d points", (
int)cloud.size());
2907 UINFO(
"cameraPoses=%d", (
int)cameraPoses.size());
2908 UINFO(
"cameraModels=%d", (
int)cameraModels.size());
2909 UINFO(
"maxDistance=%f", maxDistance);
2910 UINFO(
"maxAngle=%f", maxAngle);
2911 UINFO(
"distanceToCamPolicy=%s", distanceToCamPolicy?
"true":
"false");
2912 UINFO(
"roiRatios=%s", roiRatios.size() == 4?
uFormat(
"%f %f %f %f", roiRatios[0], roiRatios[1], roiRatios[2], roiRatios[3]).c_str():
"");
2913 UINFO(
"projMask=%dx%d", projMask.cols, projMask.rows);
2914 std::vector<std::pair< std::pair<int, int>, pcl::PointXY> > pointToPixel;
2916 if (cloud.empty() || cameraPoses.empty() || cameraModels.empty())
2917 return pointToPixel;
2919 std::string msg =
uFormat(
"Computing visible points per cam (%d points, %d cams)", (
int)cloud.size(), (int)cameraPoses.size());
2924 UWARN(
"Projecting to cameras cancelled!");
2925 return pointToPixel;
2928 std::vector<ProjectionInfo> invertedIndex(cloud.size());
2929 int cameraProcessed = 0;
2930 bool wrongMaskFormatWarned =
false;
2931 for(std::map<int, Transform>::const_iterator pter = cameraPoses.lower_bound(0); pter!=cameraPoses.end(); ++pter)
2933 std::map<int, std::vector<CameraModel> >::const_iterator iter=cameraModels.find(pter->first);
2934 if(iter!=cameraModels.end() && !iter->second.empty())
2936 cv::Mat validProjMask;
2937 if(!projMask.empty())
2939 if(projMask.type() != CV_8UC1)
2941 if(!wrongMaskFormatWarned)
2942 UERROR(
"Wrong camera projection mask type %d, should be CV_8UC1", projMask.type());
2943 wrongMaskFormatWarned =
true;
2945 else if(projMask.cols == iter->second[0].imageWidth() * (int)iter->second.size() &&
2946 projMask.rows == iter->second[0].imageHeight())
2948 validProjMask = projMask;
2952 UWARN(
"Camera projection mask (%dx%d) is not valid for current " 2953 "camera model(s) (count=%ld, image size=%dx%d). It will be " 2954 "ignored for node %d",
2955 projMask.cols, projMask.rows,
2956 iter->second.size(),
2957 iter->second[0].imageWidth(),
2958 iter->second[0].imageHeight(),
2963 for(
size_t camIndex=0; camIndex<iter->second.size(); ++camIndex)
2965 Transform cameraTransform = (pter->second * iter->second[camIndex].localTransform());
2967 cv::Mat cameraMatrixK = iter->second[camIndex].K();
2968 UASSERT(cameraMatrixK.type() == CV_64FC1 && cameraMatrixK.cols == 3 && cameraMatrixK.cols == 3);
2969 const cv::Size & imageSize = iter->second[camIndex].imageSize();
2971 float fx = cameraMatrixK.at<
double>(0,0);
2972 float fy = cameraMatrixK.at<
double>(1,1);
2973 float cx = cameraMatrixK.at<
double>(0,2);
2974 float cy = cameraMatrixK.at<
double>(1,2);
2977 cv::Mat registered = cv::Mat::zeros(imageSize, CV_32SC2);
2980 cv::Rect roi(0,0,imageSize.width, imageSize.height);
2981 if(roiRatios.size()==4)
2987 for(
size_t i=0; i<cloud.size(); ++i)
2990 PointT ptScan = cloud.at(i);
2996 if(z > 0.0
f && (maxDistance<=0 || z<maxDistance))
2998 float invZ = 1.0f/z;
2999 float dx = (fx*ptScan.x)*invZ + cx;
3000 float dy = (fy*ptScan.y)*invZ + cy;
3003 int dx_high = dx + 0.5f;
3004 int dy_high = dy + 0.5f;
3007 (validProjMask.empty() || validProjMask.at<
unsigned char>(dy_low, imageSize.width*camIndex+dx_low) > 0))
3010 cv::Vec2i &zReg = registered.at<cv::Vec2i>(dy_low, dx_low);
3011 if(zReg[0] == 0 || zMM < zReg[0])
3017 if((dx_low != dx_high || dy_low != dy_high) &&
3019 (validProjMask.empty() || validProjMask.at<
unsigned char>(dy_high, imageSize.width*camIndex+dx_high) > 0))
3022 cv::Vec2i &zReg = registered.at<cv::Vec2i>(dy_high, dx_high);
3023 if(zReg[0] == 0 || zMM < zReg[0])
3037 registered = cv::Mat();
3038 UINFO(
"No points projected in camera %d/%d", pter->first, camIndex);
3042 UDEBUG(
"%d points projected in camera %d/%d", count, pter->first, camIndex);
3044 for(
int u=0; u<registered.cols; ++u)
3046 for(
int v=0; v<registered.rows; ++v)
3048 cv::Vec2i &zReg = registered.at<cv::Vec2i>(v, u);
3052 info.
nodeID = pter->first;
3054 info.
uv.x = float(u)/float(imageSize.width);
3055 info.
uv.y = float(v)/float(imageSize.height);
3057 const PointT & pt = cloud.at(zReg[1]);
3058 Eigen::Vector4f camDir(cam.
x()-pt.x, cam.
y()-pt.y, cam.
z()-pt.z, 0);
3059 Eigen::Vector4f normal(pt.normal_x, pt.normal_y, pt.normal_z, 0);
3060 float angleToCam = maxAngle<=0?0:pcl::getAngle3D(normal, camDir);
3061 float distanceToCam = zReg[0]/1000.0f;
3062 if( (maxAngle<=0 || (camDir.dot(normal) > 0 && angleToCam < maxAngle)) &&
3063 (maxDistance<=0 || distanceToCam<maxDistance))
3065 float vx = info.
uv.x-0.5f;
3066 float vy = info.
uv.y-0.5f;
3068 float distanceToCenter = vx*vx+vy*vy;
3070 if(distanceToCamPolicy)
3072 distance = distanceToCam;
3077 if(invertedIndex[zReg[1]].distance != -1.0
f)
3079 if(distance <= invertedIndex[zReg[1]].distance)
3081 invertedIndex[zReg[1]] = info;
3086 invertedIndex[zReg[1]] = info;
3095 msg =
uFormat(
"Processed camera %d/%d", (
int)cameraProcessed+1, (
int)cameraPoses.size());
3100 UWARN(
"Projecting to cameras cancelled!");
3101 return pointToPixel;
3106 msg =
uFormat(
"Select best camera for %d points...", (
int)cloud.size());
3111 UWARN(
"Projecting to cameras cancelled!");
3112 return pointToPixel;
3115 pointToPixel.resize(invertedIndex.size());
3119 for(
size_t i=0; i<invertedIndex.size(); ++i)
3123 pcl::PointXY uv_coords;
3126 nodeID = invertedIndex[i].nodeID;
3127 cameraIndex = invertedIndex[i].cameraIndex;
3128 uv_coords = invertedIndex[i].uv;
3131 if(nodeID>-1 && cameraIndex> -1)
3133 pointToPixel[i].first.first =
nodeID;
3135 pointToPixel[i].second = uv_coords;
3140 msg =
uFormat(
"Process %d points...done! (%d [%d%%] projected in cameras)", (
int)cloud.size(), colorized, colorized*100/cloud.size());
3147 return pointToPixel;
3151 const typename pcl::PointCloud<pcl::PointXYZRGBNormal> & cloud,
3152 const std::map<int, Transform> & cameraPoses,
3153 const std::map<
int, std::vector<CameraModel> > & cameraModels,
3156 const std::vector<float> & roiRatios,
3157 const cv::Mat & projMask,
3158 bool distanceToCamPolicy,
3168 distanceToCamPolicy,
3173 const typename pcl::PointCloud<pcl::PointXYZINormal> & cloud,
3174 const std::map<int, Transform> & cameraPoses,
3175 const std::map<
int, std::vector<CameraModel> > & cameraModels,
3178 const std::vector<float> & roiRatios,
3179 const cv::Mat & projMask,
3180 bool distanceToCamPolicy,
3190 distanceToCamPolicy,
3199 pcl::PointCloud<pcl::PointXYZ>::Ptr
concatenateClouds(
const std::list<pcl::PointCloud<pcl::PointXYZ>::Ptr> & clouds)
3201 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
3202 for(std::list<pcl::PointCloud<pcl::PointXYZ>::Ptr>::const_iterator iter = clouds.begin(); iter!=clouds.end(); ++iter)
3209 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
concatenateClouds(
const std::list<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> & clouds)
3211 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZRGB>);
3212 for(std::list<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>::const_iterator iter = clouds.begin(); iter!=clouds.end(); ++iter)
3219 pcl::IndicesPtr
concatenate(
const std::vector<pcl::IndicesPtr> & indices)
3222 unsigned int totalSize = 0;
3223 for(
unsigned int i=0; i<indices.size(); ++i)
3225 totalSize += (
unsigned int)indices[i]->size();
3227 pcl::IndicesPtr ind(
new std::vector<int>(totalSize));
3228 unsigned int io = 0;
3229 for(
unsigned int i=0; i<indices.size(); ++i)
3231 for(
unsigned int j=0; j<indices[i]->size(); ++j)
3233 ind->at(io++) = indices[i]->at(j);
3239 pcl::IndicesPtr
concatenate(
const pcl::IndicesPtr & indicesA,
const pcl::IndicesPtr & indicesB)
3241 pcl::IndicesPtr ind(
new std::vector<int>(*indicesA));
3242 ind->resize(ind->size()+indicesB->size());
3243 unsigned int oi = (
unsigned int)indicesA->size();
3244 for(
unsigned int i=0; i<indicesB->size(); ++i)
3246 ind->at(oi++) = indicesB->at(i);
3252 const std::string & fileName,
3253 const std::multimap<int, pcl::PointXYZ> & words,
3258 pcl::PointCloud<pcl::PointXYZ> cloud;
3259 cloud.resize(words.size());
3261 for(std::multimap<int, pcl::PointXYZ>::const_iterator iter=words.begin(); iter!=words.end(); ++iter)
3265 pcl::io::savePCDFile(fileName, cloud);
3270 const std::string & fileName,
3271 const std::multimap<int, cv::Point3f> & words,
3276 pcl::PointCloud<pcl::PointXYZ> cloud;
3277 cloud.resize(words.size());
3279 for(std::multimap<int, cv::Point3f>::const_iterator iter=words.begin(); iter!=words.end(); ++iter)
3282 cloud[i++] = pcl::PointXYZ(pt.x, pt.y, pt.z);
3284 pcl::io::savePCDFile(fileName, cloud);
3295 UASSERT(bytes %
sizeof(
float) == 0);
3296 size_t num = bytes/
sizeof(float);
3298 output = cv::Mat(1, num/dim, CV_32FC(dim));
3302 stream = fopen (fileName.c_str(),
"rb");
3303 size_t actualReadNum = fread(output.data,
sizeof(
float),num,stream);
3304 UASSERT(num == actualReadNum);
3311 pcl::PointCloud<pcl::PointXYZ>::Ptr
loadBINCloud(
const std::string & fileName)
3316 pcl::PointCloud<pcl::PointXYZ>::Ptr
loadBINCloud(
const std::string & fileName,
int dim)
3330 pcl::PCLPointCloud2::Ptr cloud(
new pcl::PCLPointCloud2);
3334 pcl::io::loadPCDFile(path, *cloud);
3338 pcl::io::loadPLYFile(path, *cloud);
3340 if(cloud->height > 1)
3342 cloud->is_dense =
false;
3346 if(!cloud->data.empty())
3350 for(
unsigned int i=0; i<cloud->fields.size(); ++i)
3352 if(cloud->fields[i].name.compare(
"z") == 0)
3354 zOffset = cloud->fields[i].offset;
3363 const uint8_t* row_data = &cloud->data[
row * cloud->row_step];
3366 const uint8_t* msg_data = row_data + col * cloud->point_step;
3367 float z = *(
float*)(msg_data + zOffset);
3380 const std::string & path,
3386 UDEBUG(
"Loading cloud (step=%d, voxel=%f m) : %s", downsampleStep, voxelSize, path.c_str());
3388 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
3395 pcl::io::loadPCDFile(path, *cloud);
3399 pcl::io::loadPLYFile(path, *cloud);
3401 int previousSize = (int)cloud->size();
3402 if(downsampleStep > 1 && cloud->size())
3405 UDEBUG(
"Downsampling scan (step=%d): %d -> %d", downsampleStep, previousSize, (
int)cloud->size());
3407 previousSize = (int)cloud->size();
3408 if(voxelSize > 0.0
f && cloud->size())
3411 UDEBUG(
"Voxel filtering scan (voxel=%f m): %d -> %d", voxelSize, previousSize, (
int)cloud->size());
cv::Mat RTABMAP_EXP disparityFromStereoImages(const cv::Mat &leftImage, const cv::Mat &rightImage, const ParametersMap ¶meters=ParametersMap())
bool RTABMAP_EXP isFinite(const cv::Point3f &pt)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP cloudFromDisparity(const cv::Mat &imageDisparity, const StereoCameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0)
rtabmap::CameraThread * cam
pcl::PointNormal RTABMAP_EXP laserScanToPointNormal(const LaserScan &laserScan, int index)
const cv::Size & imageSize() const
cv::Point3f RTABMAP_EXP projectDisparityTo3D(const cv::Point2f &pt, float disparity, const StereoCameraModel &model)
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
cv::Point3f RTABMAP_EXP transformPoint(const cv::Point3f &pt, const Transform &transform)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP transformPointCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const Transform &transform)
void RTABMAP_EXP getMinMax3D(const cv::Mat &laserScan, cv::Point3f &min, cv::Point3f &max)
bool uIsInBounds(const T &value, const T &low, const T &high)
pcl::PointCloud< pcl::PointXYZRGBNormal >::Ptr RTABMAP_EXP laserScanToPointCloudRGBNormal(const LaserScan &laserScan, const Transform &transform=Transform(), unsigned char r=100, unsigned char g=100, unsigned char b=100)
pcl::PointXYZINormal RTABMAP_EXP laserScanToPointINormal(const LaserScan &laserScan, int index, float intensity)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP removeNaNFromPointCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud)
pcl::PCLPointCloud2::Ptr RTABMAP_EXP laserScanToPointCloud2(const LaserScan &laserScan, const Transform &transform=Transform())
GLM_FUNC_DECL bool all(vecType< bool, P > const &v)
const std::vector< StereoCameraModel > & stereoCameraModels() const
const cv::Mat & data() const
std::map< std::string, std::string > ParametersMap
GLM_FUNC_DECL genType::row_type row(genType const &m, length_t const &index)
pcl::PointXYZ RTABMAP_EXP laserScanToPoint(const LaserScan &laserScan, int index)
Basic mathematics functions.
int getNormalsOffset() const
Some conversion functions.
void RTABMAP_EXP savePCDWords(const std::string &fileName, const std::multimap< int, pcl::PointXYZ > &words, const Transform &transform=Transform::getIdentity())
std::string getExtension()
pcl::PointXYZRGBNormal RTABMAP_EXP laserScanToPointRGBNormal(const LaserScan &laserScan, int index, unsigned char r, unsigned char g, unsigned char b)
pcl::PointXYZRGB RTABMAP_EXP laserScanToPointRGB(const LaserScan &laserScan, int index, unsigned char r=100, unsigned char g=100, unsigned char b=100)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP laserScanToPointCloud(const LaserScan &laserScan, const Transform &transform=Transform())
pcl::PointCloud< pcl::PointXYZ > RTABMAP_EXP laserScanFromDepthImages(const cv::Mat &depthImages, const std::vector< CameraModel > &cameraModels, float maxDepth, float minDepth)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP cloudFromDepth(const cv::Mat &imageDepth, const CameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudFromDepthRGB(const cv::Mat &imageRgb, const cv::Mat &imageDepth, const CameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0)
cv::Mat RTABMAP_EXP interpolate(const cv::Mat &image, int factor, float depthErrorRatio=0.02f)
LaserScan RTABMAP_EXP downsample(const LaserScan &cloud, int step)
bool uIsFinite(const T &value)
#define UASSERT(condition)
pcl::PointXYZ RTABMAP_EXP projectDepthTo3D(const cv::Mat &depthImage, float x, float y, float cx, float cy, float fx, float fy, bool smoothing, float depthErrorRatio=0.02f)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP laserScanToPointCloudRGB(const LaserScan &laserScan, const Transform &transform=Transform(), unsigned char r=100, unsigned char g=100, unsigned char b=100)
const std::vector< CameraModel > & cameraModels() const
virtual bool callback(const std::string &msg) const
#define UASSERT_MSG(condition, msg_str)
pcl::PointCloud< pcl::PointXYZINormal >::Ptr RTABMAP_EXP laserScanToPointCloudINormal(const LaserScan &laserScan, const Transform &transform=Transform(), float intensity=0.0f)
const cv::Mat & imageRaw() const
std::vector< std::pair< std::pair< int, int >, pcl::PointXY > > RTABMAP_EXP projectCloudToCameras(const pcl::PointCloud< pcl::PointXYZRGBNormal > &cloud, const std::map< int, Transform > &cameraPoses, const std::map< int, std::vector< CameraModel > > &cameraModels, float maxDistance=0.0f, float maxAngle=0.0f, const std::vector< float > &roiRatios=std::vector< float >(), const cv::Mat &projMask=cv::Mat(), bool distanceToCamPolicy=false, const ProgressState *state=0)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudRGBFromSensorData(const SensorData &sensorData, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0, const ParametersMap &stereoParameters=ParametersMap(), const std::vector< float > &roiRatios=std::vector< float >())
GLM_FUNC_DECL genType abs(genType const &x)
cv::Rect RTABMAP_EXP computeRoi(const cv::Mat &image, const std::string &roiRatios)
CameraModel roi(const cv::Rect &roi) const
const Transform & localTransform() const
pcl::PointCloud< pcl::PointXYZ > RTABMAP_EXP laserScanFromDepthImage(const cv::Mat &depthImage, float fx, float fy, float cx, float cy, float maxDepth=0, float minDepth=0, const Transform &localTransform=Transform::getIdentity())
LaserScan laserScanFromPointCloud(const PointCloud2T &cloud, bool filterNaNs, bool is2D, const Transform &transform)
pcl::PointXYZI RTABMAP_EXP laserScanToPointI(const LaserScan &laserScan, int index, float intensity)
void roi(const cv::Rect &roi)
int getIntensityOffset() const
RecoveryProgressState state
cv::Mat bgrFromCloud(const pcl::PointCloud< pcl::PointXYZRGBA > &cloud, bool bgrOrder)
std::vector< std::pair< std::pair< int, int >, pcl::PointXY > > projectCloudToCamerasImpl(const typename pcl::PointCloud< PointT > &cloud, const std::map< int, Transform > &cameraPoses, const std::map< int, std::vector< CameraModel > > &cameraModels, float maxDistance, float maxAngle, const std::vector< float > &roiRatios, const cv::Mat &projMask, bool distanceToCamPolicy, const ProgressState *state)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP cloudFromSensorData(const SensorData &sensorData, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0, const ParametersMap &stereoParameters=ParametersMap(), const std::vector< float > &roiRatios=std::vector< float >())
const Transform & localTransform() const
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
Eigen::Vector3f RTABMAP_EXP projectDepthTo3DRay(const cv::Size &imageSize, float x, float y, float cx, float cy, float fx, float fy)
pcl::PointCloud< pcl::PointNormal >::Ptr RTABMAP_EXP laserScanToPointCloudNormal(const LaserScan &laserScan, const Transform &transform=Transform())
bool isCompressed() const
ULogger class and convenient macros.
void RTABMAP_EXP fillProjectedCloudHoles(cv::Mat &depthRegistered, bool verticalDirection, bool fillToBorder)
cv::Mat RTABMAP_EXP projectCloudToCamera(const cv::Size &imageSize, const cv::Mat &cameraMatrixK, const cv::Mat &laserScan, const rtabmap::Transform &cameraTransform)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP loadBINCloud(const std::string &fileName)
bool hasIntensity() const
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudFromStereoImages(const cv::Mat &imageLeft, const cv::Mat &imageRight, const StereoCameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0, const ParametersMap ¶meters=ParametersMap())
pcl::PointCloud< pcl::PointXYZI >::Ptr RTABMAP_EXP laserScanToPointCloudI(const LaserScan &laserScan, const Transform &transform=Transform(), float intensity=0.0f)
float RTABMAP_EXP getDepth(const cv::Mat &depthImage, float x, float y, bool smoothing, float depthErrorRatio=0.02f, bool estWithNeighborsIfNull=false)
pcl::IndicesPtr RTABMAP_EXP concatenate(const std::vector< pcl::IndicesPtr > &indices)
Concatenate a vector of indices to a single vector.
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudFromDisparityRGB(const cv::Mat &imageRgb, const cv::Mat &imageDisparity, const StereoCameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP voxelize(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, float voxelSize)
LaserScan RTABMAP_EXP loadScan(const std::string &path)
std::string UTILITE_EXP uFormat(const char *fmt,...)
pcl::PointCloud< pcl::PointXYZ >::Ptr loadCloud(const std::string &path, const Transform &transform, int downsampleStep, float voxelSize)
bool isValidForProjection() const
const CameraModel & right() const
void RTABMAP_EXP rgbdFromCloud(const pcl::PointCloud< pcl::PointXYZRGBA > &cloud, cv::Mat &rgb, cv::Mat &depth, float &fx, float &fy, bool bgrOrder=true, bool depth16U=true)
LaserScan RTABMAP_EXP laserScan2dFromPointCloud(const pcl::PointCloud< pcl::PointXYZ > &cloud, const Transform &transform=Transform(), bool filterNaNs=true)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP concatenateClouds(const std::list< pcl::PointCloud< pcl::PointXYZ >::Ptr > &clouds)
cv::Mat RTABMAP_EXP depthFromCloud(const pcl::PointCloud< pcl::PointXYZRGBA > &cloud, float &fx, float &fy, bool depth16U=true)
cv::Mat RTABMAP_EXP loadBINScan(const std::string &fileName)
const CameraModel & left() const