Exemplo n.º 1
0
shared_ptr<gray32F_image_t>  SensorAttributeImage::run(const char* attributeName)
{

	SensorIndexation sensorIndexation(m_lidarContainer, m_nbCols);
	sensorIndexation.setResolution(1);
	sensorIndexation.indexData();


	const SensorIndexation::GriddedDataType& grid = sensorIndexation.getSpatialIndexation();

	shared_ptr<gray32F_image_t> result_image(new gray32F_image_t(grid.GetTaille().x, grid.GetTaille().y));
	gray32F_image_t::view_t sensorImage  = view(*result_image);

	const LidarConstIteratorAttribute<float> beginAttribute = m_lidarContainer->beginAttribute<float>(attributeName);

	for(int col = 0; col < sensorImage.width(); ++col)
	{
		for(int lig = 0; lig < sensorImage.height(); ++lig)
		{
			if(!grid(col,lig).empty())
			{
				sensorImage(col,lig) = *(beginAttribute + *grid(col,lig).begin());
			}
		}
	}


	return result_image;
}
int main (int argc, char ** argv) {
  if(argc <= 2){
    throw std::runtime_error("No parameters given. Usage: " + usage(argv[0]));
  }

  //Parse all parameters
  std::map<std::string, std::string> parameter_name_value_map;
  bool parse_succeeded = Utils::parseParamters(argc, argv, parameter_name_value_map);
  if(!parse_succeeded){
    throw std::runtime_error("Mangled command line arguments. " + usage(argv[0]));
  }

  //check if we found a config file.
  if(parameter_name_value_map.count("conf") == 0){
    throw std::runtime_error("No config file was given" + usage(argv[0]));
  }

  std::string config_file = parameter_name_value_map["conf"];
  parameter_name_value_map.erase("conf");
  Utils::Config conf(config_file, parameter_name_value_map);

  Utils::DataLoader dl(conf);
  std::vector<std::string>  image_sets;
  image_sets.push_back("test_images");
  image_sets.push_back("train_images");

  for(std::string  set : image_sets){
    //Get the image list.
    std::vector<std::string> image_list = dl.getImageList(set);

    //for each image
    for(std::string file : image_list){

      //load the image data
      pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud;
      pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_unrectified;
      dl.create_cloud(file, cloud, cloud_unrectified);

      //voxelize
      std::map<int, std::shared_ptr<Voxel> > voxels;
      dl.extractVoxels(cloud, cloud_unrectified, voxels);

      //Save the image to disk.
      //Project
      cv::Mat result_image(cloud->height, cloud->width, CV_32SC1, cv::Scalar(0));
      for(auto v : voxels){
        v.second->drawValueIntoImage<int>(result_image, v.second->getVoxelID());
      }

      //Save
      cv::imwrite(dl.getVoxelName(file), Utils::segmentIdToBgr(result_image));
    }
  }
  return 0;
}
int main (int argc, char ** argv) {
  if(argc <= 2){
    throw std::runtime_error("No parameters given. Usage: " + usage(argv[0]));
  }

  //Parse all parameters
  std::map<std::string, std::string> parameter_name_value_map;
  bool parse_succeeded = Utils::parseParamters(argc, argv, parameter_name_value_map);
  if(!parse_succeeded){
    throw std::runtime_error("Mangled command line arguments. " + usage(argv[0]));
  }

  //check if we found a config file.
  if(parameter_name_value_map.count("conf") == 0){
    throw std::runtime_error("No config file was given" + usage(argv[0]));
  }

  std::string config_file = parameter_name_value_map["conf"];
  parameter_name_value_map.erase("conf");
  Utils::Config conf(config_file, parameter_name_value_map);

  Utils::DataLoader dl(conf);

  Utils::RgbLabelConversion label_converter = dl.getLabelConverter();

  std::vector<std::string> image_names = dl.getImageList(conf.get<std::string>("key","test_images"));

  //For each image
  for(std::string image_name : image_names){
    //Load the image
    cv::Mat color = dl.loadColor(image_name);
    cv::Mat depth = dl.loadDepth(image_name);
    cv::Mat label = dl.loadLabel(image_name);
    Utils::Calibration calib = dl.loadCalibration(image_name);
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud;
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_unrectified;
    dl.create_cloud(depth, color, calib, cloud, cloud_unrectified);

    //Get the voxels, we don't use the stored ones to easily visualize the change of parameters.
    std::map<int, std::shared_ptr<Voxel> > voxels;
    dl.extractVoxels(cloud, cloud_unrectified, voxels);

    int n = voxels[1]->getFeatures().rows(); //Just to get the size once.

    cv::Mat result_image(cloud->height, cloud->width, CV_32FC1, cv::Scalar(0));
    for(int j = 0; j < n; j++){
      for(auto v : voxels){
        libf::DataPoint f = v.second->getFeatures();
        v.second->drawValueIntoImage<float>(result_image, f(j));
      }
      Utils::ShowCvMatHeatMap(result_image);
    }
    cv::Mat label_image(cloud->height, cloud->width, CV_32SC1, cv::Scalar(-1));
    for(auto v : voxels){
      v.second->computeLabel(label);
      v.second->drawLabelIDIntoImage(label_image);
    }
    Utils::ShowCvMat(label_converter.labelToRgb(label_image));
  }
  return 0;
}