const std::vector<AstraVideoMode> astra_convert(const openni::Array<openni::VideoMode>& input)
{
  std::vector<AstraVideoMode> output;

  int size = input.getSize();

  output.reserve(size);

  for (int i=0; i<size; ++i)
    output.push_back(astra_convert(input[i]));

  return output;
}
Beispiel #2
0
DepthVideoIn::DepthVideoIn(int device_number) {
	openni::Status rc;

	num_frames=-1;
	m_device=NULL;
	m_depth=NULL;
	m_depthFrame=NULL;
    last_requested_n=-1;
	last_requested_output=NULL;

	if (!initialized) {
		rc=openni::OpenNI::initialize();
		if (rc!=openni::STATUS_OK) {
			printf("OpenNI-> init error:\n%s\n", openni::OpenNI::getExtendedError());
			return;
		} 
		initialized=true;
	}


	// Enumerate devices
	if (deviceInfoList.getSize()==0) openni::OpenNI::enumerateDevices(&deviceInfoList);
	if (device_number>=deviceInfoList.getSize()) return;
	


	m_device                    = new openni::Device;
	m_depth                     = new openni::VideoStream;
	m_depthFrame                = new openni::VideoFrameRef;
	openni::Device      *device = static_cast<openni::Device*>(m_device);
	openni::VideoStream *depth  = static_cast<openni::VideoStream*>(m_depth);

	const char *deviceURI=deviceInfoList[device_number].getUri();
	rc=device->open(deviceURI);
	if (rc!=openni::STATUS_OK) {
		printf("OpenNI-> Device open failed:\n%s\n", openni::OpenNI::getExtendedError());
		return;
	}


	rc=depth->create(*device,openni::SENSOR_DEPTH);
	if (rc==openni::STATUS_OK) {
		rc=depth->start();
		if (rc!=openni::STATUS_OK) {
			printf("OpenNI-> Couldn't start depth stream:\n%s\n", openni::OpenNI::getExtendedError());
		}
	} else {
		printf("OpenNI-> Couldn't find depth stream:\n%s\n", openni::OpenNI::getExtendedError());
	}


	/*rc=color.create(device, openni::SENSOR_COLOR);
	if (rc==openni::STATUS_OK) {
		rc=color.start();
		if (rc!=openni::STATUS_OK) {
			printf("SimpleViewer: Couldn't start color stream:\n%s\n", openni::OpenNI::getExtendedError());
			color.destroy();
		}
	} else {
		printf("SimpleViewer: Couldn't find color stream:\n%s\n", openni::OpenNI::getExtendedError());
	}*/

	if (!depth->isValid()) {
		printf("OpenNI-> No valid streams.\n");
		return;
	}

	openni::VideoMode depthVideoMode = depth->getVideoMode();
	width  = depthVideoMode.getResolutionX();
	height = depthVideoMode.getResolutionY();
	bpp    = 32;
	fps    = 30.0; // TODO***

	num_frames=0;
}