36#include <Image/ImageProcessor.h>
50 return "ImageToArMem";
59 defs->topic(debugObserver);
61 defs->optional(p.imageProviderName,
"img.ProviderName",
"Name of the image provier.");
62 defs->optional(p.providerSegmentName,
63 "img.ProviderSegmentName",
64 "The provider (segment) name (if not specified in the entity ID).\n"
65 "If '(auto)', the image provider name is used.");
67 defs->optional(p.clearProviderSegmentWhenExists,
68 "mem.ClearProviderSegmentsWhenExisting",
69 "If true, the provider segments are cleared when this component starts.");
71 defs->optional(p.commitCameraCalib,
72 "mem.commitCameraCalibration",
73 "Commit camera calibration to memory");
75 defs->optional(p.maxFrequencyOfCommit,
76 "mem.maxCommitFrequency",
77 "Maximal frequency with which to commit images to Vision Memory in Hz. \n"
78 "Actual commit frequency might be lower, as we wait for next image.");
80 p.images.define(*defs);
89 if (p.providerSegmentName ==
"(auto)")
91 p.providerSegmentName = p.imageProviderName;
93 p.images.read(*
this, p.providerSegmentName);
95 imageToArMem.addImagesRGB(p.images.rgbEntityID, p.images.rgbIndices);
96 imageToArMem.addImagesDepth(p.images.depthEntityID, p.images.depthIndices);
98 ARMARX_INFO <<
"Memory image structure: \n" << imageToArMem.summarizeStructure();
99 ARMARX_VERBOSE <<
"Using image provider '" << p.imageProviderName <<
"'.";
112 imageToArMem.initImages(imageProviderInfo.imageFormat);
113 inputImages = imageToArMem.makeCByteImageBuffer();
114 inputImageBuffer.clear();
115 for (CByteImage& img : inputImages)
117 inputImageBuffer.emplace_back(&img);
125 imageToArMem.setWriter(
memoryNameSystem().useWriter(imageToArMem.getMemoryID()));
132 imageToArMem.setDebugObserver(debugObserver);
134 imageToArMem.addProviderSegments();
159 int timeDifference = (n.toMicroSecondsSinceEpoch() -
160 this->timeOfLastAcceptedImage.toMicroSecondsSinceEpoch()) /
162 ARMARX_DEBUG <<
"Time difference during commit is " << timeDifference;
163 float maxFrequency = p.maxFrequencyOfCommit;
164 float minWaitingTime = (1 / maxFrequency) * 1000;
166 if (timeDifference > minWaitingTime)
168 ARMARX_DEBUG <<
"resetting time of last accepted image";
169 this->timeOfLastAcceptedImage =
172 numImages =
getImages(p.imageProviderName, inputImageBuffer.data(), imageMetaInfo);
176 if (numImages ==
static_cast<int>(inputImageBuffer.size()))
179 imageToArMem.useImageBuffers(
180 inputImageBuffer.data(),
187 ARMARX_ERROR <<
"Received unexpected number of input images. Got " << numImages
188 <<
" instead of " << inputImageBuffer.size() <<
".";
193 if (!commitedCameraCalib and p.commitCameraCalib and imageProviderInfo.proxy)
195 if (visionx::StereoCalibrationInterfacePrx calibrationProvider =
196 visionx::StereoCalibrationInterfacePrx::checkedCast(
197 imageProviderInfo.proxy);
201 <<
"Found stereo camera calibration from StereoCalibrationInterface.";
202 visionx::StereoCalibration stereoCameraCalibration =
203 calibrationProvider->getStereoCalibration();
204 imageToArMem.commitCameraCalibration(stereoCameraCalibration);
208 ARMARX_INFO <<
"Could not cast to stereo calibration interface. Creating "
209 "default monocular ";
210 visionx::MonocularCalibration monocularCameraCalibration =
213 imageToArMem.commitCameraCalibration(monocularCameraCalibration);
215 commitedCameraCalib =
true;
220 ARMARX_DEBUG <<
"Ignoring image due to high frequency of commits but lower max. "
221 "Frequency set in properties";
226 ARMARX_WARNING <<
"Timeout while waiting for camera images (> " << timeout <<
").";
232 debugObserver->setDebugChannel(
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
std::string getName() const
Retrieve name of object.
The Variant class is described here: Variants.
MemoryNameSystem & memoryNameSystem()
Indicates that a query to the Memory Name System failed.
Represents a point in time.
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
std::int64_t toMilliSeconds() const
Returns the amount of milliseconds.
double toMicroSecondsDouble() const
Returns the amount of microseconds.
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 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.
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 ...
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_INFO
The normal logging level.
#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.
#define TIMING_START(name)
Helper macro to do timing tests.
#define TIMING_END_STREAM(name, os)
Prints duration.
armarx::core::time::DateTime Time
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.