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