added ability to reset view point of depth generator to normal one (#1195)
authorMaria Dimashova <no@email>
Wed, 13 Jul 2011 17:05:57 +0000 (17:05 +0000)
committerMaria Dimashova <no@email>
Wed, 13 Jul 2011 17:05:57 +0000 (17:05 +0000)
modules/highgui/include/opencv2/highgui/highgui_c.h
modules/highgui/src/cap_openni.cpp

index 2ad1fd0..a5fbb84 100644 (file)
@@ -360,7 +360,10 @@ enum
     CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH  = 101, // in mm
     CV_CAP_PROP_OPENNI_BASELINE         = 102, // in mm
     CV_CAP_PROP_OPENNI_FOCAL_LENGTH     = 103, // in pixels
-    CV_CAP_PROP_OPENNI_REGISTRATION_ON    = 104, // flag
+    CV_CAP_PROP_OPENNI_REGISTRATION_ON  = 104, // flag
+    CV_CAP_PROP_OPENNI_REGISTRATION     = CV_CAP_PROP_OPENNI_REGISTRATION_ON, // flag that synchronizes the remapping depth map to image map
+                                                                              // by changing depth generator's view point (if the flag is "on") or
+                                                                              // sets this view point to its normal one (if the flag is "off").
     CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_OUTPUT_MODE,
     CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_BASELINE,
     CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH,
index 25dceb1..c862e67 100644 (file)
@@ -228,7 +228,7 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
         // Set map output mode.
         CV_Assert( depthGenerator.SetMapOutputMode( depthOutputMode ) == XN_STATUS_OK ); // xn::DepthGenerator supports VGA only! (Jan 2011)
         CV_Assert( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK );
-        CV_Assert( depthGenerator.GetAlternativeViewPointCap().SetViewPoint( imageGenerator ) == XN_STATUS_OK );
+        CV_Assert( setProperty(CV_CAP_PROP_OPENNI_REGISTRATION, 1.0) );
 
         //  Start generating data.
         status = context.StartGeneratingAll();
@@ -360,30 +360,48 @@ double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx )
 
 bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue )
 {
+    bool res = false;
+
     CV_Assert( depthGenerator.IsValid() );
-    switch(propIdx)
+
+    switch( propIdx )
     {
-        case CV_CAP_PROP_OPENNI_REGISTRATION_ON:
+        case CV_CAP_PROP_OPENNI_REGISTRATION:
             {
-                CV_Assert( imageGenerator.IsValid() );
-                if (!depthGenerator.GetAlternativeViewPointCap ().IsViewPointAs (imageGenerator))
+                if( propValue != 0.0 ) // "on"
                 {
-                    if (depthGenerator.GetAlternativeViewPointCap ().IsViewPointSupported (imageGenerator))
+                    CV_Assert( imageGenerator.IsValid() );
+                    if( !depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) )
                     {
-                      XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint (imageGenerator);
-                      if (status != XN_STATUS_OK)
-                         CV_Error( CV_StsError, std::string("turning registration on failed. Reason: ") + xnGetStatusString (status));
+                        if( depthGenerator.GetAlternativeViewPointCap().IsViewPointSupported(imageGenerator) )
+                        {
+                            XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator);
+                            if( status != XN_STATUS_OK )
+                                std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
+                            else
+                                res = true;
+                        }
+                        else
+                           std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl;
                     }
                     else
-                       CV_Error( CV_StsError, "turning registration on failed. Reason: unsupported viewpoint");
+                        res = true;
+                }
+                else // "off"
+                {
+                    XnStatus status = depthGenerator.GetAlternativeViewPointCap().ResetViewPoint();
+                    if( status != XN_STATUS_OK )
+                        std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl;
+                    else
+                        res = true;
                 }
             }
-            return true;
             break;
         default:
-            CV_Error( CV_StsBadArg, "Depth generator does not support such parameter for setting.\n");
+            CV_Error( CV_StsBadArg, "Unsupported depth generator property.\n");
     }
-    return false;
+
+    return res;
 }
 
 double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx )
@@ -414,10 +432,13 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue
     bool res = false;
 
     CV_Assert( imageGenerator.IsValid() );
-    XnMapOutputMode newImageOutputMode = imageOutputMode;
+
     switch( propIdx )
     {
     case CV_CAP_PROP_OPENNI_OUTPUT_MODE :
+    {
+        XnMapOutputMode newImageOutputMode = imageOutputMode;
+
         switch( cvRound(propValue) )
         {
         case CV_CAP_OPENNI_VGA_30HZ :
@@ -433,16 +454,19 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue
         default :
             CV_Error( CV_StsBadArg, "Unsupported image generator output mode.\n");
         }
-        break;
 
-   default:
-        CV_Error( CV_StsBadArg, "Image generator does not support such parameter for setting.\n");
+        XnStatus status = imageGenerator.SetMapOutputMode( newImageOutputMode );
+        if( status != XN_STATUS_OK )
+            std::cerr << "CvCapture_OpenNI::setImageGeneratorProperty : " << xnGetStatusString(status) << std::endl;
+        else
+        {
+            imageOutputMode = newImageOutputMode;
+            res = true;
+        }
+        break;
     }
-
-    if( imageGenerator.SetMapOutputMode( newImageOutputMode ) == XN_STATUS_OK )
-    {
-        imageOutputMode = newImageOutputMode;
-        res = true;
+    default:
+        CV_Error( CV_StsBadArg, "Unsupported image generator property.\n");
     }
 
     return res;