cap_openni.cpp.patch

Patch to add support for ASUS XtionPRO and other depth only devices. - Gustav Karlsson, 2011-08-15 11:20 pm

Download (5.2 kB)

 
cap_openni.cpp (working copy)
67 67
                "</Dumps>"
68 68
        "</Log>"
69 69
        "<ProductionNodes>"
70
                "<Node type=\"Image\" name=\"Image1\">"
70
                "<Node type=\"Image\" name=\"Image1\" stopOnError=\"false\">"
71 71
                        "<Configuration>"
72 72
                                "<MapOutputMode xRes=\"640\" yRes=\"480\" FPS=\"30\"/>"
73 73
                                "<Mirror on=\"false\"/>"
......
134 134
    xn::DepthMetaData  depthMetaData;
135 135
    XnMapOutputMode depthOutputMode;
136 136

  
137
    bool m_isImageGeneratorPresent;
137 138
    xn::ImageGenerator imageGenerator;
138 139
    xn::ImageMetaData  imageMetaData;
139 140
    XnMapOutputMode imageOutputMode;
......
241 242
            return;
242 243
        }
243 244

  
244
        imageGenerator.Create( context );
245
        // enumerate the nodes to find if image generator is present
246
        xn::NodeInfoList Imagelist;
247
        status = context.EnumerateExistingNodes( Imagelist, XN_NODE_TYPE_IMAGE );
245 248
        if( status != XN_STATUS_OK )
246 249
        {
247
            std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create image generator: "
248
                      <<  std::string(xnGetStatusString(status)) << std::endl;
250
            std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate Image Generators: "
251
                      << std::string(xnGetStatusString(status)) << std::endl;
249 252
            return;
250 253
        }
254
        if(Imagelist.IsEmpty())
255
        {
256
            m_isImageGeneratorPresent = FALSE;
257
        }
258
        else
259
        {
260
            m_isImageGeneratorPresent = TRUE;
261
            imageGenerator.Create( context);
262
            if( status != XN_STATUS_OK )
263
            {
264
                std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create image generator: "
265
                          <<  std::string(xnGetStatusString(status)) << std::endl;
266
                return;
267
            }
268
        }
251 269

  
252 270
        // Set map output mode.
253 271
        CV_Assert( depthGenerator.SetMapOutputMode( depthOutputMode ) == XN_STATUS_OK ); // xn::DepthGenerator supports VGA only! (Jan 2011)
254
        CV_Assert( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK );
272
        CV_Assert( m_isImageGeneratorPresent ? ( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK ) : TRUE);
255 273

  
256 274
        //  Start generating data.
257 275
        status = context.StartGeneratingAll();
......
424 442
            {
425 443
                if( propValue != 0.0 ) // "on"
426 444
                {
427
                    CV_Assert( imageGenerator.IsValid() );
428
                    if( !depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) )
445
                    // if no Image Generator is present i.e. ASUS XtionPro the imageGenerator cannot be used
446
                    if( m_isImageGeneratorPresent )
429 447
                    {
430
                        if( depthGenerator.GetAlternativeViewPointCap().IsViewPointSupported(imageGenerator) )
448
                        CV_Assert( imageGenerator.IsValid() );
449
                        if( !depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) )
431 450
                        {
432
                            XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);
433
                            if( status != XN_STATUS_OK )
434
                                std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
451
                            if( depthGenerator.GetAlternativeViewPointCap().IsViewPointSupported(imageGenerator) )
452
                            {
453
                                XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);
454
                                if( status != XN_STATUS_OK )
455
                                    std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
456
                                else
457
                                    res = true;
458
                            }
435 459
                            else
436
                                res = true;
460
                                std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl;
437 461
                        }
438 462
                        else
439
                           std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl;
463
                            res = true;
440 464
                    }
441 465
                    else
442
                        res = true;
466
                            res = false;
443 467
                }
444 468
                else // "off"
445 469
                {
......
484 508
bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue )
485 509
{
486 510
    bool res = false;
511
    if(!m_isImageGeneratorPresent)
512
        return res;
487 513

  
488 514
    CV_Assert( imageGenerator.IsValid() );
489 515

  
......
536 562
        return false;
537 563

  
538 564
    depthGenerator.GetMetaData( depthMetaData );
539
    imageGenerator.GetMetaData( imageMetaData );
565
    if(m_isImageGeneratorPresent)
566
        imageGenerator.GetMetaData( imageMetaData );
540 567
    return true;
541 568
}
542 569