Esempio n. 1
0
//---------------------------------------------------------------------------
void ofxKinect::grabDepthFrame(freenect_device *dev, void *depth, uint32_t timestamp) {

	ofxKinect* kinect = kinectContext.getKinect(dev);

	if(kinect->kinectDevice == dev) {
		kinect->lock();
		freenect_frame_mode curMode = freenect_get_current_depth_mode(dev);
		kinect->depthPixelsRawBack.setFromPixels((unsigned short*) depth, width, height, 1);
		kinect->bNeedsUpdate = true;
		kinect->unlock();
    }
}
		int getDepthBufferSize(){
			return freenect_get_current_depth_mode(m_dev).bytes;
		}
Esempio n. 3
0
void depth_cb(freenect_device *dev, void *depth, uint32_t timestamp)
{
	dump('d', timestamp, depth, freenect_get_current_depth_mode(dev).bytes);
}
Esempio n. 4
0
void qKinect::doStartGrabbing()
{
	assert(m_app);
	if (!m_app)
		return;

	f_ctx=0;
    f_dev=0;
	s_grabIndex=0;

	if (m_kDlg)
		delete m_kDlg;
	m_kDlg=0;

	s_max_depth_count = 0;
	if (s_depth_data)
		delete[] s_depth_data;
	s_depth_count = 0;
	s_depth_data = 0;
	s_wDepth = s_hDepth = 0;

	if (s_last_rgb_data)
		delete[] s_last_rgb_data;
	s_last_rgb_data = 0;
	s_rgb_count = 0;
	s_wRgb = s_hRgb = 0;

	if (freenect_init(&f_ctx, NULL) < 0)
	{
		m_app->dispToConsole("[qKinect] Failed to initialize kinect driver!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);
		return;
	}

	freenect_set_log_level(f_ctx, FREENECT_LOG_DEBUG);

	int nr_devices = freenect_num_devices(f_ctx);
	m_app->dispToConsole(qPrintable(QString("[qKinect] Number of devices found: %1").arg(nr_devices)));

	if (nr_devices < 1)
		return;

	if (freenect_open_device(f_ctx, &f_dev, 0) < 0)
	{
		m_app->dispToConsole("[qKinect] Failed to initialize kinect device!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);
		return;
	}

	//test: try to init high resolution mode
	//freenect_frame_mode upDepthMode = freenect_find_depth_mode(FREENECT_RESOLUTION_HIGH, FREENECT_DEPTH_11BIT);
	//int success = freenect_set_depth_mode(f_dev,upDepthMode);

	/*** Depth information ***/
	freenect_frame_mode depthMode = freenect_get_current_depth_mode(f_dev);
	if (!depthMode.depth_format == FREENECT_DEPTH_11BIT)
	{
		depthMode = freenect_find_depth_mode(depthMode.resolution, FREENECT_DEPTH_11BIT);
		if (freenect_set_depth_mode(f_dev,depthMode)<0)
		{
			m_app->dispToConsole("[qKinect] Failed to initialiaze depth mode!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);
			return;
		}
	}
	if (!getResolution(depthMode.resolution,s_wDepth,s_hDepth))
	{
		m_app->dispToConsole("[qKinect] Failed to read depth resolution!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);
		return;
	}
	m_app->dispToConsole(qPrintable(QString("[qKinect] Depth resolution: %1 x %2").arg(s_wDepth).arg(s_hDepth)));

	s_depth_data = new uint16_t[s_wDepth*s_hDepth];
	if (!s_depth_data)
	{
		m_app->dispToConsole("[qKinect] Not enough memory!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);
		return;
	}
	s_max_depth_count = 1;

	/*** RGB information ***/
	bool grabRGB = true;
	{
		freenect_frame_mode rgbMode = freenect_get_current_video_mode(f_dev);
		if (!rgbMode.video_format == FREENECT_VIDEO_RGB || depthMode.resolution != rgbMode.resolution)
		{
			rgbMode = freenect_find_video_mode(depthMode.resolution, FREENECT_VIDEO_RGB);
			if (freenect_set_video_mode(f_dev,rgbMode)<0)
			{
				m_app->dispToConsole("[qKinect] Can't find a video mode compatible with current depth mode?!");
				grabRGB = false;
			}
		}

		//still want to/can grab RGB info?
		if (grabRGB)
		{
			getResolution(rgbMode.resolution,s_wRgb,s_hRgb);

			s_last_rgb_data = new uint8_t[s_wRgb*s_hRgb*3];
			if (!s_last_rgb_data) //not enough memory for RGB
			{
				m_app->dispToConsole("[qKinect] Not enough memory to grab RGB info!");
				grabRGB = false;
			}
			else
			{
				m_app->dispToConsole(qPrintable(QString("[qKinect] RGB resolution: %1 x %2").arg(s_wRgb).arg(s_hRgb)));
			}
		}
	}

    int freenect_angle = 0;
	freenect_set_tilt_degs(f_dev,freenect_angle);
	freenect_set_led(f_dev,LED_RED);
	freenect_set_depth_callback(f_dev, depth_cb);
	freenect_set_video_callback(f_dev, rgb_cb);
	if (grabRGB)
		freenect_set_video_buffer(f_dev, s_last_rgb_data);

	freenect_start_depth(f_dev);
	if (s_last_rgb_data)
		freenect_start_video(f_dev);

	m_kDlg = new ccKinectDlg(m_app->getMainWindow());
	if (grabRGB)
		m_kDlg->addMode(QString("%1 x %2").arg(s_wDepth).arg(s_hDepth));
	else
		m_kDlg->grabRGBCheckBox->setChecked(false);
	m_kDlg->grabRGBCheckBox->setEnabled(grabRGB);
	m_kDlg->grabPushButton->setEnabled(true);

	connect(m_kDlg->grabPushButton, SIGNAL(clicked()), this, SLOT(grabCloud()));
	connect(m_kDlg, SIGNAL(finished(int)), this, SLOT(dialogClosed(int)));

	//m_kDlg->setModal(false);
	//m_kDlg->setWindowModality(Qt::NonModal);
	m_kDlg->show();

	if (!m_timer)
	{
		m_timer = new QTimer(this);
		connect(m_timer, SIGNAL(timeout()), this, SLOT(updateRTView()));
	}
	m_timer->start(0);
}
Esempio n. 5
0
/*
 * Get the depth resolution of a device.
 */
uint32_t get_freenect_depth_resolution(freenect_device* dev){
  freenect_frame_mode mode = freenect_get_current_depth_mode(dev);
  return mode.resolution;
}