示例#1
0
void initialize()
{
	std::cout << endl << "Initializing Kinect... " << endl << endl;

	g_RetVal = g_Context.Init();

	g_RetVal = g_DepthGenerator.Create(g_Context);
	if (g_RetVal != XN_STATUS_OK)
		printf("Failed creating DEPTH generator %s\n", xnGetStatusString(g_RetVal));

	XnMapOutputMode outputMode;
	outputMode.nXRes = g_im_w;
	outputMode.nYRes = g_im_h;
	outputMode.nFPS = g_fps;
	g_RetVal = g_DepthGenerator.SetMapOutputMode(outputMode);
	if (g_RetVal != XN_STATUS_OK)
		printf("Failed setting the DEPTH output mode %s\n", xnGetStatusString(g_RetVal));

	g_RetVal = g_Context.StartGeneratingAll();
	if (g_RetVal != XN_STATUS_OK)
		printf("Failed starting generating all %s\n", xnGetStatusString(g_RetVal));

	g_DepthGenerator.GetIntProperty ("ZPD", g_focal_length);
	g_DepthGenerator.GetRealProperty ("ZPPS", g_pixel_size);
	g_pixel_size *= 2.f;

	g_im3D.create(g_im_h,g_im_w,CV_32FC3);
}
示例#2
0
XnStatus XnFileDevice::UpdateRWData(const xn::DepthGenerator& depth)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XnUInt64 nZPD;
    nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, nZPD);
    XN_IS_STATUS_OK(nRetVal);

    XnDouble fZPPS;
    nRetVal = depth.GetRealProperty(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, fZPPS);
    XN_IS_STATUS_OK(nRetVal);

    XnFieldOfView FOV;
    FOV.fHFOV = 2*atan(fZPPS*XN_SXGA_X_RES/2/nZPD);
    FOV.fVFOV = 2*atan(fZPPS*XN_VGA_Y_RES*2/2/nZPD);

    // notify
    nRetVal = m_pNotifications->OnNodeGeneralPropChanged(m_pNotificationsCookie,
              depth.GetName(),
              XN_PROP_FIELD_OF_VIEW,
              sizeof(FOV),
              &FOV);
    XN_IS_STATUS_OK(nRetVal);

    return (XN_STATUS_OK);
}
示例#3
0
bool CvCapture_OpenNI::readCamerasParams()
{
    XnDouble pixelSize = 0;
    if( depthGenerator.GetRealProperty( "ZPPS", pixelSize ) != XN_STATUS_OK )
    {
        std::cerr << "CvCapture_OpenNI::readCamerasParams : Could not read pixel size!" << std::endl;
        return false;
    }

    // pixel size @ VGA = pixel size @ SXGA x 2
    pixelSize *= 2.0; // in mm

    // focal length of IR camera in pixels for VGA resolution
    XnUInt64 zeroPlanDistance; // in mm
    if( depthGenerator.GetIntProperty( "ZPD", zeroPlanDistance ) != XN_STATUS_OK )
    {
        std::cerr << "CvCapture_OpenNI::readCamerasParams : Could not read virtual plane distance!" << std::endl;
        return false;
    }

    if( depthGenerator.GetRealProperty( "LDDIS", baseline ) != XN_STATUS_OK )
    {
        std::cerr << "CvCapture_OpenNI::readCamerasParams : Could not read base line!" << std::endl;
        return false;
    }

    // baseline from cm -> mm
    baseline *= 10;

    // focal length from mm -> pixels (valid for 640x480)
    depthFocalLength_VGA = (XnUInt64)((double)zeroPlanDistance / (double)pixelSize);

    if( depthGenerator.GetIntProperty( "ShadowValue", shadowValue ) != XN_STATUS_OK )
    {
        std::cerr << "CvCapture_OpenNI::readCamerasParams : Could not read property \"ShadowValue\"!" << std::endl;
        return false;
    }

    if( depthGenerator.GetIntProperty("NoSampleValue", noSampleValue ) != XN_STATUS_OK )
    {
        std::cerr << "CvCapture_OpenNI::readCamerasParams : Could not read property \"NoSampleValue\"!" <<std::endl;
        return false;
    }

    return true;
}
示例#4
0
XnStatus XnFileDevice::UpdateS2DTables(const xn::DepthGenerator& depth)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XnUInt64 nTemp;
    XnDouble dTemp;

    // get config
    XnShiftToDepthConfig config;

    nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, nTemp);
    XN_IS_STATUS_OK(nRetVal);
    config.nZeroPlaneDistance = (XnDepthPixel)nTemp;

    nRetVal = depth.GetRealProperty(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, dTemp);
    XN_IS_STATUS_OK(nRetVal);
    config.fZeroPlanePixelSize = (XnFloat)dTemp;

    nRetVal = depth.GetRealProperty(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, dTemp);
    XN_IS_STATUS_OK(nRetVal);
    config.fEmitterDCmosDistance = (XnFloat)dTemp;

    nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_MAX_SHIFT, nTemp);
    XN_IS_STATUS_OK(nRetVal);
    config.nDeviceMaxShiftValue = (XnUInt32)nTemp;

    config.nDeviceMaxDepthValue = depth.GetDeviceMaxDepth();

    nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_CONST_SHIFT, nTemp);
    XN_IS_STATUS_OK(nRetVal);
    config.nConstShift = (XnUInt32)nTemp;

    nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_PIXEL_SIZE_FACTOR, nTemp);
    XN_IS_STATUS_OK(nRetVal);
    config.nPixelSizeFactor = (XnUInt32)nTemp;

    nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_PARAM_COEFF, nTemp);
    XN_IS_STATUS_OK(nRetVal);
    config.nParamCoeff = (XnUInt32)nTemp;

    nRetVal = depth.GetIntProperty(XN_STREAM_PROPERTY_SHIFT_SCALE, nTemp);
    XN_IS_STATUS_OK(nRetVal);
    config.nShiftScale = (XnUInt32)nTemp;

    config.nDepthMinCutOff = 0;
    config.nDepthMaxCutOff = (XnDepthPixel)config.nDeviceMaxDepthValue;

    if (!m_ShiftToDepth.bIsInitialized)
    {
        nRetVal = XnShiftToDepthInit(&m_ShiftToDepth, &config);
        XN_IS_STATUS_OK(nRetVal);
    }
    else
    {
        nRetVal = XnShiftToDepthUpdate(&m_ShiftToDepth, &config);
        XN_IS_STATUS_OK(nRetVal);
    }

    // notify
    nRetVal = m_pNotifications->OnNodeGeneralPropChanged(m_pNotificationsCookie, depth.GetName(), XN_STREAM_PROPERTY_S2D_TABLE, m_ShiftToDepth.nShiftsCount * sizeof(XnDepthPixel), m_ShiftToDepth.pShiftToDepthTable);
    XN_IS_STATUS_OK(nRetVal);

    nRetVal = m_pNotifications->OnNodeGeneralPropChanged(m_pNotificationsCookie, depth.GetName(), XN_STREAM_PROPERTY_D2S_TABLE, m_ShiftToDepth.nDepthsCount * sizeof(XnUInt16), m_ShiftToDepth.pDepthToShiftTable);
    XN_IS_STATUS_OK(nRetVal);

    return (XN_STATUS_OK);
}