29 #include <VirtualRobot/CollisionDetection/CollisionModel.h>
32 #include <Image/ByteImage.h>
33 #include <Image/ImageProcessor.h>
34 #include <Calibration/StereoCalibration.h>
35 #include <Calibration/Calibration.h>
36 #include <Math/LinearAlgebra.h>
37 #include <Math/FloatMatrix.h>
45 providerName = getProperty<std::string>(
"providerName").getValue();
49 usingProxy(getProperty<std::string>(
"RobotStateComponentName").getValue());
50 cameraFrameName = getProperty<std::string>(
"cameraFrameName").getValue();
52 backgroundR = getProperty<float>(
"filterColorR").getValue();
53 backgroundG = getProperty<float>(
"filterColorG").getValue();
54 backgroundB = getProperty<float>(
"filterColorB").getValue();
56 dilationStrength = getProperty<int>(
"dilationStrength").getValue();
58 flipImages = getProperty<bool>(
"flipImages").getValue();
59 useFullModel = getProperty<bool>(
"useFullModel").getValue();
60 collisionModelInflationMargin = getProperty<float>(
"collisionModelInflationMargin").getValue();
62 numResultImages = getProperty<int>(
"numResultImages").getValue();
69 if (getProperty<std::string>(
"RobotStateComponentName").getValue() !=
"")
71 robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(getProperty<std::string>(
"RobotStateComponentName").getValue());
75 ARMARX_ERROR <<
"Specification of RobotStateComponentName missing";
89 images =
new CByteImage*[numImages];
90 for (
int i = 0 ; i < numImages; i++)
98 visionx::StereoCalibrationProviderInterfacePrx calibrationProvider = visionx::StereoCalibrationProviderInterfacePrx::checkedCast(imageProviderInfo.
proxy);
100 if (calibrationProvider)
103 visionx::StereoCalibration stereoCalibration = calibrationProvider->getStereoCalibration();
105 ::visionx::MonocularCalibration calibrationLeft = stereoCalibration.calibrationLeft;
106 width = calibrationLeft.cameraParam.width;
107 height = calibrationLeft.cameraParam.height;
108 fov = 2.0 * std::atan(width / (2.0 * calibrationLeft.cameraParam.focalLength[1]));
111 ARMARX_INFO <<
"Using calibration from image provider " << providerName <<
". Field of view is: " << fov ;
113 ARMARX_INFO <<
"Iamge size: (" << width <<
", " << height <<
").";
122 visionx::StereoCalibrationInterfacePrx pointCloudAndStereoCalibrationProvider = visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.
proxy);
123 if (pointCloudAndStereoCalibrationProvider)
125 visionx::StereoCalibration stereoCalibration = pointCloudAndStereoCalibrationProvider->getStereoCalibration();
127 ::visionx::MonocularCalibration calibrationLeft = stereoCalibration.calibrationLeft;
128 width = calibrationLeft.cameraParam.width;
129 height = calibrationLeft.cameraParam.height;
130 fov = 2.0 * std::atan(width / (2.0 * calibrationLeft.cameraParam.focalLength[0]));
133 ARMARX_INFO <<
"Using calibration from image provider " << providerName <<
".";
137 ARMARX_IMPORTANT <<
"image provider " << providerName <<
" does not have a stereo calibration interface";
142 width = depthCameraCalibration.cameraParam.width;
143 height = depthCameraCalibration.cameraParam.height;
153 visionx::ImageDimension dimension(images[0]->width, images[0]->height);
159 maskRobot =
new MaskRobotInImage(robotStateComponent, cameraFrameName, imageProviderInfo.
imageFormat, fov, SbColor(backgroundR / 255.f, backgroundG / 255.f, backgroundB / 255.f), flipImages, useFullModel, collisionModelInflationMargin);
171 for (
int i = 0; i < numImages; i++)
182 std::lock_guard<std::mutex> lock(mutex);
194 armarx::MetaInfoSizeBasePtr metaInfo;
195 if (this->ImageProcessor::getImages(providerName, images, metaInfo) != numImages)
201 CByteImage* maskImage = maskRobot->
getMaskImage(metaInfo->timeProvided);
205 if (dilationStrength >= 2)
207 ::ImageProcessor::Dilate(maskImage, maskImage, dilationStrength);
211 for (
int i = 0; i < numResultImages; i++)
214 std::uint8_t* pixelsRow = images[i]->pixels;
215 std::uint8_t* maskPixelsRow = maskImage->pixels;
217 for (
int y = 0; y < height; y++)
219 for (
int x = 0; x < width; x++)
221 if (maskPixelsRow[x] == 255)
223 pixelsRow[x * 3 + 0] = 0;
224 pixelsRow[x * 3 + 1] = 0;
225 pixelsRow[x * 3 + 2] = 0;
229 pixelsRow += width * 3;
230 maskPixelsRow += width;
237 MetaInfoSizeBasePtr myMetaInfo =
new MetaInfoSizeBase(numResultImages * imageSize, numResultImages * imageSize, metaInfo->timeProvided);