35 numImages = getProperty<int>(
"numImages").getValue();
36 height = getProperty<int>(
"height").getValue();
37 width = getProperty<int>(
"width").getValue();
39 colorMask = getProperty<Eigen::Vector3i>(
"colorMask").getValue();
41 ARMARX_INFO <<
"color mask is r:" << colorMask(0) <<
" g:" << colorMask(1) <<
" b:" << colorMask(2);
43 setImageFormat(visionx::ImageDimension(width, height), visionx::eRgb);
44 setNumberImages(numImages);
46 bytesPerPixel = getImageFormat().bytesPerPixel;
60 pollImagesTask->start();
62 if (imageSources.size() == 0)
64 std::vector<std::string> imageProviders = getProperty<std::vector<std::string>>(
"imageProviders").getValue();
65 setResultImageProviders(imageProviders);
71 pollImagesTask->stop();
78 const size_t imageSize = width * height * bytesPerPixel;
81 bool imageCaptured =
false;
83 for (
auto& any : imageSources)
86 std::string proxyName = any.first;
88 if (!imageAvailable[proxyName])
94 imageAvailable[proxyName] =
false;
97 ImageProviderInterfacePrx providerPrx;
101 providerPrx = getProxy<ImageProviderInterfacePrx>(proxyName,
false);
105 ARMARX_WARNING <<
"provider" << proxyName <<
" is no longer here.";
111 CByteImage** providerImages = any.second;
112 for (
int n = 0; n < numImages; n++)
114 CByteImage* image = providerImages[n];
116 for (
int j = 0; j < height; j++)
118 for (
int i = 0; i < width; i++)
121 int r = image->pixels[3 * (j * width + i) + 0];
122 int g = image->pixels[3 * (j * width + i) + 1];
123 int b = image->pixels[3 * (j * width + i) + 2];
125 if (!(r == colorMask(0) && g == colorMask(1) && b == colorMask(2)))
127 resultImage->pixels[3 * (j * width + i) + 0] = r;
128 resultImage->pixels[3 * (j * width + i) + 1] = g;
129 resultImage->pixels[3 * (j * width + i) + 2] = b;
135 imageCaptured =
true;
141 for (
int i = 0; i < numImages; i++)
143 memcpy(ppImages[i], resultImage->pixels, imageSize);
147 return imageCaptured;
152 void ResultImageFuser::setResultImageProviders(std::vector<std::string> imageProviders)
154 imageSources.clear();
157 for (std::string& proxyName : imageProviders)
160 ImageProviderInterfacePrx providerPrx;
164 providerPrx = getProxy<ImageProviderInterfacePrx>(proxyName,
false);
168 ARMARX_WARNING <<
"provider" << proxyName <<
" is no longer here.";
172 const int providerNumImages = providerPrx->getNumberImages();
173 ImageFormatInfo imageFormat = providerPrx->getImageFormat();
175 assert(imageFormat.dimension.width == width);
176 assert(imageFormat.dimension.height == height);
177 assert(imageFormat.bytesPerPixel == bytesPerPixel);
178 assert(numImages <= providerNumImages);
180 CByteImage** images =
new CByteImage*[providerNumImages];
182 for (
int n = 0; n < numImages; n++)
188 imageSources[proxyName] = images;
189 imageAvailable[proxyName] =
false;
195 void ResultImageFuser::pollImageProviders()
197 std::unique_lock lock(imageMutex);
199 for (
auto& any : imageSources)
201 std::string proxyName = any.first;
203 ImageProviderInterfacePrx providerPrx;
207 providerPrx = getProxy<ImageProviderInterfacePrx>(proxyName,
false);
211 ARMARX_WARNING <<
"provider" << proxyName <<
" is no longer here.";
215 CByteImage** bufferImages = any.second;
216 ImageFormatInfo imageFormat = providerPrx->getImageFormat();
218 armarx::Blob images = providerPrx->getImages();
220 size_t imageSize = width * height * imageFormat.bytesPerPixel;
222 for (
int i = 0; i < numImages; i++)
224 memcpy(bufferImages[i]->pixels, &images[imageSize * i], imageSize);
227 imageAvailable[proxyName] =
true;
234 getConfigIdentifier()));