minor refactoring CvCapture_OpenNI
authorMaria Dimashova <no@email>
Thu, 15 Mar 2012 15:55:07 +0000 (15:55 +0000)
committerMaria Dimashova <no@email>
Thu, 15 Mar 2012 15:55:07 +0000 (15:55 +0000)
doc/user_guide/ug_highgui.rst
modules/highgui/src/cap_openni.cpp
samples/cpp/openni_capture.cpp

index 7afcaa9..fcc61b1 100644 (file)
@@ -4,8 +4,8 @@ HighGUI
 
 .. highlight:: cpp
 
-Using depth sensors
-===================
+Using Kinect and other OpenNI compatible depth sensors
+======================================================
 
 Depth sensors compatible with OpenNI (Kinect, XtionPRO, ...) are supported through ``VideoCapture`` class. Depth map, RGB image and some other formats of output can be retrieved by using familiar interface of ``VideoCapture``.
 
@@ -92,10 +92,10 @@ Since two types of sensor's data generators are supported (image generator and d
 
 * CV_CAP_OPENNI_DEPTH_GENERATOR -- A flag for access to the depth generator properties. This flag value is assumed by default if neither of the two possible values of the property is not set.
 
-Some depth sensors (for example XtionPRO) do not have image generator. In order to check it you can get ``CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT`` property. If returned value greater than zero sensor has image generator.
+Some depth sensors (for example XtionPRO) do not have image generator. In order to check it you can get ``CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT`` property.
 ::
 
-    bool isImageGeneratorPresent = capture.get( CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT ) > 0;
+    bool isImageGeneratorPresent = capture.get( CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT ) != 0; // or == 1
 
 
 Flags specifing the needed generator type must be used in combination with particular generator property. The following properties of cameras available through OpenNI interfaces are supported:
index 276f672..03856b4 100644 (file)
@@ -395,39 +395,40 @@ double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx )
 {
     CV_Assert( depthGenerator.IsValid() );
 
-    double res = 0;
+    double propValue = 0;
+
     switch( propIdx )
     {
     case CV_CAP_PROP_FRAME_WIDTH :
-        res = depthOutputMode.nXRes;
+        propValue = depthOutputMode.nXRes;
         break;
     case CV_CAP_PROP_FRAME_HEIGHT :
-        res = depthOutputMode.nYRes;
+        propValue = depthOutputMode.nYRes;
         break;
     case CV_CAP_PROP_FPS :
-        res = depthOutputMode.nFPS;
+        propValue = depthOutputMode.nFPS;
         break;
     case CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH :
-        res = depthGenerator.GetDeviceMaxDepth();
+        propValue = depthGenerator.GetDeviceMaxDepth();
         break;
     case CV_CAP_PROP_OPENNI_BASELINE :
-        res = baseline;
+        propValue = baseline;
         break;
     case CV_CAP_PROP_OPENNI_FOCAL_LENGTH :
-        res = (double)depthFocalLength_VGA;
+        propValue = (double)depthFocalLength_VGA;
         break;
     case CV_CAP_PROP_OPENNI_REGISTRATION :
-        res = depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ? 1.0 : 0.0;
+        propValue = depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ? 1.0 : 0.0;
     default :
         CV_Error( CV_StsBadArg, "Depth generator does not support such parameter for getting.\n");
     }
 
-    return res;
+    return propValue;
 }
 
 bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue )
 {
-    bool res = false;
+    bool isSet = false;
 
     CV_Assert( depthGenerator.IsValid() );
 
@@ -437,7 +438,8 @@ bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue
             {
                 if( propValue != 0.0 ) // "on"
                 {
-                    // if no Image Generator is present i.e. ASUS XtionPro the imageGenerator cannot be used
+                    // if there isn't image generator (i.e. ASUS XtionPro doesn't have it)
+                    // then the property isn't avaliable
                     if( m_isImageGeneratorPresent )
                     {
                         CV_Assert( imageGenerator.IsValid() );
@@ -449,16 +451,14 @@ bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue
                                 if( status != XN_STATUS_OK )
                                     std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
                                 else
-                                    res = true;
+                                    isSet = true;
                             }
                             else
                                 std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl;
                         }
                         else
-                            res = true;
+                            isSet = true;
                     }
-                    else
-                            res = false;
                 }
                 else // "off"
                 {
@@ -466,7 +466,7 @@ bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue
                     if( status != XN_STATUS_OK )
                         std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
                     else
-                        res = true;
+                        isSet = true;
                 }
             }
             break;
