25#include <VirtualRobot/CollisionDetection/CollisionModel.h>
31#include <Calibration/Calibration.h>
32#include <Calibration/StereoCalibration.h>
33#include <Image/ByteImage.h>
34#include <Image/ImageProcessor.h>
35#include <Math/FloatMatrix.h>
36#include <Math/LinearAlgebra.h>
59 collisionModelInflationMargin =
76 ARMARX_ERROR <<
"Specification of RobotStateComponentName missing";
88 numImages = imageProviderInfo.numberImages;
90 images =
new CByteImage*[numImages];
91 for (
int i = 0; i < numImages; i++)
99 visionx::StereoCalibrationProviderInterfacePrx calibrationProvider =
100 visionx::StereoCalibrationProviderInterfacePrx::checkedCast(imageProviderInfo.proxy);
102 if (calibrationProvider)
105 visionx::StereoCalibration stereoCalibration =
106 calibrationProvider->getStereoCalibration();
108 ::visionx::MonocularCalibration calibrationLeft = stereoCalibration.calibrationLeft;
109 width = calibrationLeft.cameraParam.width;
110 height = calibrationLeft.cameraParam.height;
111 fov = 2.0 * std::atan(width / (2.0 * calibrationLeft.cameraParam.focalLength[1]));
114 ARMARX_INFO <<
"Using calibration from image provider " << providerName
115 <<
". Field of view is: " << fov;
117 ARMARX_INFO <<
"Iamge size: (" << width <<
", " << height <<
").";
126 visionx::StereoCalibrationInterfacePrx pointCloudAndStereoCalibrationProvider =
127 visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.proxy);
128 if (pointCloudAndStereoCalibrationProvider)
130 visionx::StereoCalibration stereoCalibration =
131 pointCloudAndStereoCalibrationProvider->getStereoCalibration();
133 ::visionx::MonocularCalibration calibrationLeft = stereoCalibration.calibrationLeft;
134 width = calibrationLeft.cameraParam.width;
135 height = calibrationLeft.cameraParam.height;
136 fov = 2.0 * std::atan(width / (2.0 * calibrationLeft.cameraParam.focalLength[0]));
139 ARMARX_INFO <<
"Using calibration from image provider " << providerName <<
".";
144 <<
" does not have a stereo calibration interface";
149 width = depthCameraCalibration.cameraParam.width;
150 height = depthCameraCalibration.cameraParam.height;
160 visionx::ImageDimension dimension(images[0]->width, images[0]->height);
168 imageProviderInfo.imageFormat,
170 SbColor(backgroundR / 255.f, backgroundG / 255.f, backgroundB / 255.f),
173 collisionModelInflationMargin);
184 for (
int i = 0; i < numImages; i++)
196 std::lock_guard<std::mutex> lock(mutex);
208 armarx::MetaInfoSizeBasePtr metaInfo;
209 if (this->ImageProcessor::getImages(providerName, images, metaInfo) != numImages)
215 CByteImage* maskImage = maskRobot->getMaskImage(metaInfo->timeProvided);
219 if (dilationStrength >= 2)
221 ::ImageProcessor::Dilate(maskImage, maskImage, dilationStrength);
225 for (
int i = 0; i < numResultImages; i++)
228 std::uint8_t* pixelsRow = images[i]->pixels;
229 std::uint8_t* maskPixelsRow = maskImage->pixels;
231 for (
int y = 0; y < height; y++)
233 for (
int x = 0;
x < width;
x++)
235 if (maskPixelsRow[
x] == 255)
237 pixelsRow[
x * 3 + 0] = 0;
238 pixelsRow[
x * 3 + 1] = 0;
239 pixelsRow[
x * 3 + 2] = 0;
243 pixelsRow += width * 3;
244 maskPixelsRow += width;
249 int imageSize = imageProviderInfo.imageFormat.dimension.width *
250 imageProviderInfo.imageFormat.dimension.height *
251 imageProviderInfo.imageFormat.bytesPerPixel;
252 MetaInfoSizeBasePtr myMetaInfo =
new MetaInfoSizeBase(
253 numResultImages * imageSize, numResultImages * imageSize, metaInfo->timeProvided);
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
void onExitImageProcessor() override
Exit the ImapeProcessor component.
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void process() override
Process the vision component.
void onInitImageProcessor() override
Setup the vision component.
void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void enableResultImages(int numberImages, ImageDimension imageDimension, ImageType imageType, const std::string &name="")
Enables visualization.
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 provideResultImages(CByteImage **images, armarx::MetaInfoSizeBasePtr info=nullptr)
sends result images for visualization
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#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.