33 #include <Image/ImageProcessor.h>
40 defaultProvider = getProperty<std::string>(
"defaultProviderName").getValue();
51 numImages = getProperty<int>(
"NumberOfImages").getValue() <= 0 ? imageProviderInfo.
numberImages : getProperty<int>(
"NumberOfImages").getValue();
54 cameraImages[defaultProvider].resize(imageProviderInfo.
numberImages);
55 for (
int i = 0 ; i < imageProviderInfo.
numberImages; i++)
61 visionx::ImageDimension targetDimension = getProperty<visionx::ImageDimension>(
"TargetDimension").getValue();
62 visionx::ImageFormatInfo info;
63 info.bytesPerPixel = 3;
64 info.dimension = targetDimension;
65 info.type = imageDisplayType;
66 for (
int i = 0; i < numImages; ++i)
77 enableResultImages(numImages, targetDimension, imageDisplayType, getProperty<std::string>(
"resultProviderName"));
102 void ImageSourceSelection::deleteTimedOutProviders()
104 std::unique_lock lock(imageSourceMutex);
106 std::map<std::string, int> deletionMap;
107 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
109 deletionMap[it->first] = 0;
112 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
117 if (it->first != defaultProvider)
119 deletionMap[it->first]++;
121 it = providerTimeouts.erase(it);
126 deletionMap[it->first]--;
130 for (
auto& pair : deletionMap)
134 ARMARX_INFO <<
"Deleting image source " << pair.first;
135 std::unique_lock lock(mutex);
144 deleteTimedOutProviders();
147 std::unique_lock lock(mutex);
157 armarx::MetaInfoSizeBasePtr info;
158 ARMARX_DEBUG <<
deactivateSpam(5, activeProvider) <<
"Getting image from " << activeProvider <<
" width: " << cameraImages.at(activeProvider).at(0)->width;
168 visionx::ImageDimension targetDimension = getProperty<visionx::ImageDimension>(
"TargetDimension").getValue();
170 if (targetDimension != providerDimension && imageProviderInfo.
imageFormat.type != imageDisplayType)
172 info->capacity = info->size = numImages * resultCameraImages[0]->bytesPerPixel * resultCameraImages[0]->width * resultCameraImages[0]->height;
174 for (
int i = 0; i < currentNumberOfImages; i++)
177 ::ImageProcessor::Resize(cameraImages.at(activeProvider).at(i).get(), otherTypeResizedImage.get());
178 ::ImageProcessor::ConvertImage(otherTypeResizedImage.get(), resultCameraImages.at(i).get());
182 else if (targetDimension != providerDimension)
184 info->capacity = info->size = numImages * resultCameraImages[0]->bytesPerPixel * resultCameraImages[0]->width * resultCameraImages[0]->height;
185 for (
int i = 0; i < currentNumberOfImages; i++)
187 ::ImageProcessor::Resize(cameraImages.at(activeProvider).at(i).get(), resultCameraImages.at(i).get());
195 if (imageProviderInfo.
imageFormat.type != imageDisplayType)
197 for (
int i = 0; i < currentNumberOfImages; i++)
199 ::ImageProcessor::ConvertImage(cameraImages.at(activeProvider).at(i).get(), resultCameraImages.at(i).get());
207 for (
int i = 0; i < currentNumberOfImages; i++)
209 ::ImageProcessor::CopyImage(cameraImages.at(activeProvider).at(i).get(), resultCameraImages.at(i).get());
223 std::unique_lock lock(imageSourceMutex);
225 auto newTimeout =
TimeUtil::GetTime() + IceUtil::Time::milliSeconds(relativeTimeoutMs);
228 if (!providerTimeouts.empty() && providerTimeouts.front().first == imageSource)
230 ARMARX_VERBOSE <<
"Refreshing timeout: " << newTimeout.toDateTime();
231 providerTimeouts.front().second = newTimeout;
235 ARMARX_VERBOSE <<
"inserting new imageprovider " << imageSource <<
" at front with timeout " << newTimeout.toDateTime();
236 providerTimeouts.insert(providerTimeouts.begin(), std::make_pair(imageSource, newTimeout));
243 std::unique_lock lock(mutex);
249 if (imageSource != activeProvider)
251 ARMARX_INFO <<
"getting calibration for image provider " << imageSource;
252 visionx::StereoCalibrationInterfacePrx calibrationProvider = visionx::StereoCalibrationInterfacePrx::checkedCast(
imageProviderInfoMap[imageSource].proxy);
256 if (calibrationProvider)
259 visionx::StereoCalibration stereoCalibration = calibrationProvider->getStereoCalibration();
265 stereoCalibration.calibrationLeft.cameraParam.focalLength[0] /= scaleFactorX;
266 stereoCalibration.calibrationLeft.cameraParam.focalLength[1] /= scaleFactorX;
268 stereoCalibration.calibrationLeft.cameraParam.principalPoint[0] /= scaleFactorX;
269 stereoCalibration.calibrationLeft.cameraParam.principalPoint[1] /= scaleFactorX;
271 stereoCalibration.calibrationLeft.cameraParam.width /= scaleFactorX;
272 stereoCalibration.calibrationLeft.cameraParam.height /= scaleFactorX;
274 stereoCalibration.calibrationRight.cameraParam.focalLength[0] /= scaleFactorX;
275 stereoCalibration.calibrationRight.cameraParam.focalLength[1] /= scaleFactorX;
278 stereoCalibration.calibrationRight.cameraParam.principalPoint[0] /= scaleFactorX;
279 stereoCalibration.calibrationRight.cameraParam.principalPoint[1] /= scaleFactorX;
283 stereoCalibration.calibrationRight.cameraParam.width = ((
float) stereoCalibration.calibrationRight.cameraParam.width) / scaleFactorX;
284 stereoCalibration.calibrationRight.cameraParam.height = ((
float) stereoCalibration.calibrationRight.cameraParam.height) / scaleFactorX;
290 if (stereoResultImageProvider)
292 stereoResultImageProvider->setStereoCalibration(stereoCalibration, calibrationProvider->getImagesAreUndistorted(), calibrationProvider->getReferenceFrame());
301 for (
auto it = providerTimeouts.begin(); it != providerTimeouts.end(); it++)
303 if (it->first == imageSource)
305 providerTimeouts.erase(it);
317 ARMARX_INFO <<
"Enabling StereoResultImageProvider";
320 stereoResultImageProvider->setName(getProperty<std::string>(
"resultProviderName"));
346 cameraImages[providerName].resize(otherImageProviderInfo.
numberImages);
347 for (
int i = 0 ; i < otherImageProviderInfo.
numberImages; i++)
351 visionx::StereoCalibrationInterfacePrx calibrationProvider = visionx::StereoCalibrationInterfacePrx::checkedCast(imageProviderInfo.
proxy);
352 if (!calibrationProvider)
354 ARMARX_WARNING <<
"image provider does not have a stereo calibration interface";