void  FastDisparityCostVolumeEstimator::compute(gil::rgb8c_view_t  &left,
                                                gil::rgb8c_view_t &right,
                                                DisparityCostVolume &cost_volume)
{
    compute_impl(left, right, cost_volume);
    return;
}
Пример #2
0
void 
pcl::GrayStereoMatching::compute (unsigned char* ref_img, unsigned char* trg_img, int width, int height)
{
    
  //Check that a suitable value of max_disp has been selected
  if ( max_disp_ <= 0)
  {
    PCL_ERROR(
      "[pcl::StereoMatching::compute] Error. A positive max_disparity value has not be correctly inserted. Aborting..\n"
    );
    return;
  }

  if ( (disp_map_ != NULL) && (width_ != width || height_ != height) )
  {
    delete [] disp_map_;
    disp_map_ = NULL;

    if ( disp_map_trg_ != NULL)
    {
      delete [] disp_map_trg_;
      disp_map_trg_ = NULL;
    }

    if ( pp_ref_img_ != NULL)
    {
      delete [] pp_ref_img_;
      delete [] pp_trg_img_;
      pp_ref_img_ = NULL;
      pp_trg_img_ = NULL;
    }
  }

  if ( disp_map_ == NULL)
  {
    disp_map_ = new short int[width * height];  
      
    width_ = width;
    height_ = height;
  }
    

  if ( is_lr_check_ && disp_map_trg_ == NULL)
  {
    disp_map_trg_ = new short int[width * height];  
  }

  if ( !is_lr_check_ && disp_map_trg_ != NULL)
  {
    delete [] disp_map_trg_;
    disp_map_trg_ = NULL;
  }

  if ( is_pre_proc_ && pp_ref_img_ == NULL)
  {
    pp_ref_img_ = new unsigned char[width_*height_];
    pp_trg_img_ = new unsigned char[width_*height_];
  }

  if ( !is_pre_proc_ && pp_ref_img_ != NULL)
  {
    delete [] pp_ref_img_;
    delete [] pp_trg_img_;
    pp_ref_img_ = NULL;
    pp_trg_img_ = NULL;
  }

  memset(disp_map_, 0, sizeof(short int)*height_*width_);

  if ( is_pre_proc_)
  {
    preProcessing(ref_img, pp_ref_img_);
    preProcessing(trg_img, pp_trg_img_);
  }

  if (is_lr_check_)
  {

    if ( is_pre_proc_)
    {
      imgFlip(pp_ref_img_);
      imgFlip(pp_trg_img_);

      compute_impl(pp_trg_img_, pp_ref_img_);

      imgFlip(pp_ref_img_);
      imgFlip(pp_trg_img_);
    }
    else
    {
      imgFlip(ref_img);
      imgFlip(trg_img);

      compute_impl(trg_img, ref_img);

      imgFlip(ref_img);
      imgFlip(trg_img);
    }

    for (int j = 0; j < height_; j++)
      for (int i = 0; i < width_; i++)
        disp_map_trg_[j * width_ + i] = disp_map_[j * width_ + width_ - 1 - i];

  }

  if ( is_pre_proc_)
    compute_impl(pp_ref_img_, pp_trg_img_);
  else
    compute_impl(ref_img, trg_img);

  if ( is_lr_check_)
  {
    leftRightCheck();
  }

  //at the end, x_offset (*16) needs to be added to all computed disparities, 
  //so that each fixed point value of the disparity map represents the true disparity value multiplied by 16  
  for (int j = 0; j < height_; j++)
    for (int i = 0; i < width_; i++)
      if ( disp_map_[j * width_ + i] > 0)
	    disp_map_[j * width_ + i] += static_cast<short int> (x_off_ * 16);

}