126 const bool UseAnyDevice = (!
uri.length()) || (
uri == std::string(
"ANY_DEVICE")) ||
127 (
uri == std::string(
"Any")) || (
uri == std::string(
"any")) ||
128 (
uri == std::string(
"ANY"));
130 const bool LookForDeviceTarget = !UseAnyDevice;
132 bool DeviceTargetFound =
false;
134 openni::Array<openni::DeviceInfo> FoundDevices;
136 openni::OpenNI::enumerateDevices(&FoundDevices);
138 const int TotalDevices = FoundDevices.getSize();
140 ARMARX_INFO <<
"Information: Total openni devices found : " << TotalDevices <<
flush;
144 for (
int i = 0; i < TotalDevices; ++i)
146 const std::string CurrentURI = std::string(FoundDevices[i].getUri());
148 if (LookForDeviceTarget && (
uri == CurrentURI))
151 <<
"] Uri = " << CurrentURI <<
flush;
153 DeviceTargetFound =
true;
157 ARMARX_INFO <<
"Information: Available device OpenNI device[" << i
158 <<
"] Uri = " << CurrentURI <<
flush;
168 ARMARX_INFO <<
"Information: Video Dimension : (" << Width <<
"," << Height <<
")"
173 if (LookForDeviceTarget)
175 if (DeviceTargetFound)
184 ARMARX_ERROR <<
"Error: Data structures created succesffully"
214 if (
StartDevice(openni::ANY_DEVICE, Width, Height, Fps))
256 "Opening cameras failed!");
370 ARMARX_ERROR <<
"Error: Cannot open device (" << pDeviceURI <<
") => "
371 << openni::OpenNI::getExtendedError() <<
flush;
378 ARMARX_ERROR <<
"Error: Device (" << pDeviceURI <<
") [ has not depth sensor ]"
386 ARMARX_ERROR <<
"Error: Device (" << pDeviceURI <<
") [ has not color sensor ]"
396 ARMARX_ERROR <<
"Error: Cannot create Depth stream on Device (" << pDeviceURI <<
") => "
397 << openni::OpenNI::getExtendedError() <<
flush;
404 ARMARX_ERROR <<
"Error: Cannot create Depth stream on Device (" << pDeviceURI <<
") => "
405 << openni::OpenNI::getExtendedError() <<
flush;
412 ARMARX_INFO <<
"Information: Depth Stream Default Video Dimension : ("
413 << CurrentDepthStreamMode.getResolutionX() <<
","
414 << CurrentDepthStreamMode.getResolutionY() <<
")" <<
flush;
416 ARMARX_INFO <<
"Information: Depth Stream Default Frame Rate : "
417 << CurrentDepthStreamMode.getFps() <<
flush;
419 ARMARX_INFO <<
"Information: Depth Stream Target Video Dimension : (" << Width <<
","
420 << Height <<
")" <<
flush;
422 ARMARX_INFO <<
"Information: Depth Stream Target Frame Rate : " << Fps <<
flush;
424 CurrentDepthStreamMode.setResolution(Width, Height);
426 CurrentDepthStreamMode.setFps(Fps);
430 ARMARX_ERROR <<
"Error: Cannot set Depth stream settings (" << Width <<
"," << Height
431 <<
"," << Fps <<
") Device (" << pDeviceURI <<
") => "
432 << openni::OpenNI::getExtendedError() <<
flush;
441 ARMARX_ERROR <<
"Error: Cannot start Depth stream on Device (" << pDeviceURI <<
") => "
442 << openni::OpenNI::getExtendedError() <<
flush;
449 ARMARX_INFO <<
"Information: Depth Stream Active Video Dimension : ("
450 << CurrentDepthStreamMode.getResolutionX() <<
","
451 << CurrentDepthStreamMode.getResolutionY() <<
")" <<
flush;
453 ARMARX_INFO <<
"Information: Depth Stream Active Frame Rate : "
454 << CurrentDepthStreamMode.getFps() <<
flush;
458 ARMARX_ERROR <<
"Error: Cannot create Depth stream on Device (" << pDeviceURI <<
") => "
459 << openni::OpenNI::getExtendedError() <<
flush;
468 ARMARX_ERROR <<
"Error: Cannot create Color stream on Device (" << pDeviceURI <<
") => "
469 << openni::OpenNI::getExtendedError() <<
flush;
476 ARMARX_ERROR <<
"Error: Cannot create Color stream on Device (" << pDeviceURI <<
") => "
477 << openni::OpenNI::getExtendedError() <<
flush;
484 ARMARX_INFO <<
"Information: Color Stream Default Video Dimension : ("
485 << CurrentColorStreamMode.getResolutionX() <<
","
486 << CurrentColorStreamMode.getResolutionY() <<
")" <<
flush;
488 ARMARX_INFO <<
"Information: Color Stream Default Frame Rate : "
489 << CurrentColorStreamMode.getFps() <<
flush;
491 ARMARX_INFO <<
"Information: Color Stream Target Video Dimension : (" << Width <<
","
492 << Height <<
")" <<
flush;
494 ARMARX_INFO <<
"Information: Color Stream Target Frame Rate : " << Fps <<
flush;
496 CurrentColorStreamMode.setResolution(Width, Height);
498 CurrentColorStreamMode.setFps(Fps);
503 ARMARX_ERROR <<
"Error: Cannot set Color stream settings (" << Width <<
"," << Height
504 <<
"," << Fps <<
") Device (" << pDeviceURI <<
") => "
505 << openni::OpenNI::getExtendedError() <<
flush;
514 ARMARX_ERROR <<
"Error: Cannot start Color stream on Device (" << pDeviceURI <<
") => "
515 << openni::OpenNI::getExtendedError() <<
flush;
522 ARMARX_INFO <<
"Information: Color Stream Active Video Dimension : ("
523 << CurrentColorStreamMode.getResolutionX() <<
","
524 << CurrentColorStreamMode.getResolutionY() <<
")" <<
flush;
526 ARMARX_INFO <<
"Information: Color Stream Active Frame Rate : "
527 << CurrentColorStreamMode.getFps() <<
flush;
531 ARMARX_ERROR <<
"Error: Cannot create Color stream on Device (" << pDeviceURI <<
") => "
532 << openni::OpenNI::getExtendedError() <<
flush;
539 if (
deviceOpenNI.setDepthColorSyncEnabled(
true) != openni::STATUS_OK)
541 ARMARX_WARNING <<
"Warning: Cannot synchronize Depth and Color on Device ("
542 << pDeviceURI <<
") => " << openni::OpenNI::getExtendedError() <<
flush;
546 openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR))
548 if (
deviceOpenNI.setImageRegistrationMode(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR) !=
551 ARMARX_WARNING <<
"Warning: Device supports depth-to-color registration but could "
553 << pDeviceURI <<
") =>" << openni::OpenNI::getExtendedError()
684 bool HasBeenCaptured[2] = {
false,
false};
686 while (!(HasBeenCaptured[0] && HasBeenCaptured[1]))
688 int StreamIndex = -1;
690 bool CaptureSuccesfull =
false;
692 for (
int i = 0; i < 3; ++i)
694 if (openni::OpenNI::waitForAnyStream(ppStreams, 2, &StreamIndex, 5000) ==
698 CaptureSuccesfull =
true;
705 << openni::OpenNI::getExtendedError() <<
flush;
709 if (!CaptureSuccesfull)
714 if (!(StreamIndex >= 0) && (StreamIndex <= 1))
719 if (ppStreams[StreamIndex]->readFrame(&
frameOpenNI) != openni::STATUS_OK)
748 HasBeenCaptured[StreamIndex] =
true;
788 const visionx::ColoredPoint3D*
const pEndColoredPoint3D =
791 uint16_t* pDepthPixel = (uint16_t*)(
frameOpenNI.getData());
793 while (pColoredPoint3D < pEndColoredPoint3D)
795 pColoredPoint3D->point.z =
float(*pDepthPixel++);
797 if (pColoredPoint3D->point.z)
799 pColoredPoint3D->point.x = pNormalizedDepthCell->
nx * pColoredPoint3D->point.z;
801 pColoredPoint3D->point.y = pNormalizedDepthCell->
ny * pColoredPoint3D->point.z;
805 pColoredPoint3D->point.x = 0.0f;
807 pColoredPoint3D->point.y = 0.0f;
812 ++pNormalizedDepthCell;