34#include <Image/ImageProcessor.h>
55 ? imageProviderInfo.numberImages
57 ARMARX_INFO << defaultProvider <<
" " << imageProviderInfo.imageFormat.dimension.width
58 <<
"x" << imageProviderInfo.imageFormat.dimension.height;
60 cameraImages[defaultProvider].resize(imageProviderInfo.numberImages);
61 for (
int i = 0; i < imageProviderInfo.numberImages; i++)
63 cameraImages[defaultProvider].at(i).reset(
68 visionx::ImageDimension targetDimension =
70 visionx::ImageFormatInfo info;
71 info.bytesPerPixel = 3;
72 info.dimension = targetDimension;
73 info.type = imageDisplayType;
74 for (
int i = 0; i < numImages; ++i)
76 resultCameraImages.push_back(
116 ImageSourceSelection::deleteTimedOutProviders()
118 std::unique_lock lock(imageSourceMutex);
120 std::map<std::string, int> deletionMap;
121 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
123 deletionMap[it->first] = 0;
126 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
131 if (it->first != defaultProvider)
133 deletionMap[it->first]++;
135 it = providerTimeouts.erase(it);
139 deletionMap[it->first]--;
142 for (
auto& pair : deletionMap)
146 ARMARX_INFO <<
"Deleting image source " << pair.first;
147 std::unique_lock lock(mutex);
157 deleteTimedOutProviders();
160 std::unique_lock lock(mutex);
168 <<
"Timeout while waiting for images from " << activeProvider;
171 armarx::MetaInfoSizeBasePtr info;
173 <<
" width: " << cameraImages.at(activeProvider).at(0)->width;
174 if (
getImages(activeProvider, cameraImages.at(activeProvider), info) <
181 auto currentNumberOfImages =
185 visionx::ImageDimension targetDimension =
188 if (targetDimension != providerDimension &&
189 imageProviderInfo.imageFormat.type != imageDisplayType)
191 info->capacity = info->size = numImages * resultCameraImages[0]->bytesPerPixel *
192 resultCameraImages[0]->width *
193 resultCameraImages[0]->height;
196 for (
int i = 0; i < currentNumberOfImages; i++)
200 ::ImageProcessor::Resize(cameraImages.at(activeProvider).at(i).get(),
201 otherTypeResizedImage.get());
202 ::ImageProcessor::ConvertImage(otherTypeResizedImage.get(),
203 resultCameraImages.at(i).get());
206 else if (targetDimension != providerDimension)
208 info->capacity = info->size = numImages * resultCameraImages[0]->bytesPerPixel *
209 resultCameraImages[0]->width *
210 resultCameraImages[0]->height;
211 for (
int i = 0; i < currentNumberOfImages; i++)
213 ::ImageProcessor::Resize(cameraImages.at(activeProvider).at(i).get(),
214 resultCameraImages.at(i).get());
222 if (imageProviderInfo.imageFormat.type != imageDisplayType)
224 for (
int i = 0; i < currentNumberOfImages; i++)
226 ::ImageProcessor::ConvertImage(cameraImages.at(activeProvider).at(i).get(),
227 resultCameraImages.at(i).get());
235 for (
int i = 0; i < currentNumberOfImages; i++)
237 ::ImageProcessor::CopyImage(cameraImages.at(activeProvider).at(i).get(),
238 resultCameraImages.at(i).get());
247 int relativeTimeoutMs,
248 const Ice::Current&
c)
252 std::unique_lock lock(imageSourceMutex);
254 auto newTimeout =
TimeUtil::GetTime() + IceUtil::Time::milliSeconds(relativeTimeoutMs);
257 if (!providerTimeouts.empty() && providerTimeouts.front().first == imageSource)
259 ARMARX_VERBOSE <<
"Refreshing timeout: " << newTimeout.toDateTime();
260 providerTimeouts.front().second = newTimeout;
265 <<
" at front with timeout " << newTimeout.toDateTime();
266 providerTimeouts.insert(providerTimeouts.begin(),
267 std::make_pair(imageSource, newTimeout));
275 std::unique_lock lock(mutex);
281 if (imageSource != activeProvider)
283 ARMARX_INFO <<
"getting calibration for image provider " << imageSource;
284 visionx::StereoCalibrationInterfacePrx calibrationProvider =
285 visionx::StereoCalibrationInterfacePrx::checkedCast(
290 if (calibrationProvider)
293 visionx::StereoCalibration stereoCalibration =
294 calibrationProvider->getStereoCalibration();
300 stereoCalibration.calibrationLeft.cameraParam.focalLength[0] /= scaleFactorX;
301 stereoCalibration.calibrationLeft.cameraParam.focalLength[1] /= scaleFactorX;
303 stereoCalibration.calibrationLeft.cameraParam.principalPoint[0] /= scaleFactorX;
304 stereoCalibration.calibrationLeft.cameraParam.principalPoint[1] /= scaleFactorX;
306 stereoCalibration.calibrationLeft.cameraParam.width /= scaleFactorX;
307 stereoCalibration.calibrationLeft.cameraParam.height /= scaleFactorX;
309 stereoCalibration.calibrationRight.cameraParam.focalLength[0] /= scaleFactorX;
310 stereoCalibration.calibrationRight.cameraParam.focalLength[1] /= scaleFactorX;
313 stereoCalibration.calibrationRight.cameraParam.principalPoint[0] /=
315 stereoCalibration.calibrationRight.cameraParam.principalPoint[1] /=
319 stereoCalibration.calibrationRight.cameraParam.width =
320 ((
float)stereoCalibration.calibrationRight.cameraParam.width) /
322 stereoCalibration.calibrationRight.cameraParam.height =
323 ((
float)stereoCalibration.calibrationRight.cameraParam.height) /
330 if (stereoResultImageProvider)
332 stereoResultImageProvider->setStereoCalibration(
334 calibrationProvider->getImagesAreUndistorted(),
335 calibrationProvider->getReferenceFrame());
344 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
346 if (it->first == imageSource)
348 providerTimeouts.erase(it);
356 visionx::ImageType imageType)
360 ARMARX_INFO <<
"Enabling StereoResultImageProvider";
366 stereoResultImageProvider);
387 visionx::ImageType imageDisplayType,
395 <<
"x" << otherImageProviderInfo.
imageFormat.dimension.height;
396 cameraImages[providerName].resize(otherImageProviderInfo.
numberImages);
397 for (
int i = 0; i < otherImageProviderInfo.
numberImages; i++)
399 cameraImages[providerName].at(i).reset(
402 visionx::StereoCalibrationInterfacePrx calibrationProvider =
403 visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.proxy);
404 if (!calibrationProvider)
406 ARMARX_WARNING <<
"image provider does not have a stereo calibration interface";
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
Brief description of class ImageSourceSelection.
bool addImageProvider(const std::string &providerName)
void onConnectImageProcessor() override
void enableStereoResultImages(visionx::ImageDimension imageDimension, visionx::ImageType imageType)
enable stereo result images
void onExitImageProcessor() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void removeImageSource(const std::string &imageSource)
std::string getCurrentImageSource(const Ice::Current &c=Ice::emptyCurrent) override
void onInitImageProcessor() override
static std::string GetDefaultName()
void setImageSource(const std::string &imageSource, int relativeTimeoutMs, const Ice::Current &c) override
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
std::string getName() const
Retrieve name of object.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
IceInternal::Handle< ResultImageProvider > resultImageProvider
std::map< std::string, ImageProviderInfo > imageProviderInfoMap
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.
int getImages(CByteImage **ppImages)
Poll images from provider.
void provideResultImages(CByteImage **images, armarx::MetaInfoSizeBasePtr info=nullptr)
sends result images for visualization
void releaseImageProvider(std::string providerName)
ImageProviderMap usedImageProviders
int numberImages
Number of images.
ImageFormatInfo imageFormat
Image format struct that contains all necessary image information.
#define ARMARX_CHECK_GREATER(lhs, rhs)
This macro evaluates whether lhs is greater (>) than rhs and if it turns out to be false it will thro...
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#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.
IceInternal::Handle< StereoResultImageProvider > StereoResultImageProviderPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::unique_ptr< CByteImage > CByteImageUPtr