29#include <Eigen/Geometry>
31#include <pcl/common/transforms.h>
36#include <VisionX/interface/components/Calibration.h>
66 ARMARX_VERBOSE <<
"after getImageProvider('" << providerName <<
"')";
69 numImages = std::min(imageProviderInfo.numberImages, 3);
71 images =
new CByteImage*[numImages];
72 for (
size_t i = 0; i < numImages; i++)
80 auto applyCalibration = [&](visionx::StereoCalibrationInterfacePrx prx)
84 visionx::StereoCalibration stereoCalibration = prx->getStereoCalibration();
85 float fx = stereoCalibration.calibrationRight.cameraParam.focalLength[0];
86 float fy = stereoCalibration.calibrationRight.cameraParam.focalLength[1];
87 fovV = 180.0 /
M_PI * 2.0 * std::atan(images[0]->height / (2.0 * fy));
88 fovH = 180.0 /
M_PI * 2.0 * std::atan(images[0]->width / (2.0 * fx));
89 ARMARX_INFO <<
" Using provided HorizontalViewAngle/VerticalViewAngle parameters from "
100 applyCalibration(calibrationPrx);
104 ARMARX_WARNING <<
"Property CalibrationProviderName was given, but the proxy is not a "
105 "StereoCalibrationInterfacePrx. Calibration not available!";
110 visionx::StereoCalibrationInterfacePrx calibrationInterface =
111 visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.proxy);
112 if (calibrationInterface)
114 applyCalibration(calibrationInterface);
118 ARMARX_INFO <<
"HorizontalViewAngle: " << fovH <<
" VerticalViewAngle: " << fovV;
119 cloud.reset(
new pcl::PointCloud<PointL>());
120 transformedCloud.reset(
new pcl::PointCloud<PointL>());
122 debugObserver->setDebugDatafield(
getName(),
"processCount",
new Variant(processCounter));
130 for (
size_t i = 0; i < numImages; i++)
145 std::unique_lock lock(mutex);
153 if (
getImages(providerName, images, imageMetaInfo) !=
static_cast<int>(numImages))
160 cloud->width = images[0]->width;
161 cloud->height = images[0]->height;
162 cloud->header.stamp = imageMetaInfo->timeProvided;
165 cloud->points.resize(images[0]->width * images[0]->height);
166 cloud->is_dense =
true;
169 const float scaleX = std::tan(fovH *
M_PI / 180.0 / 2.0) * 2.0;
170 const float scaleY = std::tan(fovV *
M_PI / 180.0 / 2.0) * 2.0;
172 const size_t width =
static_cast<size_t>(images[0]->width);
173 const size_t height =
static_cast<size_t>(images[0]->height);
174 const float halfWidth = (width / 2.0);
175 const float halfHeight = (height / 2.0);
176 const auto& image0Data = images[0]->pixels;
177 const auto& image1Data = images[1]->pixels;
179 for (
size_t j = 0; j < height; j++)
181 for (
size_t i = 0; i < width; i++)
183 auto coord = j * width + i;
187 image1Data[3 * coord + 0], image1Data[3 * coord + 1], image1Data[3 * coord + 2]);
189 if (maxDist > 0 && value > maxDist)
193 else if (value < minDist)
199 PointL& p = cloud->points.at(coord);
200 auto index = 3 * (coord);
201 p.r = image0Data[
index + 0];
202 p.g = image0Data[
index + 1];
203 p.b = image0Data[
index + 2];
209 p.z =
static_cast<float>(nanValue);
211 p.x = -1.0 * (i - halfWidth) / width * p.z * scaleX;
212 p.y = (halfHeight - j) / height * p.z * scaleY;
216 p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN();
221 p.z =
static_cast<float>(value);
222 p.x = -1.0 * (i - halfWidth) / width * p.z * scaleX;
223 p.y = (halfHeight - j) / height * p.z * scaleY;
228 auto& image2Data = images[2]->pixels;
230 if (images[2]->bytesPerPixel == 3)
232 p.label =
static_cast<unsigned int>(image2Data[
index + 0] +
233 (image2Data[
index + 1] << 8) +
234 (image2Data[
index + 2] << 16));
238 p.label =
static_cast<unsigned int>(image2Data[coord]);
249 debugObserver->setDebugDatafield(
getName(),
"processCount",
new Variant(processCounter));
254 Eigen::Matrix4f transform2 = Eigen::Matrix4f::Identity();
256 m = Eigen::AngleAxisf(
angle, Eigen::Vector3f::UnitZ());
257 transform2.block<3, 3>(0, 0) *= m;
258 pcl::transformPointCloud(*cloud, *transformedCloud, transform2);
259 transformedCloud->header.stamp = imageMetaInfo->timeProvided;
269visionx::MetaPointCloudFormatPtr
272 visionx::MetaPointCloudFormatPtr info =
new visionx::MetaPointCloudFormat();
275 info->capacity = info->size;
276 info->type = visionx::PointContentType::eColoredLabeledPoints;
292 return "ImageToPointCloud";
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
TopicProxyType getTopicFromProperty(const std::string &propertyName)
Get a topic proxy whose name is specified by the given property.
void offeringTopicFromProperty(const std::string &propertyName)
Offer a topic whose name is specified by the given property.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
Brief description of class ImageToPointCloud.
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions()
virtual visionx::MetaPointCloudFormatPtr getDefaultPointCloudFormat()
default point cloud format used to initialize shared memory
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
void onDisconnectComponent() override
Hook for subclass.
void onExitImageProcessor() override
Exit the ImapeProcessor component.
void process() override
Process the vision component.
void onInitImageProcessor() override
Setup the vision component.
static std::string GetDefaultName()
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The Variant class is described here: Variants.
void usingImageProvider(std::string name)
Registers a delayed topic subscription and a delayed provider proxy retrieval which all will be avail...
bool waitForImages(int milliseconds=1000)
Wait for new images.
ImageProviderInfo getImageProvider(std::string name, ImageType destinationImageType=eRgb, bool waitForProxy=false)
Select an ImageProvider.
void onDisconnectComponent() override
int getImages(CByteImage **ppImages)
Poll images from provider.
void onDisconnectComponent() override
Hook for subclass.
void providePointCloud(PointCloudPtrT pointCloudPtr)
offer the new point cloud.
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
double angle(const Point &a, const Point &b, const Point &c)