29 #include <Eigen/Geometry>
31 #include <pcl/common/transforms.h>
33 #include <VisionX/interface/components/Calibration.h>
47 providerName = getProperty<std::string>(
"ProviderName").getValue();
50 fovH = getProperty<float>(
"HorizontalViewAngle").getValue();
51 fovV = getProperty<float>(
"VerticalViewAngle").getValue();
52 if (!getProperty<std::string>(
"CalibrationProviderName").getValue().
empty())
54 usingProxy(getProperty<std::string>(
"CalibrationProviderName").getValue());
56 nanValue = getProperty<float>(
"NaNValue").getValue();
57 maxDist = getProperty<float>(
"MaxDist").getValue();
58 minDist = getProperty<float>(
"MinDist").getValue();
65 ARMARX_VERBOSE <<
"after getImageProvider('" << providerName <<
"')";
70 images =
new CByteImage*[numImages];
71 for (
size_t i = 0 ; i < numImages ; i++)
79 auto applyCalibration = [&](visionx::StereoCalibrationInterfacePrx prx)
81 if (getProperty<bool>(
"ComputeViewAngleFromCalibration").getValue())
83 visionx::StereoCalibration stereoCalibration = prx->getStereoCalibration();
84 float fx = stereoCalibration.calibrationRight.cameraParam.focalLength[0];
85 float fy = stereoCalibration.calibrationRight.cameraParam.focalLength[1];
86 fovV = 180.0 /
M_PI * 2.0 * std::atan(images[0]->height / (2.0 * fy));
87 fovH = 180.0 /
M_PI * 2.0 * std::atan(images[0]->width / (2.0 * fx));
88 ARMARX_INFO <<
" Using provided HorizontalViewAngle/VerticalViewAngle parameters from calibration";
91 if (!getProperty<std::string>(
"CalibrationProviderName").getValue().
empty())
93 calibrationPrx = getProxy<visionx::StereoCalibrationInterfacePrx>(getProperty<std::string>(
"CalibrationProviderName").getValue());
97 applyCalibration(calibrationPrx);
101 ARMARX_WARNING <<
"Property CalibrationProviderName was given, but the proxy is not a StereoCalibrationInterfacePrx. Calibration not available!";
106 visionx::StereoCalibrationInterfacePrx calibrationInterface = visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.
proxy);
107 if (calibrationInterface)
109 applyCalibration(calibrationInterface);
113 ARMARX_INFO <<
"HorizontalViewAngle: " << fovH <<
" VerticalViewAngle: " << fovV;
114 cloud.reset(
new pcl::PointCloud<PointL>());
115 transformedCloud.reset(
new pcl::PointCloud<PointL>());
117 debugObserver->setDebugDatafield(
getName(),
"processCount",
new Variant(processCounter));
124 for (
size_t i = 0 ; i < numImages ; i++)
139 std::unique_lock lock(mutex);
147 if (
getImages(providerName, images, imageMetaInfo) !=
static_cast<int>(numImages))
154 cloud->width = images[0]->width;
155 cloud->height = images[0]->height;
156 cloud->header.stamp = imageMetaInfo->timeProvided;
158 ARMARX_CHECK_EQUAL(getProperty<int>(
"PointCloudHeight").getValue(), images[0]->height);
159 cloud->points.resize(images[0]->width * images[0]->height);
160 cloud->is_dense =
true;
163 const float scaleX = std::tan(fovH *
M_PI / 180.0 / 2.0) * 2.0;
164 const float scaleY = std::tan(fovV *
M_PI / 180.0 / 2.0) * 2.0;
166 const size_t width =
static_cast<size_t>(images[0]->width);
167 const size_t height =
static_cast<size_t>(images[0]->height);
168 const float halfWidth = (width / 2.0);
169 const float halfHeight = (height / 2.0);
170 const auto& image0Data = images[0]->pixels;
171 const auto& image1Data = images[1]->pixels;
173 for (
size_t j = 0; j < height; j++)
175 for (
size_t i = 0; i < width; i++)
177 auto coord = j * width + i;
182 if (maxDist > 0 &&
value > maxDist)
186 else if (
value < minDist)
192 PointL& p = cloud->points.at(coord);
193 auto index = 3 * (coord);
194 p.r = image0Data[
index + 0];
195 p.g = image0Data[
index + 1];
196 p.b = image0Data[
index + 2];
202 p.z =
static_cast<float>(nanValue);
204 p.x = -1.0 * (i - halfWidth) / width * p.z * scaleX;
205 p.y = (halfHeight - j) / height * p.z * scaleY;
209 p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN();
214 p.z =
static_cast<float>(
value);
215 p.x = -1.0 * (i - halfWidth) / width * p.z * scaleX;
216 p.y = (halfHeight - j) / height * p.z * scaleY;
221 auto& image2Data = images[2]->pixels;
223 if (images[2]->bytesPerPixel == 3)
225 p.label =
static_cast<unsigned int>(image2Data[
index + 0] + (image2Data[
index + 1] << 8) + (image2Data[
index + 2] << 16));
229 p.label =
static_cast<unsigned int>(image2Data[coord]);
242 debugObserver->setDebugDatafield(
getName(),
"processCount",
new Variant(processCounter));
244 float angle = getProperty<float>(
"PointCloudRotationZ").getValue() / 180.f *
M_PI;
249 m = Eigen::AngleAxisf(
angle,
250 Eigen::Vector3f::UnitZ());
251 transform2.block<3, 3>(0, 0) *= m;
252 pcl::transformPointCloud(*cloud, *transformedCloud, transform2);
253 transformedCloud->header.stamp = imageMetaInfo->timeProvided;
270 visionx::MetaPointCloudFormatPtr info =
new visionx::MetaPointCloudFormat();
271 info->size = getProperty<int>(
"PointCloudWidth").getValue() * getProperty<int>(
"PointCloudHeight").getValue() *
sizeof(
PointL);
272 info->capacity = info->size;
273 info->type = visionx::PointContentType::eColoredLabeledPoints;