27#include <Eigen/Geometry>
29#include <pcl/common/transforms.h>
34#include <VisionX/interface/components/Calibration.h>
64 ARMARX_VERBOSE <<
"after getImageProvider('" << providerName <<
"')";
67 numImages = std::min(imageProviderInfo.numberImages, 3);
69 images =
new CByteImage*[numImages];
70 for (
size_t i = 0; i < numImages; i++)
78 auto applyCalibration = [&](visionx::StereoCalibrationInterfacePrx prx)
82 visionx::StereoCalibration stereoCalibration = prx->getStereoCalibration();
83 float fx = stereoCalibration.calibrationRight.cameraParam.focalLength[0];
84 float fy = stereoCalibration.calibrationRight.cameraParam.focalLength[1];
85 fovV = 180.0 /
M_PI * 2.0 * std::atan(images[0]->height / (2.0 * fy));
86 fovH = 180.0 /
M_PI * 2.0 * std::atan(images[0]->width / (2.0 * fx));
87 ARMARX_INFO <<
" Using provided HorizontalViewAngle/VerticalViewAngle parameters from "
98 applyCalibration(calibrationPrx);
102 ARMARX_WARNING <<
"Property CalibrationProviderName was given, but the proxy is not a "
103 "StereoCalibrationInterfacePrx. Calibration not available!";
108 visionx::StereoCalibrationInterfacePrx calibrationInterface =
109 visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.proxy);
110 if (calibrationInterface)
112 applyCalibration(calibrationInterface);
116 ARMARX_INFO <<
"HorizontalViewAngle: " << fovH <<
" VerticalViewAngle: " << fovV;
117 cloud.reset(
new pcl::PointCloud<PointL>());
118 transformedCloud.reset(
new pcl::PointCloud<PointL>());
120 debugObserver->setDebugDatafield(
getName(),
"processCount",
new Variant(processCounter));
128 for (
size_t i = 0; i < numImages; i++)
143 std::unique_lock lock(mutex);
151 if (
getImages(providerName, images, imageMetaInfo) !=
static_cast<int>(numImages))
158 cloud->width = images[0]->width;
159 cloud->height = images[0]->height;
160 cloud->header.stamp = imageMetaInfo->timeProvided;
163 cloud->points.resize(images[0]->width * images[0]->height);
164 cloud->is_dense =
true;
167 const float scaleX = std::tan(fovH *
M_PI / 180.0 / 2.0) * 2.0;
168 const float scaleY = std::tan(fovV *
M_PI / 180.0 / 2.0) * 2.0;
170 const size_t width =
static_cast<size_t>(images[0]->width);
171 const size_t height =
static_cast<size_t>(images[0]->height);
172 const float halfWidth = (width / 2.0);
173 const float halfHeight = (height / 2.0);
174 const auto& image0Data = images[0]->pixels;
175 const auto& image1Data = images[1]->pixels;
177 for (
size_t j = 0; j < height; j++)
179 for (
size_t i = 0; i < width; i++)
181 auto coord = j * width + i;
185 image1Data[3 * coord + 0], image1Data[3 * coord + 1], image1Data[3 * coord + 2]);
187 if (maxDist > 0 && value > maxDist)
191 else if (value < minDist)
197 PointL& p = cloud->points.at(coord);
198 auto index = 3 * (coord);
199 p.r = image0Data[
index + 0];
200 p.g = image0Data[
index + 1];
201 p.b = image0Data[
index + 2];
207 p.z =
static_cast<float>(nanValue);
209 p.x = -1.0 * (i - halfWidth) / width * p.z * scaleX;
210 p.y = (halfHeight - j) / height * p.z * scaleY;
214 p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN();
219 p.z =
static_cast<float>(value);
220 p.x = -1.0 * (i - halfWidth) / width * p.z * scaleX;
221 p.y = (halfHeight - j) / height * p.z * scaleY;
226 auto& image2Data = images[2]->pixels;
228 if (images[2]->bytesPerPixel == 3)
230 p.label =
static_cast<unsigned int>(image2Data[
index + 0] +
231 (image2Data[
index + 1] << 8) +
232 (image2Data[
index + 2] << 16));
236 p.label =
static_cast<unsigned int>(image2Data[coord]);
247 debugObserver->setDebugDatafield(
getName(),
"processCount",
new Variant(processCounter));
252 Eigen::Matrix4f transform2 = Eigen::Matrix4f::Identity();
254 m = Eigen::AngleAxisf(
angle, Eigen::Vector3f::UnitZ());
255 transform2.block<3, 3>(0, 0) *= m;
256 pcl::transformPointCloud(*cloud, *transformedCloud, transform2);
257 transformedCloud->header.stamp = imageMetaInfo->timeProvided;
267visionx::MetaPointCloudFormatPtr
270 visionx::MetaPointCloudFormatPtr info =
new visionx::MetaPointCloudFormat();
273 info->capacity = info->size;
274 info->type = visionx::PointContentType::eColoredLabeledPoints;
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)
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.
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)