ImageProcessor.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX::Core
19  * @author Kai Welke (kai dot welke at kit dot edu)
20  * @author Jan Issac (jan dot issac at gmail dot com)
21  * @date 2011
22  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
23  * GNU General Public License
24  */
25 
26 #include <algorithm>
27 
28 #include <opencv2/opencv.hpp>
29 
31 
32 // IVT
33 #include <Image/ImageProcessor.h>
34 
35 // ArmarXCore
41 
42 // VisionXTools
47 
48 using namespace armarx;
49 
50 namespace visionx
51 {
52  std::string ImageProcessor::ListenerSuffix = ".ImageListener";
53 
54  void
55  ImageProcessor::onInitComponent()
56  {
57  if (hasProperty("CompressionType") && hasProperty("CompressionQuality"))
58  {
59  setCompressionType(getProperty<CompressionType>("CompressionType").getValue(),
60  getProperty<int>("CompressionQuality").getValue());
61  }
62  // call setup of vision component
63  onInitImageProcessor();
64  float cycleTime = desiredFps == 0 ? 0 : 1000.f / desiredFps;
65  processorTask = new PeriodicTask<ImageProcessor>(
66  this, &ImageProcessor::runProcessor, cycleTime, false, "ImageProcessingThread", false);
67  if (cycleTime == 0)
68  {
69  processorTask->setDelayWarningTolerance(1000);
70  }
71  else
72  {
73  processorTask->setDelayWarningTolerance(cycleTime * 5);
74  }
75  }
76 
77  void
78  ImageProcessor::onConnectComponent()
79  {
80  onConnectImageProcessor();
81 
82  // create processor task
83  if (startProcessorTask)
84  {
85  processorTask->start();
86  }
87  }
88 
89  void
90  ImageProcessor::onDisconnectComponent()
91  {
92  processorTask->stop();
93  onDisconnectImageProcessor();
94  }
95 
96  void
97  ImageProcessor::onExitComponent()
98  {
99  ARMARX_VERBOSE << "ImageProcessor::onExitComponent()";
100  onExitImageProcessor();
101 
102  cleanup();
103  }
104 
106  ImageProcessor::createPropertyDefinitions()
107  {
109  new ImageProcessorPropertyDefinitions(getConfigIdentifier()));
110  }
111 
112  void
113  ImageProcessor::runProcessor()
114  {
115 
116 
117  // call process method of sub class
118  process();
119  }
120 
121  std::string
122  ImageProcessor::getImageListenerTopicName(std::string providerName) const
123  {
124  return providerName + ListenerSuffix;
125  }
126 
127  void
128  ImageProcessor::usingImageProvider(std::string providerName)
129  {
130  // use image event topic
131  ARMARX_VERBOSE << "Using ImageProvider " << providerName;
132  usingTopic(getImageListenerTopicName(providerName));
133 
134  // create shared memory consumer
136  new IceSharedMemoryConsumer<unsigned char>(this, providerName, "ImageProvider");
137  if (hasProperty("ForceIceTransfer") && getProperty<bool>("ForceIceTransfer").getValue())
138  {
139  consumer->setTransferMode(armarx::eIce);
140  }
141  // insert into map
142  std::pair<std::string, armarx::IceSharedMemoryConsumer<unsigned char>::pointer_type>
143  consumer_info;
144  consumer_info.first = providerName;
145  consumer_info.second = consumer;
146 
147  usedImageProviders.insert(consumer_info);
148  }
149 
150  void
151  ImageProcessor::releaseImageProvider(std::string providerName)
152  {
153 
154  auto it = usedImageProviders.find(providerName);
155  if (it != usedImageProviders.end())
156  {
157  removeProxyDependency(providerName);
159  removeProxyDependency(consumer->getMemoryName());
160  unsubscribeFromTopic(getImageListenerTopicName(providerName));
161  imageProviderInfoMap.erase(providerName);
162  usedImageProviders.erase(it);
163  }
164  }
165 
167  ImageProcessor::getImageProvider(std::string providerName,
168  ImageType destinationImageType,
169  bool waitForProxy)
170  {
171  // create imageproviderinfo
172  ImageProviderInfo provider_info;
173 
174  std::unique_lock lock(imageProviderInfoMutex);
175 
176  //////////////////////////
177  // image format handling
178  //////////////////////////
179  // get proxy for image polling
180  provider_info.proxy = getProxy<ImageProviderInterfacePrx>(providerName, waitForProxy);
181 
182  provider_info.imageFormat = provider_info.proxy->getImageFormat();
183  provider_info.numberImages = provider_info.proxy->getNumberImages();
184  provider_info.destinationImageType = destinationImageType;
185  provider_info.buffer.resize(
186  provider_info.numberImages * provider_info.imageFormat.dimension.width *
187  provider_info.imageFormat.dimension.height * provider_info.imageFormat.bytesPerPixel);
188 
189  //////////////////////////
190  // synchronisation
191  //////////////////////////
192  provider_info.imageAvailableEvent.reset(new std::condition_variable);
193  provider_info.imageAvailable = false;
194 
195  // update image provider info (and lock mutex exclusively for writing)
196  std::pair<std::string, ImageProviderInfo> entry(providerName, provider_info);
197  imageProviderInfoMap.insert(entry);
198 
199  // find image provider by name
200  ImageProviderMap::iterator iter = usedImageProviders.find(providerName);
201 
202  if (iter == usedImageProviders.end())
203  {
204  usingImageProvider(providerName);
205  }
206 
207  if (!provider_info.proxy->hasSharedMemorySupport())
208  {
209  ARMARX_INFO << "shared memory not available for provider " << providerName;
210  usedImageProviders[providerName]->setTransferMode(eIce);
211  imageProviderInfoMap[providerName].imageTransferMode = eIceTransfer;
212  imageProviderInfoMap[providerName].info =
213  new MetaInfoSizeBase(0, 0, TimeUtil::GetTime().toMicroSeconds());
214  removeProxyDependency(usedImageProviders[providerName]->getMemoryName());
215  }
216  else
217  {
218  //////////////////////////
219  // start communication
220  //////////////////////////
221  usedImageProviders[providerName]->start();
222 
223  auto transferMode = usedImageProviders[providerName]->getTransferMode();
224  switch (transferMode)
225  {
226  case eIce:
227  imageProviderInfoMap[providerName].imageTransferMode = eIceTransfer;
228  break;
229  case eSharedMem:
230  imageProviderInfoMap[providerName].imageTransferMode = eSharedMemoryTransfer;
231  break;
232  }
233  }
234 
235  std::unique_lock lock2(statisticsMutex);
236  statistics[providerName].pollingFPS.reset();
237  statistics[providerName].imageProviderFPS.reset();
238 
239  return provider_info;
240  }
241 
243  ImageProcessor::getImageProvider(std::string name,
244  bool waitForProxy,
245  ImageType destinationImageType)
246  {
247  return getImageProvider(name, destinationImageType, waitForProxy);
248  }
249 
250  void
251  ImageProcessor::enableResultImages(int numberImages,
252  ImageDimension imageDimension,
253  ImageType imageType,
254  const std::string& name)
255  {
256  if (!resultImageProvider)
257  {
258  ARMARX_VERBOSE << "Enabling ResultImageProvider with " << numberImages
259  << " result images.";
260  resultImageProvider = Component::create<ResultImageProvider>();
261  resultImageProvider->setName(name.empty() ? getName() + "Result" : name);
262 
263  getArmarXManager()->addObject(resultImageProvider);
264 
265  resultImageProvider->setNumberResultImages(numberImages);
266  resultImageProvider->setResultImageFormat(imageDimension, imageType);
267 
268  // wait for resultImageProvider
269  resultImageProvider->getObjectScheduler()->waitForObjectState(eManagedIceObjectStarted);
270  }
271  }
272 
273  void
274  ImageProcessor::provideResultImages(CByteImage** images, armarx::MetaInfoSizeBasePtr info)
275  {
276  if (resultImageProvider)
277  {
278  if (info)
279  {
280  resultImageProvider->provideResultImages(images, info->timeProvided);
281  }
282  else
283  {
284  resultImageProvider->provideResultImages(
285  images, armarx::TimeUtil::GetTime().toMicroSeconds());
286  }
287  }
288  }
289 
290  void
291  ImageProcessor::provideResultImages(const std::vector<CByteImageUPtr>& images,
292  MetaInfoSizeBasePtr info)
293  {
294  if (resultImageProvider)
295  {
296  if (info)
297  {
298  resultImageProvider->provideResultImages(images, info->timeProvided);
299  }
300  else
301  {
302  resultImageProvider->provideResultImages(
303  images, armarx::TimeUtil::GetTime().toMicroSeconds());
304  }
305  }
306  }
307 
308  bool
309  ImageProcessor::waitForImages(int milliseconds)
310  {
311  if (imageProviderInfoMap.size() == 0)
312  {
313  ARMARX_ERROR << "Calling getImages without ImageProvider name, and no ImageProvider is "
314  "available - did you forget to call useImageProvider?";
315  return false;
316  }
317  else if (imageProviderInfoMap.size() > 1)
318  {
319  std::string outputText =
320  "Several image providers are available - using the first one in the list:";
321  std::map<std::string, ImageProviderInfo>::iterator iter;
322 
323  for (iter = imageProviderInfoMap.begin(); iter != imageProviderInfoMap.end(); iter++)
324  {
325  outputText << " " << iter->first;
326  }
327 
328  ARMARX_VERBOSE << outputText;
329  }
330 
331  return waitForImages(imageProviderInfoMap.begin()->first, milliseconds);
332  }
333 
334  bool
335  ImageProcessor::waitForImages(std::string providerName, int milliseconds)
336  {
337  std::shared_ptr<std::condition_variable> cond;
338  {
339  // lock image provider info mutex for reading
340  std::unique_lock lock(imageProviderInfoMutex);
341  // find image provider by name
342  std::map<std::string, ImageProviderInfo>::iterator iter =
343  imageProviderInfoMap.find(providerName);
344 
345  if (iter == imageProviderInfoMap.end())
346  {
347  ARMARX_ERROR << "Trying to wait for images from unknown image provider. Call "
348  "useImageProvider before";
349  return false;
350  }
351  cond = iter->second.imageAvailableEvent;
352  }
353 
354 
355  ARMARX_DEBUG << "Waiting for images from provider proxy " << providerName;
356 
357  // wait for conditionale
358  std::mutex mut;
359  std::unique_lock lock(mut);
360  auto td = std::chrono::milliseconds(milliseconds);
361 
362  return cond->wait_for(lock, td) != std::cv_status::timeout;
363  }
364 
365  bool
366  ImageProcessor::waitForImages(std::string providerName, IceUtil::Time waitTime)
367  {
368  return waitForImages(providerName, static_cast<int>(waitTime.toMilliSeconds()));
369  }
370 
371  bool
372  ImageProcessor::isNewImageAvailable()
373  {
374  return isNewImageAvailable(imageProviderInfoMap.begin()->first);
375  }
376 
377  bool
378  ImageProcessor::isNewImageAvailable(const std::string& providerName)
379  {
380  std::unique_lock lock(imageProviderInfoMutex);
381  std::map<std::string, ImageProviderInfo>::iterator iter =
382  imageProviderInfoMap.find(providerName);
383 
384  if (iter == imageProviderInfoMap.end())
385  {
386  ARMARX_ERROR << "Trying access unknown image provider. Call useImageProvider before";
387  return false;
388  }
389 
390  bool result = iter->second.imageAvailable;
391  return result;
392  }
393 
394  int
395  ImageProcessor::getImages(CByteImage** ppImages)
396  {
397  int numberOfImages = getNumberOfImages();
398 
399  if (!ppImages)
400  {
401  ARMARX_ERROR << "ppImages must not be NULL!";
402  }
403  else
404  for (int i = 0; i < numberOfImages; ++i)
405  {
406  if (!ppImages[i])
407  {
408  ARMARX_ERROR << "ppImages[i] must not be NULL!";
409  }
410  }
411 
412  void** ppBuffer = new void*[numberOfImages];
413 
414  for (int i = 0; i < numberOfImages; ++i)
415  {
416  ppBuffer[i] = (void*)ppImages[i]->pixels;
417  }
418 
419  numberOfImages = getImages(ppBuffer);
420  delete[] ppBuffer;
421 
422  return numberOfImages;
423  }
424 
425  int
426  ImageProcessor::getImages(CFloatImage** ppImages)
427  {
428  int numberOfImages = getNumberOfImages();
429 
430  void** ppBuffer = new void*[numberOfImages];
431 
432  for (int i = 0; i < numberOfImages; ++i)
433  {
434  ppBuffer[i] = (void*)ppImages[i]->pixels;
435  }
436 
437  numberOfImages = getImages(ppBuffer);
438  delete[] ppBuffer;
439 
440  return numberOfImages;
441  }
442 
443  int
444  ImageProcessor::getImages(void** ppBuffer)
445  {
446  if (imageProviderInfoMap.size() == 0)
447  {
448  ARMARX_ERROR << "Calling getImages without ImageProvider name, and no ImageProvider is "
449  "available - did you forget to call useImageProvider?";
450  return false;
451  }
452  else if (imageProviderInfoMap.size() > 1)
453  {
454  std::string outputText =
455  "Several image providers are available - using the first one in the list:";
456  std::map<std::string, ImageProviderInfo>::iterator iter;
457 
458  for (iter = imageProviderInfoMap.begin(); iter != imageProviderInfoMap.end(); iter++)
459  {
460  outputText << " " << iter->first;
461  }
462 
463  ARMARX_VERBOSE << outputText;
464  }
465  std::string providerName;
466  {
467  std::unique_lock lock(imageProviderInfoMutex);
468  providerName = imageProviderInfoMap.begin()->first;
469  }
470 
471 
472  armarx::MetaInfoSizeBasePtr info;
473  return getImages(providerName, ppBuffer, info);
474  }
475 
476  int
477  ImageProcessor::getImages(std::string providerName,
478  CByteImage** ppImages,
479  armarx::MetaInfoSizeBasePtr& info)
480  {
481  int numberOfImages = getNumberOfImages(providerName);
482 
483  void** ppBuffer = new void*[numberOfImages];
484 
485  for (int i = 0; i < numberOfImages; ++i)
486  {
487  ppBuffer[i] = (void*)ppImages[i]->pixels;
488  }
489 
490  numberOfImages = getImages(providerName, ppBuffer, info);
491  delete[] ppBuffer;
492 
493  return numberOfImages;
494  }
495 
496  int
497  ImageProcessor::getImages(std::string providerName,
498  const std::vector<CByteImageUPtr>& ppImages,
499  MetaInfoSizeBasePtr& info)
500  {
501  int numberOfImages = getNumberOfImages(providerName);
502 
503  void** ppBuffer = new void*[numberOfImages];
504 
505  for (int i = 0; i < numberOfImages; ++i)
506  {
507  ppBuffer[i] = (void*)ppImages.at(i)->pixels;
508  }
509 
510  numberOfImages = getImages(providerName, ppBuffer, info);
511  delete[] ppBuffer;
512 
513  return numberOfImages;
514  }
515 
516  int
517  ImageProcessor::getImages(std::string providerName,
518  CFloatImage** ppImages,
519  armarx::MetaInfoSizeBasePtr& info)
520  {
521  int numberOfImages = getNumberOfImages(providerName);
522 
523  void** ppBuffer = new void*[numberOfImages];
524 
525  for (int i = 0; i < numberOfImages; ++i)
526  {
527  ppBuffer[i] = (void*)ppImages[i]->pixels;
528  }
529 
530  numberOfImages = getImages(providerName, ppBuffer, info);
531  delete[] ppBuffer;
532 
533  return numberOfImages;
534  }
535 
536  int
537  ImageProcessor::getImages(std::string providerName,
538  void** ppBuffer,
539  armarx::MetaInfoSizeBasePtr& info)
540  {
541  int numberImages = -1;
542  {
543  // lock image provider info mutex for reading (and changing imageAvailable);
544 
545  std::unique_lock lock(imageProviderInfoMutex);
546 
547  // find image provider
548  std::map<std::string, ImageProviderInfo>::iterator iter =
549  imageProviderInfoMap.find(providerName);
550 
551  if (iter == imageProviderInfoMap.end())
552  {
553  ARMARX_ERROR << "Trying to retrieve images from unknown image provider. Call "
554  "useImageProvider before";
555  return 0;
556  }
557 
558  numberImages = iter->second.numberImages;
559 
560  // check if new images are available
561  if (!iter->second.imageAvailable)
562  {
563  ARMARX_IMPORTANT << "No image available";
564  return 0;
565  }
566 
567 
568  ImageProviderInfo& providerInfo = iter->second;
569  if (providerInfo.imageTransferMode == eIceTransfer)
570  {
571  CompressedImageProviderInterfacePrx compressedImageProvider;
572  if (compressionType != eNoCompression)
573  {
574  compressedImageProvider =
575  CompressedImageProviderInterfacePrx::checkedCast(iter->second.proxy);
576  if (!compressedImageProvider)
577  {
579  << deactivateSpam(10000000, iter->first)
580  << "Trying to use image provider as "
581  "CompressedImageProviderInterfacePrx, but it is not of this type: "
582  << iter->second.proxy->ice_id();
583  }
584  }
585  if (compressionType != eNoCompression && compressedImageProvider)
586  {
587  ARMARX_DEBUG << deactivateSpam(10) << "Using compressed images";
588  auto blob = compressedImageProvider->getCompressedImagesAndMetaInfo(
589  compressionType, compressionQuality, providerInfo.info);
590  ARMARX_CHECK_GREATER(blob.size(), 0);
591  ARMARX_DEBUG << deactivateSpam(10) << "Got image blob of size " << blob.size();
592  cv::Mat mat = cv::imdecode(blob, cv::IMREAD_COLOR);
593  ARMARX_CHECK_GREATER(mat.size().area(), 0);
594  ARMARX_DEBUG << deactivateSpam(10) << "decoded image to size "
595  << mat.size().width << "x" << mat.size().height
596  << ", bpp: " << mat.channels();
597  providerInfo.buffer = Blob(mat.datastart, mat.dataend);
598  ARMARX_DEBUG << deactivateSpam(10) << "decoded blob size "
599  << providerInfo.buffer.size();
600  }
601  else
602  {
603  Blob blob;
604  try
605  {
606  blob = iter->second.proxy->getImagesAndMetaInfo(providerInfo.info);
608  << deactivateSpam(1) << "The image is "
609  << (TimeUtil::GetTime() -
610  IceUtil::Time::microSeconds(providerInfo.info->timeProvided))
611  .toMilliSecondsDouble()
612  << " ms old, timestamp: " << providerInfo.info->timeProvided;
613  }
614  catch (...)
615  {
617  << "using fall back remote procedure call without timestamp!";
618 
619  providerInfo.info->timeProvided = TimeUtil::GetTime().toMicroSeconds();
620  blob = iter->second.proxy->getImages();
621  }
622 
623  blob.swap(providerInfo.buffer);
624  }
625  }
626  else
627  {
628  usedImageProviders[providerName]->getData(providerInfo.buffer, providerInfo.info);
629  }
630  // poll images
631  int imageSize = providerInfo.imageFormat.dimension.width *
632  providerInfo.imageFormat.dimension.height *
633  providerInfo.imageFormat.bytesPerPixel;
634 
635  // copy images
636  for (int i = 0; i < numberImages; i++)
637  {
639  iter->second, &iter->second.buffer[0] + i * imageSize, ppBuffer[i]);
640  }
641 
642  info = iter->second.info;
643 
644  // set image available to false
645  iter->second.imageAvailable = false;
646  }
647 
648 
649  // update statistics
650  std::unique_lock lock(statisticsMutex);
651  statistics[providerName].pollingFPS.update();
652 
653  return numberImages;
654  }
655 
656  int
657  ImageProcessor::getNumberOfImages(const std::string& providerName)
658  {
659  if (imageProviderInfoMap.size() == 0 && providerName.empty())
660  {
661  ARMARX_ERROR << "Calling getNumberOfImages() without ImageProvider name, and no "
662  "ImageProvider is available - did you forget to call useImageProvider?";
663  return 0;
664  }
665  else if (imageProviderInfoMap.size() > 1 && providerName.empty())
666  {
667  std::string outputText =
668  "Several image providers are available and no name was specified when calling "
669  "getNumberOfImages() - using the first one in the list:";
670  std::map<std::string, ImageProviderInfo>::iterator iter;
671 
672  for (iter = imageProviderInfoMap.begin(); iter != imageProviderInfoMap.end(); iter++)
673  {
674  outputText << " " << iter->first;
675  }
676 
677  ARMARX_VERBOSE << outputText;
678  }
679 
680  int numberOfImages = 0;
681 
682  if (providerName.empty())
683  {
684  std::unique_lock lock(imageProviderInfoMutex);
685 
686  numberOfImages = imageProviderInfoMap.begin()->second.numberImages;
687  }
688  else
689  {
690  std::unique_lock lock(imageProviderInfoMutex);
691 
692  // find image provider
693  std::map<std::string, ImageProviderInfo>::iterator iter =
694  imageProviderInfoMap.find(providerName);
695 
696  if (iter == imageProviderInfoMap.end())
697  {
698  ARMARX_ERROR << "Trying to retrieve images from unknown image provider. Call "
699  "useImageProvider before";
700  return 0;
701  }
702 
703  numberOfImages = iter->second.numberImages;
704  }
705 
706  return numberOfImages;
707  }
708 
710  ImageProcessor::getImageTransferStats(std::string providerName, bool resetStats)
711  {
712  std::unique_lock lock(statisticsMutex);
713 
714  std::map<std::string, ImageTransferStats>::iterator iter = statistics.find(providerName);
715 
716  if (iter == statistics.end())
717  {
718  ARMARX_ERROR << "Requesting statistics for unknown image provider (" << providerName
719  << ")";
720  return ImageTransferStats();
721  }
722 
723  ImageTransferStats stats = iter->second;
724 
725  if (resetStats)
726  {
727  iter->second.imageProviderFPS.reset();
728  iter->second.pollingFPS.reset();
729  }
730  else
731  {
732  iter->second.imageProviderFPS.recalculate();
733  iter->second.pollingFPS.recalculate();
734  }
735 
736  return stats;
737  }
738 
739  MetaInfoSizeBasePtr
740  ImageProcessor::getImageMetaInfo(const std::string& imageProviderName) const
741  {
742 
743  ARMARX_WARNING << "deprecated. Use getImages() instead.";
744 
745  if (usedImageProviders.empty())
746  {
747  ARMARX_WARNING << "usedImageProviders is empty";
748  return NULL;
749  }
750  if (imageProviderName.empty())
751  {
752  return usedImageProviders.begin()->second->getMetaInfo();
753  }
754  else
755  {
756  auto it = usedImageProviders.find(imageProviderName);
757  if (it != usedImageProviders.end())
758  {
759  return it->second->getMetaInfo();
760  }
761  else
762  {
763  ARMARX_ERROR << "Requesting meta info for unknown image provider ("
764  << imageProviderName << ")";
765  return NULL;
766  }
767  }
768  }
769 
770  void
771  ImageProcessor::setFramerate(float fps)
772  {
773  this->desiredFps = fps;
774  if (processorTask)
775  {
776  processorTask->changeInterval(1000.f / fps);
777  }
778  }
779 
780  float
781  ImageProcessor::getFramerate() const
782  {
783  return desiredFps;
784  }
785 
786  void
787  ImageProcessor::setCompressionType(CompressionType compressionType, int compressionQuality)
788  {
789  ARMARX_VERBOSE << "Setting compression to " << (int)compressionType << " and quality "
790  << compressionQuality;
791  this->compressionType = compressionType;
792  this->compressionQuality = compressionQuality;
793  }
794 
795  void
796  ImageProcessor::reportImageAvailable(const std::string& providerName, const Ice::Current& c)
797  {
798  {
799  // lock mutex for reading
800  std::unique_lock lock(imageProviderInfoMutex);
801  // find provider
802  std::map<std::string, ImageProviderInfo>::iterator iter =
803  imageProviderInfoMap.find(providerName);
804 
805  if (iter == imageProviderInfoMap.end())
806  {
807  ARMARX_ERROR << deactivateSpam(10, providerName)
808  << "Received notification from unknown imageprovider (" << providerName
809  << ")";
810 
811  return;
812  }
813 
814  iter->second.imageAvailable = true;
815  iter->second.imageAvailableEvent->notify_all();
816  ARMARX_DEBUG << "Got notification of image provider " << providerName;
817  }
818 
819  // update statistics
820  std::unique_lock lock(statisticsMutex);
821  statistics[providerName].imageProviderFPS.update();
822  }
823 
824  void
825  ImageProcessor::cleanup()
826  {
827  std::map<std::string, ImageProviderInfo>::iterator iter = imageProviderInfoMap.begin();
828 
829  while (iter != imageProviderInfoMap.end())
830  {
831  iter++;
832  }
833 
834  if (resultImageProvider)
835  {
836  getArmarXManager()->removeObjectBlocking(resultImageProvider);
837  }
838  }
839 
840  void
841  ImageProcessor::componentPropertiesUpdated(const std::set<std::string>& changedProperties)
842  {
843  // ARMARX_INFO << VAROUT(changedProperties);
844  if (changedProperties.count("CompressionType"))
845  {
846  setCompressionType(getProperty<CompressionType>("CompressionType").getValue());
847  }
848  if (changedProperties.count("CompressionQuality"))
849  {
850  setCompressionType(getProperty<CompressionType>("CompressionType").getValue(),
851  getProperty<int>("CompressionQuality").getValue());
852  }
853  }
854 
855  int
856  ImageProcessor::getCompressionQuality() const
857  {
858  return compressionQuality;
859  }
860 
861  CompressionType
862  ImageProcessor::getCompressionType() const
863  {
864  return compressionType;
865  }
866 } // namespace visionx
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
visionx::ImageProviderInfo::numberImages
int numberImages
Number of images.
Definition: ImageProcessor.h:519
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
OnScopeExit.h
ArmarXManager.h
visionx::ImageTransferStats
The ImageTransferStats class provides information on the connection between ImageProvider and ImagePr...
Definition: ImageProcessor.h:455
ARMARX_CHECK_GREATER
#define ARMARX_CHECK_GREATER(lhs, rhs)
This macro evaluates whether lhs is greater (>) than rhs and if it turns out to be false it will thro...
Definition: ExpressionException.h:116
visionx::ImageTransferStats::imageProviderFPS
FPSCounter imageProviderFPS
Statistics for the images announced by the ImageProvider.
Definition: ImageProcessor.h:467
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
visionx::ImageProviderInfo::imageFormat
ImageFormatInfo imageFormat
Image format struct that contains all necessary image information.
Definition: ImageProcessor.h:509
UnsupportedImageConversionException.h
visionx::ImageProviderInfo
Definition: ImageProcessor.h:479
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:75
visionx::FPSCounter::reset
void reset()
Resets the FPS counter to its initial state.
Definition: FPSCounter.cpp:51
visionx::ImageProviderInfo::imageAvailable
bool imageAvailable
Indicates whether an image is available.
Definition: ImageProcessor.h:524
ImageProcessor.h
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
ArmarXObjectScheduler.h
visionx::ImageProviderInfo::imageAvailableEvent
std::shared_ptr< std::condition_variable > imageAvailableEvent
Conditional variable used internally for synchronization purposes.
Definition: ImageProcessor.h:529
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
HardwareId.h
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
visionx::tools::convertImage
void convertImage(const ImageFormatInfo &imageFormat, const ImageType destinationImageType, void *inputData, void *outputData)
This converts the input image data into a desired destination image data type specified in the given ...
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
ExpressionException.h
visionx::ImageProviderInfo::destinationImageType
ImageType destinationImageType
Required image destination type.
Definition: ImageProcessor.h:504
visionx::ImageProviderInfo::proxy
ImageProviderInterfacePrx proxy
proxy to image provider
Definition: ImageProcessor.h:485
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ImageProcessorPropertyDefinitions
Definition: ImageProcessor.h:61
ImageUtil.h
armarx::IceSharedMemoryConsumer
Definition: IceSharedMemoryConsumer.h:50
visionx::ImageProviderInfo::info
armarx::MetaInfoSizeBasePtr info
meta info
Definition: ImageProcessor.h:495
TypeMapping.h
visionx::ImageProviderInfo::buffer
std::vector< unsigned char > buffer
memory block
Definition: ImageProcessor.h:490
armarx::PeriodicTask
Definition: ArmarXManager.h:70
visionx::ImageProviderInfo::imageTransferMode
ImageTransferMode imageTransferMode
Transfer mode of images.
Definition: ImageProcessor.h:514
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
Exception.h