Kinect 开发:取得红外图像

 

    int I_IrThreshold=12;
     IplImage* Img_Ir16U=cvCreateImage(cvSize(640,480),IPL_DEPTH_16U,1);
 IplImage* Img_IrTurn=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
 IplImage* Img_IrBgr=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
 IplImage* Img_IrTmp=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
 xn::IRMetaData MD_Ir;
 // context  
    xn::Context MyContext; 
    MyContext.Init();
 // creategenerator   
 xn::IRGenerator G_Ir;
    G_Ir.Create(MyContext);
  //map mode   
    XnMapOutputMode MyMapMode; 
    MyMapMode.nXRes = 640;  
    MyMapMode.nYRes = 480; 
    MyMapMode.nFPS = 30; 
    G_Ir.SetMapOutputMode( MyMapMode );
 MyContext.StartGeneratingAll();  
 
    MyContext.WaitNoneUpdateAll(); 
 int flag=0;
 cvNamedWindow("Img_IrTurn",1);
 cvCreateTrackbar( "Thresh", "Img_IrTurn", &I_IrThreshold, 100, 0 );
 while( !MyContext.WaitNoneUpdateAll( ) ) 
    {  
        //get meta data 
  G_Ir.GetMetaData(MD_Ir);
 
        //OpenCV output  
  memcpy(Img_Ir16U->imageData,MD_Ir.Data(),640*480*2);
  cvConvertScale(Img_Ir16U,Img_IrTurn,255/255.,0);
  //模糊操作
  
  if(flag>2){cvCopyImage(Img_IrTurn,Img_IrBgr);flag=-1;}
  if(flag>=0)flag++;
  cvShowImage("1",Img_IrTurn);
  cvAbsDiff(Img_IrTurn,Img_IrBgr,Img_IrTurn);
  //ir二值化
  cvThreshold(Img_IrTurn,Img_IrTurn,I_IrThreshold,255,CV_THRESH_BINARY);
  cvShowImage("Img_IrTurn",Img_IrTurn);
  cvWaitKey(10);
 }
 cvDestroyAllWindows();  
    MyContext.StopGeneratingAll();
    MyContext.Shutdown();

posted on 2012-12-04 17:37  tokutoku  阅读(1358)  评论(0编辑  收藏  举报

导航