示例#1
0
IplImage* knt_get_image_IR_color(kinect_t *k){
    XnStatus nRetVal = XN_STATUS_OK;
  //Creamos una imagen de profundidad de 8 bits y 3 canales
    IplImage* imgk = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 3);
    
    XnIRPixel* pIRMapColor;
    int i = 0, j = 0;
    
    //Esperamos a que nos devuelva los datos
    nRetVal = xnWaitOneUpdateAll(k->pContext, k->Node_Image);
    
    if(nRetVal != XN_STATUS_OK){
      printf("Error actualizando información: %s\n", xnGetStatusString(nRetVal));
    }
    
    //Obtenemos la información
     pIRMapColor = xnGetIRMap(k->Node_Image); 
      
     for( i = 0; i < 480; i++) 
       for( j = 0; j < 640; j++){
	 *pIRMapColor=(*pIRMapColor>>4);
	 ((uchar *)(imgk->imageData + i*imgk->widthStep))[j*imgk->nChannels+0] = (((*pIRMapColor>>6)&0x02)<<6)|0x2D;
	 ((uchar *)(imgk->imageData + i*imgk->widthStep))[j*imgk->nChannels+1] = (((*pIRMapColor>>3)&0x03)<<5)|0x1D; 
	 ((uchar *)(imgk->imageData + i*imgk->widthStep))[j*imgk->nChannels+2] = (((*pIRMapColor)&0x03)<<5)|0x1D;
	 ++pIRMapColor;
       }
     
     return imgk;
}
示例#2
0
IplImage* knt_get_image_RGB(kinect_t *k){
    XnStatus nRetVal = XN_STATUS_OK;
  //Creamos una imagen de profundidad de 8 bits y 3 canales
    IplImage* imgk = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 3);
    
    XnRGB24Pixel* pImghMap;
    int i = 0, j = 0;
    
    //Esperamos a que nos devuelva los datos
    nRetVal = xnWaitOneUpdateAll(k->pContext, k->Node_Image);
    
    if(nRetVal != XN_STATUS_OK){
      printf("Error actualizando información: %s\n", xnGetStatusString(nRetVal));
    }
    
    //Obtenemos la información
     pImghMap = xnGetRGB24ImageMap(k->Node_Image); 
      
     for( i = 0; i < 480; i++) 
       for( j = 0; j < 640; j++){
	 ((uchar *)(imgk->imageData + i*imgk->widthStep))[j*imgk->nChannels+0] = pImghMap->nBlue;
	 ((uchar *)(imgk->imageData + i*imgk->widthStep))[j*imgk->nChannels+1] = pImghMap->nGreen;
	 ((uchar *)(imgk->imageData + i*imgk->widthStep))[j*imgk->nChannels+2] = pImghMap->nRed;
	 ++pImghMap;
       }
     
     return imgk;
}
示例#3
0
IplImage* knt_get_image_IR(kinect_t *k){
   XnStatus nRetVal = XN_STATUS_OK;
  //Creamos una imagen de profundidad de 8 bits y un canal
   IplImage* imgk = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
    
    XnIRPixel* pIRMap;
    int i = 0, j = 0;
    
    //Esperamos a que nos devuelva los datos
    nRetVal = xnWaitOneUpdateAll(k->pContext, k->Node_Image);
    
    if(nRetVal != XN_STATUS_OK){
      printf("Error actualizando información de IR: %s\n", xnGetStatusString(nRetVal));
    }
    
    //Obtenemos la información
    pIRMap = xnGetIRMap( k->Node_Image); 
      
     for( i = 0; i < 480; i++) 
       for( j = 0; j < 640; j++){
	 ((uchar *)(imgk->imageData + i*imgk->widthStep))[j] = (*pIRMap)>>4;
	 ++pIRMap;
       }
       
     cvNormalize(imgk, imgk, 255, 0, CV_MINMAX);
     
     return imgk;
}
示例#4
0
int main()
{
	XnStatus nRetVal = XN_STATUS_OK;
	XnContext* pContext;
	XnEnumerationErrors* pErrors;
	XnNodeHandle hDepth;
	XnDepthMetaData* pDepthMD;
	const XnDepthPixel* pDepthMap;
	XnDepthPixel middlePoint;

	nRetVal = xnEnumerationErrorsAllocate(&pErrors);
	CHECK_RC(nRetVal, "Allocate errors object");

	nRetVal = xnInitFromXmlFile(SAMPLE_XML_PATH, &pContext, pErrors);
	CHECK_RC(nRetVal, "Init context");

	if (nRetVal == XN_STATUS_NO_NODE_PRESENT)
	{
		XnChar strError[1024];
		xnEnumerationErrorsToString(pErrors, strError, 1024);
		printf("%s\n", strError);
		return (nRetVal);
	}
	else if (nRetVal != XN_STATUS_OK)
	{
		printf("Open failed: %s\n", xnGetStatusString(nRetVal));
		return (nRetVal);
	}

	nRetVal = xnFindExistingNodeByType(pContext, XN_NODE_TYPE_DEPTH, &hDepth);
	CHECK_RC(nRetVal, "Find depth generator");

	pDepthMD = xnAllocateDepthMetaData();
	
	while (!xnOSWasKeyboardHit())
	{
		nRetVal = xnWaitOneUpdateAll(pContext, hDepth);
		if (nRetVal != XN_STATUS_OK)
		{
			printf("UpdateData failed: %s\n", xnGetStatusString(nRetVal));
			continue;
		}

		xnGetDepthMetaData(hDepth, pDepthMD);
		pDepthMap = pDepthMD->pData;
		middlePoint = pDepthMap[pDepthMD->pMap->Res.X * pDepthMD->pMap->Res.Y/2 + pDepthMD->pMap->Res.X/2];

		printf("Frame %d Middle point is: %u\n", pDepthMD->pMap->pOutput->nFrameID, middlePoint);
	}

	xnShutdown(pContext);

	return 0;
}
int main()
{
	XnStatus nRetVal = XN_STATUS_OK;
	XnContext* pContext;
	XnNodeHandle hScriptNode;
	XnEnumerationErrors* pErrors;
	XnNodeHandle hDepth;
	XnDepthMetaData* pDepthMD;
	const XnDepthPixel* pDepthMap;
	XnDepthPixel middlePoint;
	const char *fn = NULL;

	nRetVal = xnEnumerationErrorsAllocate(&pErrors);
	CHECK_RC(nRetVal, "Allocate errors object");


	if	(fileExists(SAMPLE_XML_PATH)) fn = SAMPLE_XML_PATH;
	else if (fileExists(SAMPLE_XML_PATH_LOCAL)) fn = SAMPLE_XML_PATH_LOCAL;
	else {
		printf("Could not find '%s' nor '%s'. Aborting.\n" , SAMPLE_XML_PATH, SAMPLE_XML_PATH_LOCAL);
		return XN_STATUS_ERROR;
	}
	printf("Reading config from: '%s'\n", fn);
	nRetVal = xnInitFromXmlFileEx(fn, &pContext, pErrors, &hScriptNode);
	if (nRetVal == XN_STATUS_NO_NODE_PRESENT)
	{
		XnChar strError[1024];
		xnEnumerationErrorsToString(pErrors, strError, 1024);
		printf("%s\n", strError);
		xnEnumerationErrorsFree(pErrors);
		return (nRetVal);
	}
	else if (nRetVal != XN_STATUS_OK)
	{
		printf("Open failed: %s\n", xnGetStatusString(nRetVal));
		xnEnumerationErrorsFree(pErrors);
		return (nRetVal);
	}

	xnEnumerationErrorsFree(pErrors);

	nRetVal = xnFindExistingRefNodeByType(pContext, XN_NODE_TYPE_DEPTH, &hDepth);
	CHECK_RC(nRetVal, "Find depth generator");

	pDepthMD = xnAllocateDepthMetaData();
	
	while (!xnOSWasKeyboardHit())
	{
		nRetVal = xnWaitOneUpdateAll(pContext, hDepth);
		if (nRetVal != XN_STATUS_OK)
		{
			printf("UpdateData failed: %s\n", xnGetStatusString(nRetVal));
			continue;
		}

		xnGetDepthMetaData(hDepth, pDepthMD);
		pDepthMap = pDepthMD->pData;
		middlePoint = pDepthMap[pDepthMD->pMap->Res.X * pDepthMD->pMap->Res.Y/2 + pDepthMD->pMap->Res.X/2];

		printf("Frame %d Middle point is: %u\n", pDepthMD->pMap->pOutput->nFrameID, middlePoint);
	}

	xnFreeDepthMetaData(pDepthMD);

	xnProductionNodeRelease(hDepth);
	xnProductionNodeRelease(hScriptNode);
	xnContextRelease(pContext);

	return 0;
}