32#include <Image/ImageProcessor.h>
53 ? imageProviderInfo.numberImages
55 ARMARX_INFO << defaultProvider <<
" " << imageProviderInfo.imageFormat.dimension.width
56 <<
"x" << imageProviderInfo.imageFormat.dimension.height;
58 cameraImages[defaultProvider].resize(imageProviderInfo.numberImages);
59 for (
int i = 0; i < imageProviderInfo.numberImages; i++)
61 cameraImages[defaultProvider].at(i).reset(
66 visionx::ImageDimension targetDimension =
68 visionx::ImageFormatInfo info;
69 info.bytesPerPixel = 3;
70 info.dimension = targetDimension;
71 info.type = imageDisplayType;
72 for (
int i = 0; i < numImages; ++i)
74 resultCameraImages.push_back(
114 ImageSourceSelection::deleteTimedOutProviders()
116 std::unique_lock lock(imageSourceMutex);
118 std::map<std::string, int> deletionMap;
119 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
121 deletionMap[it->first] = 0;
124 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
129 if (it->first != defaultProvider)
131 deletionMap[it->first]++;
133 it = providerTimeouts.erase(it);
137 deletionMap[it->first]--;
140 for (
auto& pair : deletionMap)
144 ARMARX_INFO <<
"Deleting image source " << pair.first;
145 std::unique_lock lock(mutex);
155 deleteTimedOutProviders();
158 std::unique_lock lock(mutex);
166 <<
"Timeout while waiting for images from " << activeProvider;
169 armarx::MetaInfoSizeBasePtr info;
171 <<
" width: " << cameraImages.at(activeProvider).at(0)->width;
172 if (
getImages(activeProvider, cameraImages.at(activeProvider), info) <
179 auto currentNumberOfImages =
183 visionx::ImageDimension targetDimension =
186 if (targetDimension != providerDimension &&
187 imageProviderInfo.imageFormat.type != imageDisplayType)
189 info->capacity = info->size = numImages * resultCameraImages[0]->bytesPerPixel *
190 resultCameraImages[0]->width *
191 resultCameraImages[0]->height;
194 for (
int i = 0; i < currentNumberOfImages; i++)
198 ::ImageProcessor::Resize(cameraImages.at(activeProvider).at(i).get(),
199 otherTypeResizedImage.get());
200 ::ImageProcessor::ConvertImage(otherTypeResizedImage.get(),
201 resultCameraImages.at(i).get());
204 else if (targetDimension != providerDimension)
206 info->capacity = info->size = numImages * resultCameraImages[0]->bytesPerPixel *
207 resultCameraImages[0]->width *
208 resultCameraImages[0]->height;
209 for (
int i = 0; i < currentNumberOfImages; i++)
211 ::ImageProcessor::Resize(cameraImages.at(activeProvider).at(i).get(),
212 resultCameraImages.at(i).get());
220 if (imageProviderInfo.imageFormat.type != imageDisplayType)
222 for (
int i = 0; i < currentNumberOfImages; i++)
224 ::ImageProcessor::ConvertImage(cameraImages.at(activeProvider).at(i).get(),
225 resultCameraImages.at(i).get());
233 for (
int i = 0; i < currentNumberOfImages; i++)
235 ::ImageProcessor::CopyImage(cameraImages.at(activeProvider).at(i).get(),
236 resultCameraImages.at(i).get());
245 int relativeTimeoutMs,
246 const Ice::Current&
c)
250 std::unique_lock lock(imageSourceMutex);
252 auto newTimeout =
TimeUtil::GetTime() + IceUtil::Time::milliSeconds(relativeTimeoutMs);
255 if (!providerTimeouts.empty() && providerTimeouts.front().first == imageSource)
257 ARMARX_VERBOSE <<
"Refreshing timeout: " << newTimeout.toDateTime();
258 providerTimeouts.front().second = newTimeout;
263 <<
" at front with timeout " << newTimeout.toDateTime();
264 providerTimeouts.insert(providerTimeouts.begin(),
265 std::make_pair(imageSource, newTimeout));
273 std::unique_lock lock(mutex);
279 if (imageSource != activeProvider)
281 ARMARX_INFO <<
"getting calibration for image provider " << imageSource;
282 visionx::StereoCalibrationInterfacePrx calibrationProvider =
283 visionx::StereoCalibrationInterfacePrx::checkedCast(
288 if (calibrationProvider)
291 visionx::StereoCalibration stereoCalibration =
292 calibrationProvider->getStereoCalibration();
298 stereoCalibration.calibrationLeft.cameraParam.focalLength[0] /= scaleFactorX;
299 stereoCalibration.calibrationLeft.cameraParam.focalLength[1] /= scaleFactorX;
301 stereoCalibration.calibrationLeft.cameraParam.principalPoint[0] /= scaleFactorX;
302 stereoCalibration.calibrationLeft.cameraParam.principalPoint[1] /= scaleFactorX;
304 stereoCalibration.calibrationLeft.cameraParam.width /= scaleFactorX;
305 stereoCalibration.calibrationLeft.cameraParam.height /= scaleFactorX;
307 stereoCalibration.calibrationRight.cameraParam.focalLength[0] /= scaleFactorX;
308 stereoCalibration.calibrationRight.cameraParam.focalLength[1] /= scaleFactorX;
311 stereoCalibration.calibrationRight.cameraParam.principalPoint[0] /=
313 stereoCalibration.calibrationRight.cameraParam.principalPoint[1] /=
317 stereoCalibration.calibrationRight.cameraParam.width =
318 ((
float)stereoCalibration.calibrationRight.cameraParam.width) /
320 stereoCalibration.calibrationRight.cameraParam.height =
321 ((
float)stereoCalibration.calibrationRight.cameraParam.height) /
328 if (stereoResultImageProvider)
330 stereoResultImageProvider->setStereoCalibration(
332 calibrationProvider->getImagesAreUndistorted(),
333 calibrationProvider->getReferenceFrame());
342 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
344 if (it->first == imageSource)
346 providerTimeouts.erase(it);
354 visionx::ImageType imageType)
358 ARMARX_INFO <<
"Enabling StereoResultImageProvider";
364 stereoResultImageProvider);
385 visionx::ImageType imageDisplayType,
393 <<
"x" << otherImageProviderInfo.
imageFormat.dimension.height;
394 cameraImages[providerName].resize(otherImageProviderInfo.
numberImages);
395 for (
int i = 0; i < otherImageProviderInfo.
numberImages; i++)
397 cameraImages[providerName].at(i).reset(
400 visionx::StereoCalibrationInterfacePrx calibrationProvider =
401 visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.proxy);
402 if (!calibrationProvider)
404 ARMARX_WARNING <<
"image provider does not have a stereo calibration interface";
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)
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
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