DepthImageUtils.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <pcl/point_cloud.h>
4 #include <pcl/point_types.h>
5 
6 #include <ArmarXCore/interface/core/SharedMemory.h>
7 
10 
11 #include <Image/ByteImage.h>
12 
13 namespace armarx
14 {
16  {
17 
18  typedef pcl::PointXYZRGBL PointL;
19 
20  public:
21  DepthImageUtils(float fovH = 43.0f, float fovV = 57.0f);
22 
23  void setFieldOfView(float fovH, float fovV);
24 
25  void updateCameraParameters(float fx, float fy, int width, int height);
26 
27  void convertDepthImageToPointCloud(CByteImage** images,
28  armarx::MetaInfoSizeBasePtr imageMetaInfo,
29  size_t numImages,
30  pcl::PointCloud<pcl::PointXYZRGBL>::Ptr& result);
31 
32  template <typename PointCloudPtrT>
33  void
34  convertDepthImageToPointCloud(CByteImage** images,
35  armarx::MetaInfoSizeBasePtr imageMetaInfo,
36  PointCloudPtrT& result)
37  {
38  using PointT = typename PointCloudPtrT::PointType;
39 
40  result->width = images[0]->width;
41  result->height = images[0]->height;
42  result->header.stamp = imageMetaInfo->timeProvided;
43  result->points.resize(images[0]->width * images[0]->height);
44  result->is_dense = true;
45 
46 
47  const size_t width = static_cast<size_t>(images[0]->width);
48  const size_t height = static_cast<size_t>(images[0]->height);
49  const float halfWidth = (width / 2.0);
50  const float halfHeight = (height / 2.0);
51  const auto& image0Data = images[0]->pixels;
52  const auto& image1Data = images[1]->pixels;
53 
54  for (size_t j = 0; j < height; j++)
55  {
56  for (size_t i = 0; i < width; i++)
57  {
58  auto coord = j * width + i;
59  // unsigned short value = images[1]->pixels[3 * coord + 0]
60  // + (images[1]->pixels[3 * coord + 1] << 8);
61  auto value = visionx::tools::rgbToDepthValue(image1Data[3 * coord + 0],
62  image1Data[3 * coord + 1],
63  image1Data[3 * coord + 2]);
64 
65  PointT& p = result->points.at(coord);
66  auto index = 3 * (coord);
67  p.r = image0Data[index + 0];
68  p.g = image0Data[index + 1];
69  p.b = image0Data[index + 2];
70 
71  if (value == 0)
72  {
73  p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN();
74  }
75  else
76  {
77  p.z = static_cast<float>(value);
78  //p.z /= 1000.0;
79  p.x = -1.0 * (i - halfWidth) / width * p.z * scaleX;
80  p.y = (halfHeight - j) / height * p.z * scaleY;
81  }
82  }
83  }
84  }
85 
86  private:
87  float scaleX;
88  float scaleY;
89  };
90 } // namespace armarx
armarx::DepthImageUtils::DepthImageUtils
DepthImageUtils(float fovH=43.0f, float fovV=57.0f)
Definition: DepthImageUtils.cpp:11
armarx::DepthImageUtils::convertDepthImageToPointCloud
void convertDepthImageToPointCloud(CByteImage **images, armarx::MetaInfoSizeBasePtr imageMetaInfo, size_t numImages, pcl::PointCloud< pcl::PointXYZRGBL >::Ptr &result)
Definition: DepthImageUtils.cpp:32
armarx::DepthImageUtils::updateCameraParameters
void updateCameraParameters(float fx, float fy, int width, int height)
Definition: DepthImageUtils.cpp:24
visionx::armem::pointcloud::PointType
PointType
Definition: constants.h:78
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::DepthImageUtils::convertDepthImageToPointCloud
void convertDepthImageToPointCloud(CByteImage **images, armarx::MetaInfoSizeBasePtr imageMetaInfo, PointCloudPtrT &result)
Definition: DepthImageUtils.h:34
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::DepthImageUtils
Definition: DepthImageUtils.h:15
PCLUtilities.h
armarx::PointT
pcl::PointXYZRGBL PointT
Definition: Common.h:30
armarx::DepthImageUtils::setFieldOfView
void setFieldOfView(float fovH, float fovV)
Definition: DepthImageUtils.cpp:17
ImageUtil.h
visionx::tools::rgbToDepthValue
float rgbToDepthValue(unsigned char r, unsigned char g, unsigned char b, bool noiseResistant=false)
Definition: ImageUtil.h:148
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27