Creating color disparity images from mono images using Bumblebee2 and BumblebeeXB3 cameras

Last Revision Date: 12/21/2015

This article explains how to create color disparity images from Bumblebee2/XB3 cameras. By default, the Triclops API does not support color disparity images. Use the following code snippet from the triclopsDemo.exe to remap a mono disparity image into a color disparity image.

void

CPGRStereoDoc::remapDisparityImage()

{

     TriclopsError          te; 

     TriclopsBool                    bSubpixelOn;

 

     te = triclopsGetSubpixelInterpolation( m_triclopsContext, &bSubpixelOn ); 

     ASSERT( te == TriclopsErrorOk );

 

      // if mapping parameters have not changed, this function returns

      // without regenerating the tables

     generateLookupTables();

 

 

      if ( bSubpixelOn )

     {

           TriclopsImage16     imageDisparity;

           // get the 16 bit depth image

           te = triclopsGetImage16(

                m_triclopsContext, TriImg16_DISPARITY, TriCam_REFERENCE, &imageDisparity );

 

          if ( te != TriclopsErrorOk )

           {

                     ASSERT( false );

               return;

           }

 

      unsigned short* pRow       = imageDisparity.data;

     int iPixelInc                  = imageDisparity.rowinc/2;

 

     unsigned char*  pucDisp = m_arpBitmap[ IMAGE_DISPARITY ]->getDataPointer();

 

      for ( int r = 0, I = 0; r < imageDisparity.nrows; r++ )

      {

           for ( int c = 0; c < imageDisparity.ncols; c++ )

           {

                if (pRow[c] >= 0xFF00)

                {

                     // for an invalid pixel, only take the bottom 8-bits

                     int index = 0x00FF & pRow[c];

 

                     pucDisp[ i++ ] = m_ucInvalidDisparityMapLUT[index][0]; // blue

                     pucDisp[ i++ ] = m_ucInvalidDisparityMapLUT[index][1]; // green

                     pucDisp[ i++ ] = m_ucInvalidDisparityMapLUT[index][2]; // red

                     i++; // unused

               }

                else

                {

                     int index = pRow[c] >> DISPARITY_LUT_SHIFT_BITS;

                     pucDisp[ i++ ] = m_ucValidDisparityMapLUT[index][0]; // blue

                     pucDisp[ i++ ] = m_ucValidDisparityMapLUT[index][1]; // green

                     pucDisp[ i++ ] = m_ucValidDisparityMapLUT[index][2]; // red

                      i++; // unused

                }

           }

           pRow   += iPixelInc;

      }

 }

 else // if ( bSubpixelOn )

 {

           // subpixel is not on – let’s remap with the 8-bit disparity image

           TriclopsImage   imageDisparity;

           // get the 8-bit depth image

           te = triclopsGetImage(

                m_triclopsContext, TriImg_DISPARITY, TriCam_REFERENCE, &imageDisparity );

           if ( te != TriclopsErrorOk )

           {

                    ASSERT(false );

                return;

           }

 

           unsigned char* pRow = imageDisparity.data;

          Int iPixelInc     = imageDisparity.rowinc;

 

      Unsigned char*  pucDisp = m_arpBitmap[ IMAGE_DISPARITY ]->getDataPointer();

      for ( int r =0,i =0; r < imageDisparity.nrows; r++ )

      {

                for ( int c = 0; c < imageDisparity.ncols; c++ )

                {

                     if (pRow[c] > 239)

                     {

                          // invalid pixel

                          int index = pRow[c];

                          pucDisp[ i++ ] = m_ucInvalidDisparityMapLUT[index][0]; // red

                          pucDisp[ i++ ] = m_ucInvalidDisparityMapLUT[index][1]; // green

                          pucDisp[ i++ ] = m_ucInvalidDisparityMapLUT[index][2]; // blue

                          i++; // unused

                     }

                     else

                     {

                          // valid pixel

                          int index = pRow[c] << (8 - DISPARITY_LUT_SHIFT_BITS);

                          pucDisp[ i++ ] = m_ucValidDisparityMapLUT[index][0]; // red

                          pucDisp[ i++ ] = m_ucValidDisparityMapLUT[index][1]; // green

                          pucDisp[ i++ ] = m_ucValidDisparityMapLUT[index][2]; // blue

                          ++; // unused

                     }

                }

                pRow     += iPixelInc;

           }

     }

}

Artículos relacionados