27 #include <Eigen/Geometry>
29 #include <pcl/common/transforms.h>
34 #include <VisionX/interface/components/Calibration.h>
45 providerName = getProperty<std::string>(
"ProviderName").getValue();
48 fovH = getProperty<float>(
"HorizontalViewAngle").getValue();
49 fovV = getProperty<float>(
"VerticalViewAngle").getValue();
50 if (!getProperty<std::string>(
"CalibrationProviderName").getValue().
empty())
52 usingProxy(getProperty<std::string>(
"CalibrationProviderName").getValue());
54 nanValue = getProperty<float>(
"NaNValue").getValue();
55 maxDist = getProperty<float>(
"MaxDist").getValue();
56 minDist = getProperty<float>(
"MinDist").getValue();
64 ARMARX_VERBOSE <<
"after getImageProvider('" << providerName <<
"')";
69 images =
new CByteImage*[numImages];
70 for (
size_t i = 0; i < numImages; i++)
78 auto applyCalibration = [&](visionx::StereoCalibrationInterfacePrx prx)
80 if (getProperty<bool>(
"ComputeViewAngleFromCalibration").getValue())
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 "
91 if (!getProperty<std::string>(
"CalibrationProviderName").getValue().
empty())
93 calibrationPrx = getProxy<visionx::StereoCalibrationInterfacePrx>(
94 getProperty<std::string>(
"CalibrationProviderName").getValue());
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;
162 ARMARX_CHECK_EQUAL(getProperty<int>(
"PointCloudHeight").getValue(), images[0]->height);
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));
249 float angle = getProperty<float>(
"PointCloudRotationZ").getValue() / 180.f *
M_PI;
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;
267 visionx::MetaPointCloudFormatPtr
270 visionx::MetaPointCloudFormatPtr info =
new visionx::MetaPointCloudFormat();
271 info->size = getProperty<int>(
"PointCloudWidth").getValue() *
272 getProperty<int>(
"PointCloudHeight").getValue() *
sizeof(
PointL);
273 info->capacity = info->size;
274 info->type = visionx::PointContentType::eColoredLabeledPoints;