Ejemplo n.º 1
0
int main(int argc, char **argv, char **envp) {
  int ** matriz_adj = NULL;
  int N;
  int i;
  if (argc != 2) {
    printUsage();
    exit(1);
  }
  if (strlen(argv[1]) < 4 || strcmp(argv[1] + strlen(argv[1]) - 4, ".adj") != 0) {
    printUsage();
    exit(1);
  }

  if (readMatrixFromFile(argv[1], &matriz_adj, &N)) {
    printf("Erro na leitura da matriz do ficheiro!!!\n");
    exit(3);
  }

  printf("Densidade do grafo: %.4f\n", getGraphDensity(matriz_adj, N));
  printf("Grau maximo do grafo: %d\n", getGraphHighRank(matriz_adj, N));
  writeMatrixToFile(argv[1], matriz_adj, N);

  for (i=0;i<N;i++)
    free(matriz_adj[i]);
  free(matriz_adj);
  return 0;
}
int main(int argc, char** argv) {
	Matrix *m1 = NULL, *m2 = NULL, *resultSequential = NULL, *resultParallel = NULL;
	int numParallelTasks = 1;
	struct timeval diff;

	checkArgsSize(argc);
	
	m1 = readMatrixFromFile(M1);
	m2 = readMatrixFromFile(M2);
	 
	checkInputMatrices(m1, m2);
	checkNumTasks(argv, &numParallelTasks, m1);
		
	diff = measureBalanceWork(m1, m2, numParallelTasks, &resultParallel, balanceWork);
	writeMatrixInFile(OUT, resultParallel);
		 	
	printTime("Tempo levado para executar a multiplicação com %d threads: ", numParallelTasks, diff);

	pthread_exit(NULL);
}
Ejemplo n.º 3
0
int readTwoOnDimMatrixFromAFile(char *fileName , oneDimMatrix * a , oneDimMatrix * b){
   FILE *fp;
   int numberOfLines = 0;

   fp = openAFileForReading(fileName);
   numberOfLines = readMatrixFromFile(fp, numberOfLines, DETECT_SIZE, a);
   printf("%d  %d %d \n" ,numberOfLines ,  a->nrows , a->ncols );
   numberOfLines= readMatrixFromFile(fp, numberOfLines, DETECT_SIZE , b);
   printf("%d  %d %d \n" ,numberOfLines , b->nrows , b->ncols);
   if(a->nrows != b->nrows)
      inconsistentErrorReport("Different number of rows in each matrix.", 
                              numberOfLines, a->nrows , a->ncols);
   fclose(fp);

   *a = createMatrix(a->nrows , a->ncols);
   *b = createMatrix(b->nrows , b->ncols);
   fp = openAFileForReading(fileName);
   numberOfLines = readMatrixFromFile(fp, numberOfLines, READ_MATRIX, a);
   numberOfLines= readMatrixFromFile(fp, numberOfLines, READ_MATRIX , b);
   fclose(fp);   
   /*   printOneDimMatrix(a);  printf("\n");  printOneDimMatrix(b); */
   return numberOfLines;
}
Ejemplo n.º 4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    thread = new QThread();
    reader = new Reader();

    reader->moveToThread(thread);
    connect(reader, SIGNAL(sendPoint(int,int,double)),
            this, SLOT(setPointProb(int,int,double)));
    connect(reader, SIGNAL(workRequested()), thread, SLOT(start()));
    connect(thread, SIGNAL(started()), reader, SLOT(doWork()));
    connect(reader, SIGNAL(finished()),
            thread, SLOT(quit()) , Qt::DirectConnection);
    connect(reader, SIGNAL(finished()),
            this, SLOT(fileFinished()));
    connect(reader, SIGNAL(sendReset()), this, SLOT(resetPositions()));

    setFixedSize(800,600);
    p_scene = new QGraphicsScene(this);
    p_view = new QGraphicsView(p_scene, this);

    QPixmap background(QCoreApplication::applicationDirPath() +
                                   "/img/sol.png");
    if (background.isNull()) {
        std::cout << "Ouverture de sol.png échouée, ouverture de sol.jpg" << std::endl;
        background = QPixmap(QCoreApplication::applicationDirPath() +
                                       "/img/sol.jpg");
    }

    p_scene->setBackgroundBrush(QBrush(background));
    p_view->setGeometry(10,10,505,505);

    p_addPosition = new QPushButton("Ajouter position", this);
    p_addPosition->setGeometry(590,90, 120, 30);

    p_deletePos = new QPushButton("Réinitialiser positions", this);
    p_deletePos->setGeometry(590,130, 120, 30);

    p_openFile = new QPushButton("Ouvrir fichier", this);
    p_openFile->setGeometry(590, 170, 120, 30);

    p_changeTableSize = new QPushButton("Changer taille table", this);
    p_changeTableSize->setGeometry(50, 560, 120, 30);

    pauseButton = new QPushButton("", this);
    QIcon pauseIcon(QCoreApplication::applicationDirPath() + "/img/pause.png");
    if (pauseIcon.isNull()) {
        std::cout << "Ouverture de pause.png échouée, ouverture de pause.jpg" << std::endl;
        pauseIcon = QIcon((QCoreApplication::applicationDirPath() + "/img/pause.jpg"));
    }
    pauseButton->setIcon(pauseIcon);
    pauseButton->setGeometry(590, 250, 30, 30);
    pauseButton->setDisabled(true);

    stopButton = new QPushButton("", this);
    QIcon stopIcon(QCoreApplication::applicationDirPath() + "/img/stop.png");
    if (stopIcon.isNull()) {
        std::cout << "Ouverture de stop.png échouée, ouverture de stop.jpg" << std::endl;
        pauseIcon = QIcon((QCoreApplication::applicationDirPath() + "/img/stop.jpg"));
    }
    stopButton->setIcon(stopIcon);
    stopButton->setGeometry(630, 250, 30, 30);
    stopButton->setDisabled(true);

    stepButton = new QPushButton("", this);
    QIcon stepIcon(QCoreApplication::applicationDirPath() + "/img/step.png");
    if (stepIcon.isNull()) {
        std::cout << "Ouverture de step.png échouée, ouverture de step.jpg" << std::endl;
        stepIcon = QIcon((QCoreApplication::applicationDirPath() + "/img/step.jpg"));
    }
    stepButton->setIcon(stepIcon);
    stepButton->setGeometry(670, 250, 30, 30);
    stepButton->setDisabled(true);

    p_quit = new QPushButton("Quitter", this);
    p_quit->setGeometry(600, 560, 100, 30);

    p_addPosX = new QLineEdit(this);
    p_addPosY = new QLineEdit(this);
    p_addPosP = new QLineEdit(this);

    p_addPosX->setGeometry(580, 50, 40, 30);
    p_addPosY->setGeometry(630, 50, 40, 30);
    p_addPosP->setGeometry(680, 50, 40, 30);

    p_addPosX->setPlaceholderText("Abscisse");
    p_addPosY->setPlaceholderText("Ordonnée");
    p_addPosP->setPlaceholderText("Proba");

    currentDate = new QLabel("Pas de fichier en cours", this);
    currentDate->setGeometry(580, 300, 140, 30);


    QObject::connect(p_addPosition, SIGNAL(clicked()),
                     this, SLOT(sendPointProbValues()));
    QObject::connect(this, SIGNAL(pointProbValues(int,int,double)),
                     this, SLOT(setPointProb(int,int,double)));
    QObject::connect(p_deletePos, SIGNAL(clicked()),
                     this, SLOT(resetPositions()));
    QObject::connect(p_quit, SIGNAL(clicked()),
                     qApp, SLOT(quit()));
    QObject::connect(p_openFile, SIGNAL(clicked()),
                     this, SLOT(readMatrixFromFile()));
    QObject::connect(p_changeTableSize, SIGNAL(clicked()),
                     this, SLOT(changeTableSize()));
    QObject::connect(pauseButton, SIGNAL(clicked()),
                     this, SLOT(pauseRead()));
    QObject::connect(stopButton, SIGNAL(clicked()),
                     this, SLOT(stopRead()));
    QObject::connect(reader, SIGNAL(sendDate(QString)),
                     this, SLOT(setDate(QString)));
    QObject::connect(stepButton, SIGNAL(clicked()),
                     this, SLOT(clickNextDate()));


}
Ejemplo n.º 5
0
void pcl::face_detection::FaceDetectorDataProvider<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>::initialize(std::string & data_dir)
{
  std::string start;
  std::string ext = std::string ("pcd");
  bf::path dir = data_dir;

  std::vector < std::string > files;
  getFilesInDirectory (dir, start, files, ext);

  //apart from loading the file names, we will do some bining regarding pitch and yaw
  std::vector < std::vector<int> > yaw_pitch_bins;
  std::vector < std::vector<std::vector<std::string> > > image_files_per_bin;

  float res_yaw = 15.f;
  float res_pitch = res_yaw;
  int min_yaw = -75;
  int min_pitch = -60;

  int num_yaw = static_cast<int>((std::abs (min_yaw) * 2) / static_cast<int>(res_yaw + 1.f));
  int num_pitch = static_cast<int>((std::abs (min_pitch) * 2) / static_cast<int>(res_pitch + 1.f));

  yaw_pitch_bins.resize (num_yaw);
  image_files_per_bin.resize (num_yaw);
  for (int i = 0; i < num_yaw; i++)
  {
    yaw_pitch_bins[i].resize (num_pitch);
    image_files_per_bin[i].resize (num_pitch);
    for (int j = 0; j < num_pitch; j++)
    {
      yaw_pitch_bins[i][j] = 0;
    }
  }

  for (size_t i = 0; i < files.size (); i++)
  {
    std::stringstream filestream;
    filestream << data_dir << "/" << files[i];
    std::string file = filestream.str ();

    std::string pose_file (files[i]);
    boost::replace_all (pose_file, ".pcd", "_pose.txt");

    Eigen::Matrix4f pose_mat;
    pose_mat.setIdentity (4, 4);

    std::stringstream filestream_pose;
    filestream_pose << data_dir << "/" << pose_file;
    pose_file = filestream_pose.str ();

    bool result = readMatrixFromFile (pose_file, pose_mat);
    if (result)
    {
      Eigen::Vector3f ea = pose_mat.block<3, 3> (0, 0).eulerAngles (0, 1, 2);
      ea *= 57.2957795f; //transform it to degrees to do the binning
      int y = static_cast<int>(pcl_round ((ea[0] + static_cast<float>(std::abs (min_yaw))) / res_yaw));
      int p = static_cast<int>(pcl_round ((ea[1] + static_cast<float>(std::abs (min_pitch))) / res_pitch));

      if (y < 0)
        y = 0;
      if (p < 0)
        p = 0;
      if (p >= num_pitch)
        p = num_pitch - 1;
      if (y >= num_yaw)
        y = num_yaw - 1;

      assert (y >= 0 && y < num_yaw);
      assert (p >= 0 && p < num_pitch);

      yaw_pitch_bins[y][p]++;

      image_files_per_bin[y][p].push_back (file);
    }
  }

  pcl::face_detection::showBining (num_pitch, res_pitch, min_pitch, num_yaw, res_yaw, min_yaw, yaw_pitch_bins);

  int max_elems = 0;
  int total_elems = 0;

  for (int i = 0; i < num_yaw; i++)
  {
    for (int j = 0; j < num_pitch; j++)
    {
      total_elems += yaw_pitch_bins[i][j];
      if (yaw_pitch_bins[i][j] > max_elems)
        max_elems = yaw_pitch_bins[i][j];
    }
  }

  float average = static_cast<float> (total_elems) / (static_cast<float> (num_pitch + num_yaw));
  std::cout << "The average number of image per bin is:" << average << std::endl;

  std::cout << "Total number of images in the dataset:" << total_elems << std::endl;
  //reduce unbalance from dataset by capping the number of images per bin, keeping at least a certain min
  if (min_images_per_bin_ != -1)
  {
    std::cout << "Reducing unbalance of the dataset." << std::endl;
    for (int i = 0; i < num_yaw; i++)
    {
      for (int j = 0; j < num_pitch; j++)
      {
        if (yaw_pitch_bins[i][j] >= min_images_per_bin_)
        {
          std::random_shuffle (image_files_per_bin[i][j].begin (), image_files_per_bin[i][j].end ());
          image_files_per_bin[i][j].resize (min_images_per_bin_);
          yaw_pitch_bins[i][j] = min_images_per_bin_;
        }

        for (size_t ii = 0; ii < image_files_per_bin[i][j].size (); ii++)
        {
          image_files_.push_back (image_files_per_bin[i][j][ii]);
        }
      }
    }
  }

  pcl::face_detection::showBining (num_pitch, res_pitch, min_pitch, num_yaw, res_yaw, min_yaw, yaw_pitch_bins);
  std::cout << "Total number of images in the dataset:" << image_files_.size () << std::endl;
}
Ejemplo n.º 6
0
void pcl::face_detection::FaceDetectorDataProvider<FeatureType, DataSet, LabelType, ExampleIndex, NodeType>::getDatasetAndLabels(DataSet & data_set,
    std::vector<LabelType> & label_data, std::vector<ExampleIndex> & examples)
{
  srand (static_cast<unsigned int>(time (NULL)));
  std::random_shuffle (image_files_.begin (), image_files_.end ());
  std::vector < std::string > files;
  files = image_files_;
  files.resize (std::min (num_images_, static_cast<int> (files.size ())));

  std::vector < TrainingExample > training_examples;
  std::vector<float> labels;

  int total_neg, total_pos;
  total_neg = total_pos = 0;

#if PCL_FACE_DETECTION_VIS_TRAINING_FDDP == 1
  pcl::visualization::PCLVisualizer vis("training");
#endif

  for (size_t j = 0; j < files.size (); j++)
  {

#if PCL_FACE_DETECTION_VIS_TRAINING_FDDP == 1
    vis.removeAllPointClouds();
    vis.removeAllShapes();
#endif

    if ((j % 50) == 0)
    {
      std::cout << "Loading image..." << j << std::endl;
    }
    //1. Load clouds with and without labels
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr loaded_cloud (new pcl::PointCloud<pcl::PointXYZ>);

    pcl::io::loadPCDFile (files[j], *loaded_cloud);

    pcl::PointCloud<pcl::PointXYZL>::Ptr cloud_labels (new pcl::PointCloud<pcl::PointXYZL>);
    pcl::PointCloud<pcl::PointXYZL>::Ptr loaded_cloud_labels (new pcl::PointCloud<pcl::PointXYZL>);
    pcl::io::loadPCDFile (files[j], *loaded_cloud_labels);

    //crop images to remove as many NaNs as possible and reduce the memory footprint
    {
      size_t min_col, min_row;
      size_t max_col, max_row;
      min_col = min_row = std::numeric_limits<size_t>::max ();
      max_col = max_row = 0;

      for (size_t col = 0; col < loaded_cloud->width; col++)
      {
        for (size_t row = 0; row < loaded_cloud->height; row++)
        {
          if (pcl::isFinite (loaded_cloud->at (col, row)))
          {
            if (row < min_row)
              min_row = row;

            if (row > max_row)
              max_row = row;

            if (col < min_col)
              min_col = col;

            if (col > max_col)
              max_col = col;
          }
        }
      }

      //std::cout << min_col << " - " << max_col << std::endl;
      //std::cout << min_row << " - " << max_row << std::endl;

      cropCloud<pcl::PointXYZ> (min_col, max_col, min_row, max_row, *loaded_cloud, *cloud);
      cropCloud<pcl::PointXYZL> (min_col, max_col, min_row, max_row, *loaded_cloud_labels, *cloud_labels);

      /*pcl::visualization::PCLVisualizer vis ("training");
       vis.addPointCloud(loaded_cloud);
       vis.spin();*/
    }

    //Compute integral image over depth
    boost::shared_ptr < pcl::IntegralImage2D<float, 1> > integral_image_depth;
    integral_image_depth.reset (new pcl::IntegralImage2D<float, 1> (false));

    int element_stride = sizeof(pcl::PointXYZ) / sizeof(float);
    int row_stride = element_stride * cloud->width;
    const float *data = reinterpret_cast<const float*> (&cloud->points[0]);
    integral_image_depth->setInput (data + 2, cloud->width, cloud->height, element_stride, row_stride);

    //Compute normals and normal integral images
    pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);

    if (USE_NORMALS_)
    {
      typedef typename pcl::IntegralImageNormalEstimation<pcl::PointXYZ, pcl::Normal> NormalEstimator_;
      NormalEstimator_ n3d;
      n3d.setNormalEstimationMethod (n3d.COVARIANCE_MATRIX);
      n3d.setInputCloud (cloud);
      n3d.setRadiusSearch (0.02);
      n3d.setKSearch (0);
      {
        pcl::ScopeTime t ("compute normals...");
        n3d.compute (*normals);
      }
    }

    int element_stride_normal = sizeof(pcl::Normal) / sizeof(float);
    int row_stride_normal = element_stride_normal * normals->width;
    boost::shared_ptr < pcl::IntegralImage2D<float, 1> > integral_image_normal_x;
    boost::shared_ptr < pcl::IntegralImage2D<float, 1> > integral_image_normal_y;
    boost::shared_ptr < pcl::IntegralImage2D<float, 1> > integral_image_normal_z;

    if (USE_NORMALS_)
    {
      integral_image_normal_x.reset (new pcl::IntegralImage2D<float, 1> (false));
      const float *data_nx = reinterpret_cast<const float*> (&normals->points[0]);
      integral_image_normal_x->setInput (data_nx, normals->width, normals->height, element_stride_normal, row_stride_normal);

      integral_image_normal_y.reset (new pcl::IntegralImage2D<float, 1> (false));
      const float *data_ny = reinterpret_cast<const float*> (&normals->points[0]);
      integral_image_normal_y->setInput (data_ny + 1, normals->width, normals->height, element_stride_normal, row_stride_normal);

      integral_image_normal_z.reset (new pcl::IntegralImage2D<float, 1> (false));
      const float *data_nz = reinterpret_cast<const float*> (&normals->points[0]);
      integral_image_normal_z->setInput (data_nz + 2, normals->width, normals->height, element_stride_normal, row_stride_normal);
    }

    //Using cloud labels estimate a 2D window from where to extract positive samples
    //Rest can be used to extract negative samples
    size_t min_col, min_row;
    size_t max_col, max_row;
    min_col = min_row = std::numeric_limits<size_t>::max ();
    max_col = max_row = 0;

    //std::cout << cloud_labels->width << " " << cloud_labels->height << std::endl;

    for (size_t col = 0; col < cloud_labels->width; col++)
    {
      for (size_t row = 0; row < cloud_labels->height; row++)
      {
        if (cloud_labels->at (col, row).label == 1)
        {
          if (row < min_row)
            min_row = row;

          if (row > max_row)
            max_row = row;

          if (col < min_col)
            min_col = col;

          if (col > max_col)
            max_col = col;
        }
      }
    }

#if PCL_FACE_DETECTION_VIS_TRAINING_FDDP == 1
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_intensity(new pcl::PointCloud<pcl::PointXYZI>);
    cloud_intensity->width = cloud->width;
    cloud_intensity->height = cloud->height;
    cloud_intensity->points.resize(cloud->points.size());
    cloud_intensity->is_dense = cloud->is_dense;

    for (int jjj = 0; jjj < static_cast<int>(cloud->points.size()); jjj++)
    {
      cloud_intensity->points[jjj].getVector4fMap() = cloud->points[jjj].getVector4fMap();
      cloud_intensity->points[jjj].intensity = 0.f;
      int row, col;
      col = jjj % cloud->width;
      row = jjj / cloud->width;
      //std::cout << row << " " << col << std::endl;
      if (check_inside(col, row, min_col, max_col, min_row, max_row))
      {
        cloud_intensity->points[jjj].intensity = 1.f;
      }
    }

    pcl::visualization::PointCloudColorHandlerGenericField < pcl::PointXYZI > handler(cloud_intensity, "intensity");
    vis.addPointCloud(cloud_intensity, handler, "intensity_cloud");
#endif

    std::string pose_file (files[j]);
    boost::replace_all (pose_file, ".pcd", "_pose.txt");

    Eigen::Matrix4f pose_mat;
    pose_mat.setIdentity (4, 4);
    readMatrixFromFile (pose_file, pose_mat);

    Eigen::Vector3f ea = pose_mat.block<3, 3> (0, 0).eulerAngles (0, 1, 2);
    Eigen::Vector3f trans_vector = Eigen::Vector3f (pose_mat (0, 3), pose_mat (1, 3), pose_mat (2, 3));

    pcl::PointXYZ center_point;
    center_point.x = trans_vector[0];
    center_point.y = trans_vector[1];
    center_point.z = trans_vector[2];

    int N_patches = patches_per_image_;
    int pos_extracted = 0;
    int neg_extracted = 0;
    int w_size_2 = static_cast<int> (w_size_ / 2);

    //************************************************
    //2nd training style, fanelli's journal description
    //************************************************
    {

      typedef std::pair<int, int> pixelpair;
      std::vector < pixelpair > negative_p, positive_p;
      //get negative and positive indices to sample from
      for (int col = 0; col < (static_cast<int> (cloud_labels->width) - w_size_); col++)
      {
        for (int row = 0; row < (static_cast<int> (cloud_labels->height) - w_size_); row++)
        {
          if (!pcl::isFinite (cloud->at (col + w_size_2, row + w_size_2)))
            continue;

          //reject patches with more than percent invalid values
          float percent = 0.5f;
          if (static_cast<float>(integral_image_depth->getFiniteElementsCount (col, row, w_size_, w_size_)) < (percent * static_cast<float>(w_size_ * w_size_)))
            continue;

          pixelpair pp = std::make_pair (col, row);
          if (cloud_labels->at (col + w_size_2, row + w_size_2).label == 1)
            positive_p.push_back (pp);
          else
            negative_p.push_back (pp);
        }
      }

      //shuffle and resize
      std::random_shuffle (positive_p.begin (), positive_p.end ());
      std::random_shuffle (negative_p.begin (), negative_p.end ());
      positive_p.resize (N_patches);
      negative_p.resize (N_patches);

      //extract positive patch
      for (size_t p = 0; p < positive_p.size (); p++)
      {
        int col, row;
        col = positive_p[p].first;
        row = positive_p[p].second;

        pcl::PointXYZ patch_center_point;
        patch_center_point.x = cloud->at (col + w_size_2, row + w_size_2).x;
        patch_center_point.y = cloud->at (col + w_size_2, row + w_size_2).y;
        patch_center_point.z = cloud->at (col + w_size_2, row + w_size_2).z;

        TrainingExample te;
        te.iimages_.push_back (integral_image_depth);
        if (USE_NORMALS_)
        {
          te.iimages_.push_back (integral_image_normal_x);
          te.iimages_.push_back (integral_image_normal_y);
          te.iimages_.push_back (integral_image_normal_z);
        }

        te.row_ = row;
        te.col_ = col;
        te.wsize_ = w_size_;

        te.trans_ = center_point.getVector3fMap () - patch_center_point.getVector3fMap ();
        te.trans_ *= 1000.f; //transform it to millimeters
        te.rot_ = ea;
        te.rot_ *= 57.2957795f; //transform it to degrees

        labels.push_back (1);
        pos_extracted++;
        total_pos++;

        training_examples.push_back (te);
#if PCL_FACE_DETECTION_VIS_TRAINING_FDDP == 1
        pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_intensity2(new pcl::PointCloud<pcl::PointXYZI>(*cloud_intensity));
        for (int jjj = col; jjj < (col + w_size_); jjj++)
        {
          for (int iii = row; iii < (row + w_size_); iii++)
          {
            cloud_intensity2->at(jjj, iii).intensity = 2.f;
          }
        }

        vis.removeAllPointClouds();

        pcl::visualization::PointCloudColorHandlerGenericField < pcl::PointXYZI > handler(cloud_intensity2, "intensity");
        vis.addPointCloud(cloud_intensity2, handler, "cloud");
        vis.spinOnce();
        vis.spin();
        sleep(1);
#endif

      }

#if PCL_FACE_DETECTION_VIS_TRAINING_FDDP == 1
      std::cout << "Going to extract negative patches..." << std::endl;
      sleep(2);
#endif

      for (size_t p = 0; p < negative_p.size (); p++)
      {
        int col, row;
        col = negative_p[p].first;
        row = negative_p[p].second;

        TrainingExample te;
        te.iimages_.push_back (integral_image_depth);
        if (USE_NORMALS_)
        {
          te.iimages_.push_back (integral_image_normal_x);
          te.iimages_.push_back (integral_image_normal_y);
          te.iimages_.push_back (integral_image_normal_z);
        }

        te.row_ = row;
        te.col_ = col;
        te.wsize_ = w_size_;
        labels.push_back (0);
        neg_extracted++;
        total_neg++;

        training_examples.push_back (te);
#if PCL_FACE_DETECTION_VIS_TRAINING_FDDP == 1
        pcl::PointCloud<pcl::PointXYZI>::Ptr cloud_intensity2(new pcl::PointCloud<pcl::PointXYZI>(*cloud_intensity));
        for (int jjj = col; jjj < (col + w_size_); jjj++)
        {
          for (int iii = row; iii < (row + w_size_); iii++)
          {
            cloud_intensity2->at(jjj, iii).intensity = 2.f;
          }
        }

        vis.removeAllPointClouds();

        pcl::visualization::PointCloudColorHandlerGenericField < pcl::PointXYZI > handler(cloud_intensity2, "intensity");
        vis.addPointCloud(cloud_intensity2, handler, "cloud");
        vis.spinOnce();
        vis.spin();
        sleep(1);
#endif
      }

      if (neg_extracted != N_patches)
      {
        std::cout << "Extracted " << neg_extracted << " negative patches" << std::endl;
        std::cout << files[j] << std::endl;
      }

      if (pos_extracted != N_patches)
      {
        std::cout << "Extracted " << pos_extracted << " positive patches" << std::endl;
        std::cout << files[j] << std::endl;
      }
    }
  }

  std::cout << training_examples.size () << " " << labels.size () << " " << total_neg << " " << total_pos << std::endl;

  //train random forest and make persistent
  std::vector<int> example_indices;
  for (size_t i = 0; i < labels.size (); i++)
    example_indices.push_back (static_cast<int> (i));

  label_data = labels;
  data_set = training_examples;
  examples = example_indices;
}
Ejemplo n.º 7
0
int main(int argc, char **argv){
  double *a;
  double *b;
  double temp;
  int initID = 0;
  int n=0;
  //int res;
  char *name;
  clock_t t;
  double time=0.;
  FILE *input;
    
  if (argc==2){
    if ( !(n = atoi(argv[1]))){
      printf("This is not a moon!\nI need numberz!\n");
      return -4;
    }
    //n = atoi(argv[1]);
    //m = atoi(argv[2]);
    a = new double[n*n];
    if (a==NULL){
      printf("Failed to allocate memory for matrix A\n");
      return -2;
    }
    defineMatrixWithFunction(a, n);
    initID=1;
  }
  else if (argc==3){
    if ( !(n = atoi(argv[2]))){
      printf("This is not a moon!\n");
      return -4;
    }
    name = argv[1];
    //n = atoi(argv[2]);
    //m = atoi(argv[3]);
    int size = n*n;
    a = new double[size];
    if (a==NULL){
      printf("Failed to allocate memory for matrix A\n");
      return -2;
    }
    input = fopen(name, "r");
    readMatrixFromFile(input, a, n);
    fclose(input);
    initID=2;
  }
  else{
    printf("Usage:\n %s n\n %s file_name n\n", argv[0], argv[0]);
    return -1;
  }
  if (initID==0){
    printf("Failed to initialize matrix\n");
    delete[] a;
    return -1;
  }
  b = new double[n];
  //printMatrix(a, n, n);

  //temp = someInvariant_ii(a, n);
  //printf("Sum before step 1:%.2lf\n", temp);
  t = clock();
  qrAlmostUpperTriangle(a, n);
  //printMatrix(a, n, n);
  temp = traceMatrix(a, n);
  printf("Trace after step 1:%.2lf\n", temp);
  //temp = someInvariant_ii(a, n);
  //printf("Sum after step 1:%.2lf\n", temp);
  searchEigenValues(a, b, n);
  printMatrix(a, n, n);
  temp = traceMatrix(a, n);
  printf("Trace after step 2:%.2lf\n", temp);
  time = (clock()-t)/(double)(CLOCKS_PER_SEC);
  printf("Total time:\n%.2lf sec\n", time);
  for (int i=0; i<n; i++){
    printf("Value %d: %.4lf\n", i, b[i]);
  }
  delete[] a;
  delete[] b;
  return 0;
}
Ejemplo n.º 8
0
Matrix::Matrix(std::string name)
{
	//readFromFile(name);
	readMatrixFromFile(name);
}