int
main( int /* argc */, char* /* * argv */ )
{
   TriclopsContext	triclops;
   TriclopsError       	error;
   TriclopsInput 	triclopsInput;
   char* 		szInputFile 	= "input.ppm";
   char* 		szCalFile 	= "input.cal";
   char* 		szDisparityBase	= "disparity";


   // Get the camera calibration data
   error = triclopsGetDefaultContextFromFile( &triclops, szCalFile );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetDefaultContextFromFile(): "
			   "Can't open calibration file", 
			   error );
   
   // Load images from file
   if ( !ppmReadToTriclopsInput( szInputFile,  &triclopsInput ) )
   {
      printf( "ppmReadToTriclopsInput() failed. Can't read '%s'\n", szInputFile );
      return 1;
   }
   
   doRectifyStereoSave( triclops, &triclopsInput, szDisparityBase, "default" );

   // try doing stereo with a big stereo mask
   triclopsSetStereoMask( triclops, 21 );
   doRectifyStereoSave( triclops, &triclopsInput, szDisparityBase, "bigmask" );

   // try doing stereo with a small stereo mask
   triclopsSetStereoMask( triclops, 5 );
   doRectifyStereoSave( triclops, &triclopsInput, szDisparityBase, "smallmask" );

   // set mask to a neutral value
   triclopsSetStereoMask( triclops, 11 );

   // try doing stereo without any validation
   triclopsSetSurfaceValidation( triclops, 0 );
   triclopsSetUniquenessValidation( triclops, 0 );
   triclopsSetTextureValidation( triclops, 0 );
   doRectifyStereoSave( triclops, &triclopsInput, szDisparityBase, "novalidation" );

   // try doing stereo with only texture and surface
   triclopsSetSurfaceValidation( triclops, 1 );
   triclopsSetTextureValidation( triclops, 1 );
   doRectifyStereoSave( triclops, &triclopsInput, szDisparityBase, "surf-tex-val" );


   // try doing stereo in 2 camera mode with back and forth validation
   triclopsSetCameraConfiguration( triclops, TriCfg_2CAM_HORIZONTAL );
   triclopsSetBackForthValidation( triclops, 1 );
   doRectifyStereoSave( triclops, &triclopsInput, szDisparityBase, "backforth" );

   // try doing stereo in subpixel mode to compare the results of subpixel with
   // whole pixel - try running "convertimage16" example to convert this image to
   // one that is more easily viewed
   triclopsSetSubpixelInterpolation( triclops, 1 );
   doRectifyStereoSave( triclops, &triclopsInput, szDisparityBase, "subpixel" );


   
   // clean up memory allocated in context
   freeInput( &triclopsInput );
   error = triclopsDestroyContext( triclops );
   _HANDLE_TRICLOPS_ERROR( "triclopsDestroyContext()", error );
   
   return 0;
}
Beispiel #2
0
int
main( int /* argc */, char** /* argv */ )
{
   TriclopsContext     context;
   TriclopsImage       depthImage;
   TriclopsInput       inputData;
   TriclopsError       error;
   
   // get the camera module configuration
   error = triclopsGetDefaultContextFromFile( &context, "config" );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetDefaultContextFromFile()", error );
   if ( error != TriclopsErrorOk )
   {
      printf( "Can't open calibration file 'config'\n" );
      exit( 1 );
   }
   
   // Load images from file
   TriclopsBool bErr = ppmReadToTriclopsInput( "input.ppm", &inputData );
   if( !bErr )
   {
      printf( "ppmReadToTriclopsInput() failed. Can't find input.ppm?\n" );
      exit( 1 );
   }
   
   // set up some stereo parameters:
   // set to 320x240 output images
   error = triclopsSetResolution( context, 240, 320 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetResolution()", error );
   // set disparity range
   error = triclopsSetDisparity( context, 5, 60 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetDisparity()", error );
   
   // set the display mapping
   // note: disparity mapping corrupts the disparity values so that making
   // distance measurements is more difficult and less accurate.
   // Do not use it when you intend to actually use disparity values for
   // purposes other than display
   error = triclopsSetDisparityMapping( context, 128, 255 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetDisparityMapping()", error );
   error = triclopsSetDisparityMappingOn( context, 1 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetDisparityMappingOn()", error );
   // set the validation mappings to 0 (black)
   error = triclopsSetUniquenessValidationMapping( context, 0 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetUniquenessValidationMapping()", error );
   error = triclopsSetTextureValidationMapping( context, 0 );
   _HANDLE_TRICLOPS_ERROR( "triclopsSetTextureValidationMapping()", error );
   
   // Preprocessing the images
   error = triclopsPreprocess( context, &inputData );
   _HANDLE_TRICLOPS_ERROR( "triclopsPreprocess()", error );
     
   // stereo processing
   error =  triclopsStereo( context );
   _HANDLE_TRICLOPS_ERROR( "triclopsStereo()", error );
   
   // retrieve the depth image from the context
   error = triclopsGetImage( context, TriImg_DISPARITY, TriCam_REFERENCE, &depthImage );
   _HANDLE_TRICLOPS_ERROR( "triclopsGetImage()", error );
   
   // save the depth image
   error = triclopsSaveImage( &depthImage, "depth.pgm" );
   _HANDLE_TRICLOPS_ERROR( "triclopsSaveImage()", error );
   
   
   // clean up memory allocated in context
   freeInput( &inputData );
   error = triclopsDestroyContext( context );
   
   return 0;
}