35 #include <Image/ImageProcessor.h>
43 return "ImageToArMem";
52 defs->topic(debugObserver);
54 defs->optional(p.imageProviderName,
"img.ProviderName",
"Name of the image provier.");
55 defs->optional(p.providerSegmentName,
56 "img.ProviderSegmentName",
57 "The provider (segment) name (if not specified in the entity ID).\n"
58 "If '(auto)', the image provider name is used.");
60 defs->optional(p.clearProviderSegmentWhenExists,
61 "mem.ClearProviderSegmentsWhenExisting",
62 "If true, the provider segments are cleared when this component starts.");
64 defs->optional(p.commitCameraCalib,
65 "mem.commitCameraCalibration",
66 "Commit camera calibration to memory");
68 defs->optional(p.maxFrequencyOfCommit,
69 "mem.maxCommitFrequency",
70 "Maximal frequency with which to commit images to Vision Memory in Hz. \n"
71 "Actual commit frequency might be lower, as we wait for next image.");
73 p.images.define(*defs);
82 if (p.providerSegmentName ==
"(auto)")
84 p.providerSegmentName = p.imageProviderName;
86 p.images.read(*
this, p.providerSegmentName);
88 imageToArMem.addImagesRGB(p.images.rgbEntityID, p.images.rgbIndices);
89 imageToArMem.addImagesDepth(p.images.depthEntityID, p.images.depthIndices);
91 ARMARX_INFO <<
"Memory image structure: \n" << imageToArMem.summarizeStructure();
92 ARMARX_VERBOSE <<
"Using image provider '" << p.imageProviderName <<
"'.";
94 usingImageProvider(p.imageProviderName);
102 imageProviderInfo = getImageProvider(p.imageProviderName);
105 imageToArMem.initImages(imageProviderInfo.imageFormat);
106 inputImages = imageToArMem.makeCByteImageBuffer();
107 inputImageBuffer.clear();
108 for (CByteImage& img : inputImages)
110 inputImageBuffer.emplace_back(&img);
118 imageToArMem.setWriter(memoryNameSystem().useWriter(imageToArMem.getMemoryID()));
125 imageToArMem.setDebugObserver(debugObserver);
127 imageToArMem.addProviderSegments();
148 int millisecondsSinceLastCommit = 0;
149 if (waitForImages(p.imageProviderName,
static_cast<int>(timeout.
toMilliSeconds())))
152 int timeDifference = (n.
toMicroSecondsSinceEpoch() - this->timeOfLastAcceptedImage.toMicroSecondsSinceEpoch())/1000;
153 ARMARX_DEBUG <<
"Time difference during commit is " << timeDifference;
154 float maxFrequency = p.maxFrequencyOfCommit;
155 float minWaitingTime = (1/maxFrequency) * 1000;
157 if (timeDifference > minWaitingTime){
158 ARMARX_DEBUG <<
"resetting time of last accepted image";
161 numImages = getImages(p.imageProviderName, inputImageBuffer.data(), imageMetaInfo);
165 if (numImages ==
static_cast<int>(inputImageBuffer.size()))
168 imageToArMem.useImageBuffers(
169 inputImageBuffer.data(),
170 Time(Duration::MicroSeconds(imageMetaInfo->timeProvided)));
171 imageToArMem.commitImages();
175 ARMARX_ERROR <<
"Received unexpected number of input images. Got " << numImages
176 <<
" instead of " << inputImageBuffer.size() <<
".";
181 if (!commitedCameraCalib and p.commitCameraCalib and imageProviderInfo.proxy)
183 if (visionx::StereoCalibrationInterfacePrx calibrationProvider =
184 visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.proxy);
188 <<
"Found stereo camera calibration from StereoCalibrationInterface.";
189 visionx::StereoCalibration stereoCameraCalibration =
190 calibrationProvider->getStereoCalibration();
191 imageToArMem.commitCameraCalibration(stereoCameraCalibration);
195 ARMARX_INFO <<
"Could not cast to stereo calibration interface. Creating default monocular ";
196 visionx::MonocularCalibration monocularCameraCalibration =
199 imageToArMem.commitCameraCalibration(monocularCameraCalibration);
201 commitedCameraCalib =
true;
205 ARMARX_DEBUG <<
"Ignoring image due to high frequency of commits but lower max. Frequency set in properties";
210 ARMARX_WARNING <<
"Timeout while waiting for camera images (> " << timeout <<
").";
216 debugObserver->setDebugChannel(