32 #include <Image/ImageProcessor.h>
40 defaultProvider = getProperty<std::string>(
"defaultProviderName").getValue();
52 numImages = getProperty<int>(
"NumberOfImages").getValue() <= 0
54 : getProperty<int>(
"NumberOfImages").getValue();
56 <<
"x" << imageProviderInfo.
imageFormat.dimension.height;
58 cameraImages[defaultProvider].resize(imageProviderInfo.
numberImages);
61 cameraImages[defaultProvider].at(i).reset(
66 visionx::ImageDimension targetDimension =
67 getProperty<visionx::ImageDimension>(
"TargetDimension").getValue();
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(
87 getProperty<std::string>(
"resultProviderName"));
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 =
184 getProperty<visionx::ImageDimension>(
"TargetDimension").getValue();
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";
361 Component::create<StereoResultImageProvider>();
362 stereoResultImageProvider->setName(getProperty<std::string>(
"resultProviderName"));
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";