27#include <VirtualRobot/CollisionDetection/CollisionModel.h>
33#include <Calibration/Calibration.h>
34#include <Calibration/StereoCalibration.h>
35#include <Image/ByteImage.h>
36#include <Image/ImageProcessor.h>
37#include <Math/FloatMatrix.h>
38#include <Math/LinearAlgebra.h>
61 collisionModelInflationMargin =
78 ARMARX_ERROR <<
"Specification of RobotStateComponentName missing";
90 numImages = imageProviderInfo.numberImages;
92 images =
new CByteImage*[numImages];
93 for (
int i = 0; i < numImages; i++)
101 visionx::StereoCalibrationProviderInterfacePrx calibrationProvider =
102 visionx::StereoCalibrationProviderInterfacePrx::checkedCast(imageProviderInfo.proxy);
104 if (calibrationProvider)
107 visionx::StereoCalibration stereoCalibration =
108 calibrationProvider->getStereoCalibration();
110 ::visionx::MonocularCalibration calibrationLeft = stereoCalibration.calibrationLeft;
111 width = calibrationLeft.cameraParam.width;
112 height = calibrationLeft.cameraParam.height;
113 fov = 2.0 * std::atan(width / (2.0 * calibrationLeft.cameraParam.focalLength[1]));
116 ARMARX_INFO <<
"Using calibration from image provider " << providerName
117 <<
". Field of view is: " << fov;
119 ARMARX_INFO <<
"Iamge size: (" << width <<
", " << height <<
").";
128 visionx::StereoCalibrationInterfacePrx pointCloudAndStereoCalibrationProvider =
129 visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.proxy);
130 if (pointCloudAndStereoCalibrationProvider)
132 visionx::StereoCalibration stereoCalibration =
133 pointCloudAndStereoCalibrationProvider->getStereoCalibration();
135 ::visionx::MonocularCalibration calibrationLeft = stereoCalibration.calibrationLeft;
136 width = calibrationLeft.cameraParam.width;
137 height = calibrationLeft.cameraParam.height;
138 fov = 2.0 * std::atan(width / (2.0 * calibrationLeft.cameraParam.focalLength[0]));
141 ARMARX_INFO <<
"Using calibration from image provider " << providerName <<
".";
146 <<
" does not have a stereo calibration interface";
151 width = depthCameraCalibration.cameraParam.width;
152 height = depthCameraCalibration.cameraParam.height;
162 visionx::ImageDimension dimension(images[0]->width, images[0]->height);
170 imageProviderInfo.imageFormat,
172 SbColor(backgroundR / 255.f, backgroundG / 255.f, backgroundB / 255.f),
175 collisionModelInflationMargin);
186 for (
int i = 0; i < numImages; i++)
198 std::lock_guard<std::mutex> lock(mutex);
210 armarx::MetaInfoSizeBasePtr metaInfo;
211 if (this->ImageProcessor::getImages(providerName, images, metaInfo) != numImages)
217 CByteImage* maskImage = maskRobot->getMaskImage(metaInfo->timeProvided);
221 if (dilationStrength >= 2)
223 ::ImageProcessor::Dilate(maskImage, maskImage, dilationStrength);
227 for (
int i = 0; i < numResultImages; i++)
230 std::uint8_t* pixelsRow = images[i]->pixels;
231 std::uint8_t* maskPixelsRow = maskImage->pixels;
233 for (
int y = 0; y < height; y++)
235 for (
int x = 0;
x < width;
x++)
237 if (maskPixelsRow[
x] == 255)
239 pixelsRow[
x * 3 + 0] = 0;
240 pixelsRow[
x * 3 + 1] = 0;
241 pixelsRow[
x * 3 + 2] = 0;
245 pixelsRow += width * 3;
246 maskPixelsRow += width;
251 int imageSize = imageProviderInfo.imageFormat.dimension.width *
252 imageProviderInfo.imageFormat.dimension.height *
253 imageProviderInfo.imageFormat.bytesPerPixel;
254 MetaInfoSizeBasePtr myMetaInfo =
new MetaInfoSizeBase(
255 numResultImages * imageSize, numResultImages * imageSize, metaInfo->timeProvided);
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
Brief description of class CropRobotFromImage.
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.
static std::string GetDefaultName()
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.