31 #include <Image/ImageProcessor.h>
32 #include <Calibration/StereoCalibration.h>
42 void StereoImagePointCloudProvider::onInitComponent()
44 ImageProcessor::onInitComponent();
45 CapturingPointCloudProvider::onInitComponent();
46 ImageProvider::onInitComponent();
47 downsamplingRate = getProperty<int>(
"DownsamplingRate").getValue();
48 smoothDisparity = getProperty<bool>(
"SmoothDisparity").getValue();
51 void StereoImagePointCloudProvider::onConnectComponent()
53 ImageProcessor::onConnectComponent();
54 CapturingPointCloudProvider::onConnectComponent();
55 ImageProvider::onConnectComponent();
58 void StereoImagePointCloudProvider::onDisconnectComponent()
60 ImageProcessor::onDisconnectComponent();
61 CapturingPointCloudProvider::onDisconnectComponent();
62 ImageProvider::onDisconnectComponent();
66 void StereoImagePointCloudProvider::onExitComponent()
68 ImageProvider::onExitComponent();
69 CapturingPointCloudProvider::onExitComponent();
70 ImageProcessor::onExitComponent();
73 void StereoImagePointCloudProvider::onInitCapturingPointCloudProvider()
78 void StereoImagePointCloudProvider::onStartCapture(
float frameRate)
83 void StereoImagePointCloudProvider::onStopCapture()
88 void StereoImagePointCloudProvider::onExitCapturingPointCloudProvider()
93 MetaPointCloudFormatPtr StereoImagePointCloudProvider::getDefaultPointCloudFormat()
95 MetaPointCloudFormatPtr info =
new MetaPointCloudFormat();
97 info->type = PointContentType::eColoredPoints;
98 info->capacity = 1600 * 1200 *
sizeof(ColoredPoint3D);
99 info->size = info->capacity;
104 void StereoImagePointCloudProvider::onInitImageProcessor()
107 providerName = getProperty<std::string>(
"ImageProviderAdapterName").getValue();
108 usingImageProvider(providerName);
112 void StereoImagePointCloudProvider::onConnectImageProcessor()
115 ARMARX_INFO << getName() <<
" connecting to " << providerName;
117 imageProviderPrx = getProxy<ImageProviderInterfacePrx>(providerName);
120 StereoCalibrationProviderInterfacePrx calibrationProviderPrx1 = StereoCalibrationProviderInterfacePrx::checkedCast(imageProviderPrx);
121 CapturingPointCloudAndImageAndStereoCalibrationProviderInterfacePrx calibrationProviderPrx2 = CapturingPointCloudAndImageAndStereoCalibrationProviderInterfacePrx::checkedCast(imageProviderPrx);
123 if (calibrationProviderPrx1)
126 imagesAreUndistorted = calibrationProviderPrx1->getImagesAreUndistorted();
128 else if (calibrationProviderPrx2)
131 imagesAreUndistorted = calibrationProviderPrx2->getImagesAreUndistorted();
135 ARMARX_WARNING <<
"Image provider with name " << providerName <<
" is not a StereoCalibrationProvider";
136 imagesAreUndistorted =
true;
139 cameraImages =
new CByteImage*[2];
142 width = imageProviderInfo.
imageFormat.dimension.width;
143 height = imageProviderInfo.
imageFormat.dimension.height;
144 cameraImagesGrey =
new CByteImage*[2];
145 cameraImagesGrey[0] =
new CByteImage(width, height, CByteImage::eGrayScale);
146 cameraImagesGrey[1] =
new CByteImage(width, height, CByteImage::eGrayScale);
147 disparityImage =
new CByteImage(width, height, CByteImage::eGrayScale);
148 disparityImageRGB =
new CByteImage(cameraImages[0]);
149 resultImages =
new CByteImage*[2];
150 resultImages[0] = cameraImages[0];
151 resultImages[1] = disparityImageRGB;
155 void StereoImagePointCloudProvider::onExitImageProcessor()
157 delete cameraImages[0];
158 delete cameraImages[1];
159 delete[] cameraImages;
160 delete cameraImagesGrey[0];
161 delete cameraImagesGrey[1];
162 delete[] cameraImagesGrey;
163 delete disparityImage;
164 delete disparityImageRGB;
165 delete[] resultImages;
170 void StereoImagePointCloudProvider::onInitImageProvider()
172 setImageFormat(visionx::ImageDimension(width, height), visionx::eRgb);
179 MonocularCalibration StereoImagePointCloudProvider::getMonocularCalibration(
const Ice::Current&
c)
184 bool StereoImagePointCloudProvider::doCapture()
186 std::unique_lock lock(captureLock);
188 if (!waitForImages(8000))
196 int nNumberImages = ImageProcessor::getImages(cameraImages);
197 ARMARX_DEBUG << getName() <<
" got " << nNumberImages <<
" images";
199 pcl::PointCloud<PointXYZRGBA>::Ptr pointcloud(
new pcl::PointCloud<PointXYZRGBA>());
200 ::ImageProcessor::ConvertImage(cameraImages[0], cameraImagesGrey[0]);
201 ::ImageProcessor::ConvertImage(cameraImages[1], cameraImagesGrey[1]);
203 ARMARX_DEBUG << getName() <<
"depthfromstereo::GetPointsFromDisparity";
205 *pointcloud, disparityImage, width, height, stereoCalibration, imagesAreUndistorted, smoothDisparity);
209 providePointCloud(pointcloud);
211 for (
size_t j = 0; j < pointcloud->height; j++)
213 for (
size_t i = 0; i < pointcloud->width; i++)
215 int idx = (j * pointcloud->width + i);
216 int value = pointcloud->points[idx].z;
219 disparityImageRGB->pixels[3 * idx + 0] =
value & 0xFF;
220 disparityImageRGB->pixels[3 * idx + 1] = (
value >> 8) & 0xFF;
224 provideImages(resultImages);