@@ -474,46 +474,45 @@ bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue
             CV_Error( CV_StsBadArg, "Unsupported depth generator property.\n");
     }
 
-    return res;
+    return isSet;
 }
 
 double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx )
 {
-    double res = 0;
+    double propValue = 0;
+    if( !m_isImageGeneratorPresent )
+           return propValue;
 
-    if (propIdx == CV_CAP_PROP_IMAGE_GENERATOR_PRESENT)
-        res = m_isImageGeneratorPresent ? 1 : -1;
+    if( propIdx == CV_CAP_PROP_IMAGE_GENERATOR_PRESENT )
+        propValue = m_isImageGeneratorPresent ? 1. : 0.;
     else
-    {
-        if (!m_isImageGeneratorPresent)
-            return res;
-
+    {       
         CV_Assert( imageGenerator.IsValid() );
 
         switch( propIdx )
         {
         case CV_CAP_PROP_FRAME_WIDTH :
-            res = imageOutputMode.nXRes;
+            propValue = imageOutputMode.nXRes;
             break;
         case CV_CAP_PROP_FRAME_HEIGHT :
-            res = imageOutputMode.nYRes;
+            propValue = imageOutputMode.nYRes;
             break;
         case CV_CAP_PROP_FPS :
-            res = imageOutputMode.nFPS;
+            propValue = imageOutputMode.nFPS;
             break;
         default :
             CV_Error( CV_StsBadArg, "Image generator does not support such parameter for getting.\n");
         }
     }
-    return res;
+    return propValue;
 }
 
 bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue )
 {
-    bool res = false;
-    if(!m_isImageGeneratorPresent)
-        return res;
-
+       bool isSet = false;
+    if( !m_isImageGeneratorPresent )
+        return isSet;   
+    
     CV_Assert( imageGenerator.IsValid() );
 
     switch( propIdx )
@@ -549,7 +548,7 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue
         else
         {
             imageOutputMode = newImageOutputMode;
-            res = true;
+            isSet = true;
         }
         break;
     }
@@ -557,7 +556,7 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue
         CV_Error( CV_StsBadArg, "Unsupported image generator property.\n");
     }
 
-    return res;
+    return isSet;
 }
 
 bool CvCapture_OpenNI::grabFrame()
@@ -570,8 +569,9 @@ bool CvCapture_OpenNI::grabFrame()
         return false;
 
     depthGenerator.GetMetaData( depthMetaData );
-    if(m_isImageGeneratorPresent)
+    if( m_isImageGeneratorPresent )
         imageGenerator.GetMetaData( imageMetaData );
+
     return true;
 }
 
index 9014fa7..3836c16 100644 (file)
@@ -208,12 +208,14 @@ int main( int argc, char* argv[] )
             "FRAME_HEIGHT   " << capture.get( CV_CAP_PROP_FRAME_HEIGHT ) << endl <<
             "FRAME_MAX_DEPTH    " << capture.get( CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH ) << " mm" << endl <<
             "FPS    " << capture.get( CV_CAP_PROP_FPS ) << endl;
-    bool isImageGeneratorPresent = capture.get( CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT ) > 0;
-    if (isImageGeneratorPresent)
-    cout << "\nImage generator output mode:" << endl <<
+    if( capture.get( CV_CAP_OPENNI_PROP_IMAGE_GENERATOR_PRESENT ) )
+    {
+        cout <<
+            "\nImage generator output mode:" << endl <<
             "FRAME_WIDTH    " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_WIDTH ) << endl <<
             "FRAME_HEIGHT   " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_HEIGHT ) << endl <<
             "FPS    " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FPS ) << endl;
+    }
     else
     {
         cout << "\nDevice doesn't contain image generator" << endl;