28#include <opencv2/opencv.hpp>
33#include <Image/ImageProcessor.h>
139 consumer->setTransferMode(armarx::eIce);
142 std::pair<std::string, armarx::IceSharedMemoryConsumer<unsigned char>::pointer_type>
144 consumer_info.first = providerName;
145 consumer_info.second = consumer;
168 ImageType destinationImageType,
185 provider_info.
buffer.resize(
196 std::pair<std::string, ImageProviderInfo> entry(providerName, provider_info);
207 if (!provider_info.
proxy->hasSharedMemorySupport())
209 ARMARX_INFO <<
"shared memory not available for provider " << providerName;
224 switch (transferMode)
237 statistics[providerName].imageProviderFPS.reset();
239 return provider_info;
245 ImageType destinationImageType)
252 ImageDimension imageDimension,
254 const std::string& name)
258 ARMARX_VERBOSE <<
"Enabling ResultImageProvider with " << numberImages
259 <<
" result images.";
292 MetaInfoSizeBasePtr info)
313 ARMARX_ERROR <<
"Calling getImages without ImageProvider name, and no ImageProvider is "
314 "available - did you forget to call useImageProvider?";
319 std::string outputText =
320 "Several image providers are available - using the first one in the list:";
321 std::map<std::string, ImageProviderInfo>::iterator iter;
325 outputText <<
" " << iter->first;
337 std::shared_ptr<std::condition_variable> cond;
342 std::map<std::string, ImageProviderInfo>::iterator iter =
347 ARMARX_ERROR <<
"Trying to wait for images from unknown image provider. Call "
348 "useImageProvider before";
351 cond = iter->second.imageAvailableEvent;
355 ARMARX_DEBUG <<
"Waiting for images from provider proxy " << providerName;
359 std::unique_lock lock(mut);
360 auto td = std::chrono::milliseconds(milliseconds);
362 return cond->wait_for(lock, td) != std::cv_status::timeout;
368 return waitForImages(providerName,
static_cast<int>(waitTime.toMilliSeconds()));
381 std::map<std::string, ImageProviderInfo>::iterator iter =
386 ARMARX_ERROR <<
"Trying access unknown image provider. Call useImageProvider before";
390 bool result = iter->second.imageAvailable;
404 for (
int i = 0; i < numberOfImages; ++i)
412 void** ppBuffer =
new void*[numberOfImages];
414 for (
int i = 0; i < numberOfImages; ++i)
416 ppBuffer[i] = (
void*)ppImages[i]->pixels;
422 return numberOfImages;
430 void** ppBuffer =
new void*[numberOfImages];
432 for (
int i = 0; i < numberOfImages; ++i)
434 ppBuffer[i] = (
void*)ppImages[i]->pixels;
440 return numberOfImages;
448 ARMARX_ERROR <<
"Calling getImages without ImageProvider name, and no ImageProvider is "
449 "available - did you forget to call useImageProvider?";
454 std::string outputText =
455 "Several image providers are available - using the first one in the list:";
456 std::map<std::string, ImageProviderInfo>::iterator iter;
460 outputText <<
" " << iter->first;
465 std::string providerName;
472 armarx::MetaInfoSizeBasePtr info;
473 return getImages(providerName, ppBuffer, info);
478 CByteImage** ppImages,
479 armarx::MetaInfoSizeBasePtr& info)
483 void** ppBuffer =
new void*[numberOfImages];
485 for (
int i = 0; i < numberOfImages; ++i)
487 ppBuffer[i] = (
void*)ppImages[i]->pixels;
490 numberOfImages =
getImages(providerName, ppBuffer, info);
493 return numberOfImages;
498 const std::vector<CByteImageUPtr>& ppImages,
499 MetaInfoSizeBasePtr& info)
503 void** ppBuffer =
new void*[numberOfImages];
505 for (
int i = 0; i < numberOfImages; ++i)
507 ppBuffer[i] = (
void*)ppImages.at(i)->pixels;
510 numberOfImages =
getImages(providerName, ppBuffer, info);
513 return numberOfImages;
518 CFloatImage** ppImages,
519 armarx::MetaInfoSizeBasePtr& info)
523 void** ppBuffer =
new void*[numberOfImages];
525 for (
int i = 0; i < numberOfImages; ++i)
527 ppBuffer[i] = (
void*)ppImages[i]->pixels;
530 numberOfImages =
getImages(providerName, ppBuffer, info);
533 return numberOfImages;
539 armarx::MetaInfoSizeBasePtr& info)
541 int numberImages = -1;
548 std::map<std::string, ImageProviderInfo>::iterator iter =
553 ARMARX_ERROR <<
"Trying to retrieve images from unknown image provider. Call "
554 "useImageProvider before";
558 numberImages = iter->second.numberImages;
561 if (!iter->second.imageAvailable)
571 CompressedImageProviderInterfacePrx compressedImageProvider;
574 compressedImageProvider =
575 CompressedImageProviderInterfacePrx::checkedCast(iter->second.proxy);
576 if (!compressedImageProvider)
580 <<
"Trying to use image provider as "
581 "CompressedImageProviderInterfacePrx, but it is not of this type: "
582 << iter->second.proxy->ice_id();
588 auto blob = compressedImageProvider->getCompressedImagesAndMetaInfo(
592 cv::Mat mat = cv::imdecode(blob, cv::IMREAD_COLOR);
595 << mat.size().width <<
"x" << mat.size().height
596 <<
", bpp: " << mat.channels();
597 providerInfo.
buffer = Blob(mat.datastart, mat.dataend);
599 << providerInfo.
buffer.size();
606 blob = iter->second.proxy->getImagesAndMetaInfo(providerInfo.
info);
610 IceUtil::Time::microSeconds(providerInfo.
info->timeProvided))
611 .toMilliSecondsDouble()
612 <<
" ms old, timestamp: " << providerInfo.
info->timeProvided;
617 <<
"using fall back remote procedure call without timestamp!";
620 blob = iter->second.proxy->getImages();
623 blob.swap(providerInfo.
buffer);
631 int imageSize = providerInfo.
imageFormat.dimension.width *
636 for (
int i = 0; i < numberImages; i++)
639 iter->second, &iter->second.buffer[0] + i * imageSize, ppBuffer[i]);
642 info = iter->second.info;
645 iter->second.imageAvailable =
false;
661 ARMARX_ERROR <<
"Calling getNumberOfImages() without ImageProvider name, and no "
662 "ImageProvider is available - did you forget to call useImageProvider?";
667 std::string outputText =
668 "Several image providers are available and no name was specified when calling "
669 "getNumberOfImages() - using the first one in the list:";
670 std::map<std::string, ImageProviderInfo>::iterator iter;
674 outputText <<
" " << iter->first;
680 int numberOfImages = 0;
682 if (providerName.empty())
693 std::map<std::string, ImageProviderInfo>::iterator iter =
698 ARMARX_ERROR <<
"Trying to retrieve images from unknown image provider. Call "
699 "useImageProvider before";
703 numberOfImages = iter->second.numberImages;
706 return numberOfImages;
714 std::map<std::string, ImageTransferStats>::iterator iter =
statistics.find(providerName);
718 ARMARX_ERROR <<
"Requesting statistics for unknown image provider (" << providerName
727 iter->second.imageProviderFPS.reset();
728 iter->second.pollingFPS.reset();
732 iter->second.imageProviderFPS.recalculate();
733 iter->second.pollingFPS.recalculate();
750 if (imageProviderName.empty())
759 return it->second->getMetaInfo();
763 ARMARX_ERROR <<
"Requesting meta info for unknown image provider ("
764 << imageProviderName <<
")";
802 std::map<std::string, ImageProviderInfo>::iterator iter =
808 <<
"Received notification from unknown imageprovider (" << providerName
814 iter->second.imageAvailable =
true;
815 iter->second.imageAvailableEvent->notify_all();
816 ARMARX_DEBUG <<
"Got notification of image provider " << providerName;
821 statistics[providerName].imageProviderFPS.update();
844 if (changedProperties.count(
"CompressionType"))
848 if (changedProperties.count(
"CompressionQuality"))
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)
The IceSharedMemoryConsumer reads data via Ice or shared memory.
IceUtil::Handle< IceSharedMemoryConsumer< MemoryObject, MemoryObjectMetaInfo > > pointer_type
pointer type for convenience.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
bool unsubscribeFromTopic(const std::string &name)
Unsubscribe from a topic.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
void waitForProxy(std::string const &name, bool addToDependencies)
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
bool removeProxyDependency(const std::string &name)
This function removes the dependency of this object on the in parameter name specified object.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
The periodic task executes one thread method repeatedly using the time period specified in the constr...
bool hasProperty(const std::string &name)
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
void onInitComponent() override
IceInternal::Handle< ResultImageProvider > resultImageProvider
virtual void process()=0
Process the vision component.
void componentPropertiesUpdated(const std::set< std::string > &changedProperties) override
Implement this function if you would like to react to changes in the properties.
std::map< std::string, ImageProviderInfo > imageProviderInfoMap
void enableResultImages(int numberImages, ImageDimension imageDimension, ImageType imageType, const std::string &name="")
Enables visualization.
armarx::PeriodicTask< ImageProcessor >::pointer_type processorTask
void usingImageProvider(std::string name)
Registers a delayed topic subscription and a delayed provider proxy retrieval which all will be avail...
virtual void onInitImageProcessor()=0
Setup the vision component.
bool waitForImages(int milliseconds=1000)
Wait for new images.
virtual void onConnectImageProcessor()=0
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
bool isNewImageAvailable()
ImageProviderInfo getImageProvider(std::string name, ImageType destinationImageType=eRgb, bool waitForProxy=false)
Select an ImageProvider.
void onDisconnectComponent() override
static std::string ListenerSuffix
int getImages(CByteImage **ppImages)
Poll images from provider.
void cleanup()
clean up memory
CompressionType compressionType
virtual void runProcessor()
int getCompressionQuality() const
armarx::MetaInfoSizeBasePtr getImageMetaInfo(const std::string &imageProviderName="") const
Get meta information from the image provider.
CompressionType getCompressionType() const
virtual void onDisconnectImageProcessor()
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
ImageTransferStats getImageTransferStats(std::string provideNname, bool resetStats=false)
Retrieve statistics for a connection to an ImageProvider.
void setCompressionType(CompressionType compressionType=ePNG, int compressionQuality=9)
Sets the compression type and compression quality.
int getNumberOfImages(const std::string &providerName="")
Returns the number of images provided by the specified image provider If no provider is specified,...
virtual void onExitImageProcessor()=0
Exit the ImapeProcessor component.
void onConnectComponent() override
void provideResultImages(CByteImage **images, armarx::MetaInfoSizeBasePtr info=nullptr)
sends result images for visualization
std::map< std::string, ImageTransferStats > statistics
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void releaseImageProvider(std::string providerName)
void reportImageAvailable(const std::string &providerName, const Ice::Current &c=Ice::emptyCurrent) override
Listener callback function.
void setFramerate(float fps)
void onExitComponent() override
std::string getImageListenerTopicName(std::string providerName) const
std::shared_mutex imageProviderInfoMutex
ImageProviderMap usedImageProviders
float getFramerate() const
std::mutex statisticsMutex
ImageType destinationImageType
Required image destination type.
bool imageAvailable
Indicates whether an image is available.
ImageTransferMode imageTransferMode
Transfer mode of images.
std::vector< unsigned char > buffer
memory block
int numberImages
Number of images.
armarx::MetaInfoSizeBasePtr info
meta info
ImageFormatInfo imageFormat
Image format struct that contains all necessary image information.
ImageProviderInterfacePrx proxy
proxy to image provider
std::shared_ptr< std::condition_variable > imageAvailableEvent
Conditional variable used internally for synchronization purposes.
The ImageTransferStats class provides information on the connection between ImageProvider and ImagePr...
#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_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_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.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.