34#include <Image/ImageProcessor.h>
42 return "ImageToArMem";
51 defs->topic(debugObserver);
53 defs->optional(p.imageProviderName,
"img.ProviderName",
"Name of the image provier.");
54 defs->optional(p.providerSegmentName,
55 "img.ProviderSegmentName",
56 "The provider (segment) name (if not specified in the entity ID).\n"
57 "If '(auto)', the image provider name is used.");
59 defs->optional(p.clearProviderSegmentWhenExists,
60 "mem.ClearProviderSegmentsWhenExisting",
61 "If true, the provider segments are cleared when this component starts.");
63 defs->optional(p.commitCameraCalib,
64 "mem.commitCameraCalibration",
65 "Commit camera calibration to memory");
67 defs->optional(p.maxFrequencyOfCommit,
68 "mem.maxCommitFrequency",
69 "Maximal frequency with which to commit images to Vision Memory in Hz. \n"
70 "Actual commit frequency might be lower, as we wait for next image.");
72 p.images.define(*defs);
81 if (p.providerSegmentName ==
"(auto)")
83 p.providerSegmentName = p.imageProviderName;
85 p.images.read(*
this, p.providerSegmentName);
87 imageToArMem.addImagesRGB(p.images.rgbEntityID, p.images.rgbIndices);
88 imageToArMem.addImagesDepth(p.images.depthEntityID, p.images.depthIndices);
90 ARMARX_INFO <<
"Memory image structure: \n" << imageToArMem.summarizeStructure();
91 ARMARX_VERBOSE <<
"Using image provider '" << p.imageProviderName <<
"'.";
104 imageToArMem.initImages(imageProviderInfo.imageFormat);
105 inputImages = imageToArMem.makeCByteImageBuffer();
106 inputImageBuffer.clear();
107 for (CByteImage& img : inputImages)
109 inputImageBuffer.emplace_back(&img);
117 imageToArMem.setWriter(
memoryNameSystem().useWriter(imageToArMem.getMemoryID()));
124 imageToArMem.setDebugObserver(debugObserver);
126 imageToArMem.addProviderSegments();
151 int timeDifference = (n.toMicroSecondsSinceEpoch() -
152 this->timeOfLastAcceptedImage.toMicroSecondsSinceEpoch()) /
154 ARMARX_DEBUG <<
"Time difference during commit is " << timeDifference;
155 float maxFrequency = p.maxFrequencyOfCommit;
156 float minWaitingTime = (1 / maxFrequency) * 1000;
158 if (timeDifference > minWaitingTime)
160 ARMARX_DEBUG <<
"resetting time of last accepted image";
161 this->timeOfLastAcceptedImage =
164 numImages =
getImages(p.imageProviderName, inputImageBuffer.data(), imageMetaInfo);
168 if (numImages ==
static_cast<int>(inputImageBuffer.size()))
171 imageToArMem.useImageBuffers(
172 inputImageBuffer.data(),
179 ARMARX_ERROR <<
"Received unexpected number of input images. Got " << numImages
180 <<
" instead of " << inputImageBuffer.size() <<
".";
185 if (!commitedCameraCalib and p.commitCameraCalib and imageProviderInfo.proxy)
187 if (visionx::StereoCalibrationInterfacePrx calibrationProvider =
188 visionx::StereoCalibrationInterfacePrx::checkedCast(
189 imageProviderInfo.proxy);
193 <<
"Found stereo camera calibration from StereoCalibrationInterface.";
194 visionx::StereoCalibration stereoCameraCalibration =
195 calibrationProvider->getStereoCalibration();
196 imageToArMem.commitCameraCalibration(stereoCameraCalibration);
200 ARMARX_INFO <<
"Could not cast to stereo calibration interface. Creating "
201 "default monocular ";
202 visionx::MonocularCalibration monocularCameraCalibration =
205 imageToArMem.commitCameraCalibration(monocularCameraCalibration);
207 commitedCameraCalib =
true;
212 ARMARX_DEBUG <<
"Ignoring image due to high frequency of commits but lower max. "
213 "Frequency set in properties";
218 ARMARX_WARNING <<
"Timeout while waiting for camera images (> " << timeout <<
").";
224 debugObserver->setDebugChannel(
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.
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.