OpenNIImageProvider.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::Component
19  * @author David Gonzalez (david dot gonzalez at kit dot edu)
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "OpenNIImageProvider.h"
26 #include "Helpers/helpers.h"
27 
28 // boost
29 #include <boost/algorithm/string.hpp>
30 #include <boost/lexical_cast.hpp>
31 
32 // VisionXCore
35 
36 // VisionXTools
39 
40 // ArmarXCore
42 
43 using namespace armarx;
44 using namespace visionx::tools;
45 
46 
47 namespace visionx
48 {
49 
50 
51  bool OpenNIImageProvider::isBackEndInitialized = false;
52 
53  void OpenNIImageProvider::onInitCapturingImageProvider()
54  {
55  //-------------------------------------------------------------------------
56 
57  coloredPoint3DBuffer = NULL;
58 
59  normalizedDepthCells = NULL;
60 
61  isModuleInitialized = false;
62 
63  //-------------------------------------------------------------------------
64 
65  uri = getProperty<std::string>("DeviceURI").getValue();
66 
67  videoDimension = getProperty<ImageDimension>("VideoMode").getValue();
68 
69  frameRate = getProperty<float>("FrameRate").getValue();
70 
71  imageType = getProperty<ImageType>("ImageType").getValue();
72 
73  ARMARX_INFO << "Information: URI : " << uri << flush;
74 
75  ARMARX_INFO << "Information: Video Dimension : (" << videoDimension.width << "," << videoDimension.height << ")" << flush;
76 
77  ARMARX_INFO << "Information: Frame Rate : " << frameRate << flush;
78 
79  ARMARX_INFO << "Information: Image Type : " << imageType << flush;
80 
81  setNumberImages(1);
82 
83  setImageFormat(videoDimension, imageType, eBayerPatternBg);
84 
85  setImageSyncMode(eCaptureSynchronization);
86 
87  //-------------------------------------------------------------------------
88 
89  if (!isBackEndInitialized)
90  {
91  if (openni::OpenNI::initialize() == openni::STATUS_OK)
92  {
93  isBackEndInitialized = true;
94 
95  ARMARX_INFO << "Information: OpenNI Initialized successfully." << flush;
96 
97  }
98  else
99  {
100  ARMARX_ERROR << "Error: While intializing OpenNI : " << openni::OpenNI::getExtendedError() << flush;
101  }
102  }
103  }
104 
105  void OpenNIImageProvider::onExitCapturingImageProvider()
106  {
107  StopDevice();
108 
109  DestroyDataStructure();
110 
111  ARMARX_INFO << "Information : Exit Capturing." << flush;
112  }
113 
114  void OpenNIImageProvider::onStartCapture(float frameRate)
115  {
116  ARMARX_INFO << "Information: Starting capturing..." << flush;
117 
118  bool ERROR = false;
119 
120  if (isBackEndInitialized)
121  {
122  const bool UseAnyDevice = (!uri.length()) || (uri == std::string("ANY_DEVICE")) || (uri == std::string("Any")) || (uri == std::string("any")) || (uri == std::string("ANY"));
123 
124  const bool LookForDeviceTarget = !UseAnyDevice;
125 
126  bool DeviceTargetFound = false;
127 
128  openni::Array<openni::DeviceInfo> FoundDevices;
129 
130  openni::OpenNI::enumerateDevices(&FoundDevices);
131 
132  const int TotalDevices = FoundDevices.getSize();
133 
134  ARMARX_INFO << "Information: Total openni devices found : " << TotalDevices << flush;
135 
136  if (TotalDevices)
137  {
138  for (int i = 0 ; i < TotalDevices ; ++i)
139  {
140  const std::string CurrentURI = std::string(FoundDevices[i].getUri());
141 
142  if (LookForDeviceTarget && (uri == CurrentURI))
143  {
144  ARMARX_INFO << "Target found: openni device[" << i << "] Uri = " << CurrentURI << flush;
145 
146  DeviceTargetFound = true;
147  }
148  else
149  {
150  ARMARX_INFO << "Information: Available device OpenNI device[" << i << "] Uri = " << CurrentURI << flush;
151  }
152  }
153 
154  const int Width = videoDimension.width;
155 
156  const int Height = videoDimension.height;
157 
158  const int Fps = EnsureFPS(int(round(frameRate)));
159 
160  ARMARX_INFO << "Information: Video Dimension : (" << Width << "," << Height << ")" << flush;
161 
162  ARMARX_INFO << "Information: Frame Rate : " << Fps << flush;
163 
164  if (LookForDeviceTarget)
165  {
166  if (DeviceTargetFound)
167  {
168  if (StartDevice(uri.c_str(), Width, Height, Fps))
169  {
170  ARMARX_INFO << "openni device[" << uri << "] started succesfully" << flush;
171 
172  if (CreateDataStructures())
173  {
174  ARMARX_ERROR << "Error: Data structures created succesffully" << flush;
175 
176  ERROR = false;
177  }
178  else
179  {
180  ARMARX_ERROR << "Error: Data structures creation failure" << flush;
181 
182  ERROR = true;
183  }
184  }
185  else
186  {
187  ARMARX_ERROR << "Error: openni device[" << uri << "] started failure" << flush;
188 
189  ERROR = true;
190  }
191  }
192  else
193  {
194  ARMARX_ERROR << "Error: openni device Uri = " << uri << " not found" << flush;
195 
196  ERROR = true;
197  }
198  }
199  else
200  {
201  if (StartDevice(openni::ANY_DEVICE, Width, Height, Fps))
202  {
203  ARMARX_INFO << "Infromation: OpenNI device started succesfully." << flush;
204 
205  if (CreateDataStructures())
206  {
207  ARMARX_INFO << " Data structures created succesffully" << flush;
208 
209  ERROR = false;
210  }
211  else
212  {
213  ARMARX_ERROR << " Error: Data structures creation failure" << flush;
214 
215  ERROR = true;
216  }
217 
218  }
219  else
220  {
221  ARMARX_ERROR << "Error: openni device started failure" << flush;
222 
223  ERROR = true;
224  }
225  }
226 
227  }
228  else
229  {
230  ARMARX_ERROR << "Error: No openni devices are available" << flush;
231 
232  ERROR = true;
233  }
234  }
235  else
236  {
237  ARMARX_ERROR << "Error: Openni backend not initialized" << flush;
238 
239  ERROR = true;
240  }
241 
242  if (ERROR)
243  {
244  throw visionx::exceptions::user::StartingCaptureFailedException("Opening cameras failed!");
245  }
246  }
247 
248 
249  void OpenNIImageProvider::onStopCapture()
250  {
251  StopDevice();
252 
253  DestroyDataStructure();
254  }
255 
256 
257  bool OpenNIImageProvider::capture(void** ppImageBuffers)
258  {
259  if (!isModuleInitialized)
260  {
261  return false;
262  }
263 
264  bool succeeded = false;
265 
266  switch (getImageFormat().type)
267  {
268  /*case visionx::ePointsScan:
269  succeeded = true;
270  break;*/
271 
272  case visionx::eColoredPointsScan:
273  succeeded = CaptureColoredPoint();
274  break;
275 
276  /*
277  * Handle image types which are not supported by OpenNIImageProvider
278  */
279  default:
280  ARMARX_ERROR << "Error: Image type not supported by OpenNIImageProvider!" << flush;
281  return false;
282  }
283 
284  if (!succeeded)
285  {
286  ARMARX_ERROR << "Error: Capturing failed!" << flush;
287  return false;
288  }
289 
290  {
291  armarx::SharedMemoryScopedWriteLockPtr lock = getScopedWriteLock();
292 
293  ImageFormatInfo imageFormat = getImageFormat();
294 
295  const int BufferSize = imageFormat.dimension.width * imageFormat.dimension.height * imageFormat.bytesPerPixel;
296 
297  memcpy(ppImageBuffers[0], coloredPoint3DBuffer, BufferSize);
298 
299  }
300 
301  return true;
302  }
303 
304  /*
305  void OpenNIImageProvider::provideImages(CByteImage** images)
306  {
307  if(numberImages == 0)
308  return;
309 
310  const int Width = videoDimension.width;
311 
312  const int Height = videoDimension.height;
313 
314  CByteImage Result = Display(m_pColoredPoint3DBuffer,Width,Height,true);
315 
316  memcpy(images[0]->pixels, Result.pixels, Width * Height * Result.bytesPerPixel);
317  }
318 
319  void OpenNIImageProvider::provideImages(CFloatImage** images)
320  {
321  if(numberImages == 0)
322  return;
323 
324  const int Width = videoDimension.width;
325 
326  const int Height = videoDimension.height;
327 
328  const visionx::ColoredPoint3D* pColoredPoint3DBuffer = pColoredPoint3DBufferBase;
329 
330  const visionx::ColoredPoint3D* const pEndColoredPoint3DBuffer = pColoredPoint3DBufferBase + (Width * Height);
331 
332  float* pDepthPixel = images[0]->pixels;
333 
334  while(pColoredPoint3DBuffer<pEndColoredPoint3DBuffer)
335  {
336  *pDepthPixel++ = pColoredPoint3DBuffer->m_Point.z;
337 
338  ++pColoredPoint3DBuffer;
339  }
340  }
341  */
342 
343  bool OpenNIImageProvider::StartDevice(const char* pDeviceURI, const int Width, const int Height, const int Fps)
344  {
345  if (isModuleInitialized)
346  {
347  return false;
348  }
349 
350  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
351 
352  if (deviceOpenNI.open(pDeviceURI) != openni::STATUS_OK)
353  {
354  ARMARX_ERROR << "Error: Cannot open device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
355 
356  return false;
357  }
358 
359  if (!deviceOpenNI.hasSensor(openni::SENSOR_DEPTH))
360  {
361  ARMARX_ERROR << "Error: Device (" << pDeviceURI << ") [ has not depth sensor ]" << flush;
362 
363  return false;
364  }
365 
366  if (!deviceOpenNI.hasSensor(openni::SENSOR_COLOR))
367  {
368  ARMARX_ERROR << "Error: Device (" << pDeviceURI << ") [ has not color sensor ]" << flush;
369 
370  return false;
371  }
372 
373  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
374 
375  if (depthStreamOpenNI.create(deviceOpenNI, openni::SENSOR_DEPTH) != openni::STATUS_OK)
376  {
377  ARMARX_ERROR << "Error: Cannot create Depth stream on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
378 
379  return false;
380  }
381 
382  if (!depthStreamOpenNI.isValid())
383  {
384  ARMARX_ERROR << "Error: Cannot create Depth stream on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
385 
386  return false;
387  }
388 
389  openni::VideoMode CurrentDepthStreamMode = depthStreamOpenNI.getVideoMode();
390 
391  ARMARX_INFO << "Information: Depth Stream Default Video Dimension : (" << CurrentDepthStreamMode.getResolutionX() << "," << CurrentDepthStreamMode.getResolutionY() << ")" << flush;
392 
393  ARMARX_INFO << "Information: Depth Stream Default Frame Rate : " << CurrentDepthStreamMode.getFps() << flush;
394 
395  ARMARX_INFO << "Information: Depth Stream Target Video Dimension : (" << Width << "," << Height << ")" << flush;
396 
397  ARMARX_INFO << "Information: Depth Stream Target Frame Rate : " << Fps << flush;
398 
399  CurrentDepthStreamMode.setResolution(Width, Height);
400 
401  CurrentDepthStreamMode.setFps(Fps);
402 
403  if (depthStreamOpenNI.setVideoMode(CurrentDepthStreamMode) != openni::STATUS_OK)
404  {
405  ARMARX_ERROR << "Error: Cannot set Depth stream settings (" << Width << "," << Height << "," << Fps << ") Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
406 
407  return false;
408  }
409 
410  if (depthStreamOpenNI.start() != openni::STATUS_OK)
411  {
412  depthStreamOpenNI.destroy();
413 
414  ARMARX_ERROR << "Error: Cannot start Depth stream on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
415 
416  return false;
417  }
418 
419  CurrentDepthStreamMode = depthStreamOpenNI.getVideoMode();
420 
421  ARMARX_INFO << "Information: Depth Stream Active Video Dimension : (" << CurrentDepthStreamMode.getResolutionX() << "," << CurrentDepthStreamMode.getResolutionY() << ")" << flush;
422 
423  ARMARX_INFO << "Information: Depth Stream Active Frame Rate : " << CurrentDepthStreamMode.getFps() << flush;
424 
425  if (!depthStreamOpenNI.isValid())
426  {
427  ARMARX_ERROR << "Error: Cannot create Depth stream on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
428 
429  return false;
430  }
431 
432  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
433 
434  if (colorStreamOpenNI.create(deviceOpenNI, openni::SENSOR_COLOR) != openni::STATUS_OK)
435  {
436  ARMARX_ERROR << "Error: Cannot create Color stream on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
437 
438  return false;
439  }
440 
441  if (!colorStreamOpenNI.isValid())
442  {
443  ARMARX_ERROR << "Error: Cannot create Color stream on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
444 
445  return false;
446  }
447 
448  openni::VideoMode CurrentColorStreamMode = colorStreamOpenNI.getVideoMode();
449 
450  ARMARX_INFO << "Information: Color Stream Default Video Dimension : (" << CurrentColorStreamMode.getResolutionX() << "," << CurrentColorStreamMode.getResolutionY() << ")" << flush;
451 
452  ARMARX_INFO << "Information: Color Stream Default Frame Rate : " << CurrentColorStreamMode.getFps() << flush;
453 
454  ARMARX_INFO << "Information: Color Stream Target Video Dimension : (" << Width << "," << Height << ")" << flush;
455 
456  ARMARX_INFO << "Information: Color Stream Target Frame Rate : " << Fps << flush;
457 
458  CurrentColorStreamMode.setResolution(Width, Height);
459 
460  CurrentColorStreamMode.setFps(Fps);
461 
462 
463  if (colorStreamOpenNI.setVideoMode(CurrentColorStreamMode) != openni::STATUS_OK)
464  {
465  ARMARX_ERROR << "Error: Cannot set Color stream settings (" << Width << "," << Height << "," << Fps << ") Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
466 
467  return false;
468  }
469 
470  if (colorStreamOpenNI.start() != openni::STATUS_OK)
471  {
472  depthStreamOpenNI.destroy();
473 
474  ARMARX_ERROR << "Error: Cannot start Color stream on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
475 
476  return false;
477  }
478 
479  CurrentColorStreamMode = colorStreamOpenNI.getVideoMode();
480 
481  ARMARX_INFO << "Information: Color Stream Active Video Dimension : (" << CurrentColorStreamMode.getResolutionX() << "," << CurrentColorStreamMode.getResolutionY() << ")" << flush;
482 
483  ARMARX_INFO << "Information: Color Stream Active Frame Rate : " << CurrentColorStreamMode.getFps() << flush;
484 
485  if (!colorStreamOpenNI.isValid())
486  {
487  ARMARX_ERROR << "Error: Cannot create Color stream on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
488 
489  return false;
490  }
491 
492  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
493 
494  if (deviceOpenNI.setDepthColorSyncEnabled(true) != openni::STATUS_OK)
495  {
496  ARMARX_WARNING << "Warning: Cannot synchronize Depth and Color on Device (" << pDeviceURI << ") => " << openni::OpenNI::getExtendedError() << flush;
497  }
498 
499  if (deviceOpenNI.isImageRegistrationModeSupported(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR))
500  {
501  if (deviceOpenNI.setImageRegistrationMode(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR) != openni::STATUS_OK)
502  {
503  ARMARX_WARNING << "Warning: Device supports depth-to-color registration but could not be enabled (" << pDeviceURI << ") =>" << openni::OpenNI::getExtendedError() << flush;
504  }
505  }
506 
507  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
508 
509  isModuleInitialized = true;
510 
511  return true;
512  }
513 
514  bool OpenNIImageProvider::CreateDataStructures()
515  {
516  DestroyDataStructure();
517 
518  const int Width = videoDimension.width;
519 
520  const int Height = videoDimension.height;
521 
522  const int Area = Width * Height;
523 
524  coloredPoint3DBuffer = new visionx::ColoredPoint3D[Area];
525 
526  memset(coloredPoint3DBuffer, 0, sizeof(visionx::ColoredPoint3D)*Area);
527 
528  normalizedDepthCells = new NormalizedDepthCell[Area];
529 
530  memset(normalizedDepthCells, 0, sizeof(NormalizedDepthCell)*Area);
531 
532  InitializeNormalizedDepthCells();
533 
534  return true;
535  }
536 
537  bool OpenNIImageProvider::InitializeNormalizedDepthCells()
538  {
539  if (!normalizedDepthCells)
540  {
541  return false;
542  }
543 
544  const int Width = videoDimension.width;
545 
546  const int Height = videoDimension.height;
547 
548  const float XZFactor = std::tan(depthStreamOpenNI.getHorizontalFieldOfView() / 2.0f) * 2.0f;
549 
550  const float YZFactor = std::tan(depthStreamOpenNI.getVerticalFieldOfView() / 2.0f) * 2.0f;
551 
552  NormalizedDepthCell* pNormalizedDepthCell = normalizedDepthCells;
553 
554  for (int Y = 0 ; Y < Height ; ++Y)
555  {
556  const float NY = (0.5f - (float(Y) / float(Height))) * YZFactor;
557 
558  for (int X = 0 ; X < Width ; ++X, ++pNormalizedDepthCell)
559  {
560  pNormalizedDepthCell->nx = ((float(X) / float(Width)) - 0.5f) * XZFactor;
561 
562  pNormalizedDepthCell->ny = NY;
563  }
564  }
565 
566  return true;
567  }
568 
569  bool OpenNIImageProvider::StopDevice()
570  {
571  if (isModuleInitialized)
572  {
573  depthStreamOpenNI.stop();
574 
575  depthStreamOpenNI.destroy();
576 
577  colorStreamOpenNI.stop();
578 
579  colorStreamOpenNI.destroy();
580 
581  deviceOpenNI.close();
582 
583  isModuleInitialized = false;
584  }
585 
586  //TODO: Verifiy this out value
587  return true;
588  }
589 
590  bool OpenNIImageProvider::DestroyDataStructure()
591  {
592  if (coloredPoint3DBuffer)
593  {
594  delete[] coloredPoint3DBuffer;
595 
596  coloredPoint3DBuffer = NULL;
597  }
598 
599  if (normalizedDepthCells)
600  {
601  delete[] normalizedDepthCells;
602 
603  normalizedDepthCells = NULL;
604  }
605 
606  return true;
607  }
608 
609  bool OpenNIImageProvider::CaptureColoredPoint()
610  {
611  if (!isModuleInitialized)
612  {
613  return false;
614  }
615 
616  if (!coloredPoint3DBuffer)
617  {
618  return false;
619  }
620 
621  if (!normalizedDepthCells)
622  {
623  return false;
624  }
625 
626  openni::VideoStream* ppStreams[2] = {&depthStreamOpenNI, &colorStreamOpenNI};
627 
628  bool HasBeenCaptured[2] = {false, false};
629 
630  while (!(HasBeenCaptured[0] && HasBeenCaptured[1]))
631  {
632  int StreamIndex = -1;
633 
634  bool CaptureSuccesfull = false;
635 
636  for (int i = 0; i < 3; ++i)
637  {
638  if (openni::OpenNI::waitForAnyStream(ppStreams, 2, &StreamIndex, 5000) == openni::STATUS_OK)
639  {
640 
641  CaptureSuccesfull = true;
642 
643  break;
644  }
645  else
646  {
647  ARMARX_WARNING << "Warning: Capturing Try not succesfull ->" << openni::OpenNI::getExtendedError() << flush;
648  }
649  }
650 
651  if (!CaptureSuccesfull)
652  {
653  return false;
654  }
655 
656  if (!(StreamIndex >= 0) && (StreamIndex <= 1))
657  {
658  return false;
659  }
660 
661  if (ppStreams[StreamIndex]->readFrame(&frameOpenNI) != openni::STATUS_OK)
662  {
663  return false;
664  }
665 
666  switch (StreamIndex)
667  {
668  case 0:
669 
670  if (!DispatchDepthFrame())
671  {
672  return false;
673  }
674 
675  break;
676 
677  case 1:
678 
679  if (!DispatchColorFrame())
680  {
681  return false;
682  }
683 
684  break;
685 
686  default:
687  return false;
688  }
689 
690  HasBeenCaptured[StreamIndex] = true;
691  }
692 
693 
694  /*
695  //Only for Testing and Debug
696  const int Width = videoDimension.width;
697 
698  const int Height = videoDimension.height;
699 
700  CByteImage* pColorImage = Display(m_pColoredPoint3DBuffer,Width,Height,true);
701 
702  CByteImage* pDepthImage = Display(m_pColoredPoint3DBuffer,Width,Height,false);
703 
704  if(pColorImage)
705  {
706  pColorImage->SaveToFile("/home/gonzalez/ColorImage.bmp");
707  delete pColorImage;
708  pColorImage = NULL;
709  }
710 
711  if(pDepthImage)
712  {
713  pDepthImage->SaveToFile("/home/gonzalez/DepthImage.bmp");
714  delete pDepthImage;
715  pDepthImage = NULL;
716  }
717  */
718 
719 
720  return true;
721  }
722 
723  bool OpenNIImageProvider::DispatchDepthFrame()
724  {
725  const NormalizedDepthCell* pNormalizedDepthCell = normalizedDepthCells;
726 
727  visionx::ColoredPoint3D* pColoredPoint3D = coloredPoint3DBuffer;
728 
729  const visionx::ColoredPoint3D* const pEndColoredPoint3D = coloredPoint3DBuffer + (videoDimension.width * videoDimension.height);
730 
731  uint16_t* pDepthPixel = (uint16_t*)(frameOpenNI.getData());
732 
733  while (pColoredPoint3D < pEndColoredPoint3D)
734  {
735  pColoredPoint3D->point.z = float(*pDepthPixel++);
736 
737  if (pColoredPoint3D->point.z)
738  {
739  pColoredPoint3D->point.x = pNormalizedDepthCell->nx * pColoredPoint3D->point.z;
740 
741  pColoredPoint3D->point.y = pNormalizedDepthCell->ny * pColoredPoint3D->point.z;
742  }
743  else
744  {
745  pColoredPoint3D->point.x = 0.0f;
746 
747  pColoredPoint3D->point.y = 0.0f;
748  }
749 
750  ++pColoredPoint3D;
751 
752  ++pNormalizedDepthCell;
753  }
754 
755  return true;
756  }
757 
758 
759  bool OpenNIImageProvider::DispatchColorFrame()
760  {
761  visionx::ColoredPoint3D* pColoredPoint3D = coloredPoint3DBuffer;
762 
763  const visionx::ColoredPoint3D* const pEndColoredPoint3D = coloredPoint3DBuffer + (videoDimension.width * videoDimension.height);
764 
765  unsigned char* pColorPixel = (unsigned char*) frameOpenNI.getData();
766 
767  while (pColoredPoint3D < pEndColoredPoint3D)
768  {
769  pColoredPoint3D->color.r = *pColorPixel++;
770 
771  pColoredPoint3D->color.g = *pColorPixel++;
772 
773  pColoredPoint3D->color.b = *pColorPixel++;
774 
775  pColoredPoint3D->color.a = 0;
776 
777  ++pColoredPoint3D;
778  }
779 
780  return true;
781  }
782 
783  int OpenNIImageProvider::EnsureFPS(const int FPS)
784  {
785  if (FPS == 30)
786  {
787  return FPS;
788  }
789 
790  else if (FPS == 15)
791  {
792  return FPS;
793  }
794 
795  const int DeviationTo30 = std::abs(FPS - 30);
796 
797  const int DeviationTo15 = std::abs(FPS - 15);
798 
799  ARMARX_WARNING << "Warning: Selected FPS = " << FPS << "not supported by device" << flush;
800 
801  if (DeviationTo30 < DeviationTo15)
802  {
803  ARMARX_ERROR << "Warning: Closest Fps = [30] supported will be used" << flush;
804 
805  return 30;
806  }
807  else
808  {
809  ARMARX_ERROR << "Warning: Closest Fps = [15] supported will be used" << flush;
810 
811  return 15;
812  }
813  }
814 }
StartingCaptureFailedException.h
Area
ldouble Area(const point2d &a, const point2d &b, const point2d &c)
Definition: gdiam.cpp:1564
armarx::MessageTypeT::ERROR
@ ERROR
visionx::tools
Definition: PCLUtilities.cpp:4
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
OpenNIImageProvider.h
visionx::OpenNIImageProvider::NormalizedDepthCell::nx
float nx
Definition: OpenNIImageProvider.h:270
armarx::SharedMemoryScopedWriteLockPtr
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
Definition: SharedMemoryProvider.h:46
visionx::OpenNIImageProvider::NormalizedDepthCell
OpenNI Capture.
Definition: OpenNIImageProvider.h:268
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
Property.h
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
visionx::exceptions::user::StartingCaptureFailedException
Definition: StartingCaptureFailedException.h:31
FrameRateNotSupportedException.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
float
#define float
Definition: 16_Level.h:22
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
visionx::OpenNIImageProvider::NormalizedDepthCell::ny
float ny
Definition: OpenNIImageProvider.h:271
ImageUtil.h
TypeMapping.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28