void display()

in source/render/ComputeRephotographyErrors.cpp [102:191]


  void display() override {
    // Create output directories
    const filesystem::path rephotoDir = filesystem::path(FLAGS_output) / "rephoto";
    for (const Camera& cam : rig) {
      filesystem::create_directories(rephotoDir / cam.id);
    }

    cv::Scalar totalScore = cv::Scalar::all(0);
    const int numFrames = std::stoi(FLAGS_last) - std::stoi(FLAGS_first) + 1;
    CHECK_GT(numFrames, 0);

    for (int iFrame = 0; iFrame < numFrames; ++iFrame) {
      const std::string frameName =
          image_util::intToStringZeroPad(iFrame + std::stoi(FLAGS_first), 6);
      LOG(INFO) << folly::sformat("Processing frame {}...", frameName);

      LOG(INFO) << "Loading color and disparity images...";

      std::vector<cv::Mat_<float>> disps = loadPfmImages(FLAGS_disparity, rig, frameName);
      CHECK_EQ(rig.size(), disps.size());

      // Need to scale to m to match convention
      const std::vector<cv::Mat_<PixelType>> colors = loadResizedImages<PixelType>(
          FLAGS_color, rig, frameName, disps[0].size(), cv::INTER_AREA);
      CHECK_EQ(colors.size(), disps.size());

      const int cubeHeight = colors[0].rows;
      cv::Scalar frameScore = cv::Scalar::all(0);
      std::vector<std::string> cameras;
      if (!FLAGS_cameras.empty()) {
        boost::split(cameras, FLAGS_cameras, [](char c) { return c == ','; });
      }
      for (ssize_t i = 0; i < ssize(rig); ++i) {
        const std::string camId = rig[i].id;
        if (cameras.size() > 0) {
          if (std::find(cameras.begin(), cameras.end(), camId) == cameras.end()) {
            continue;
          }
        }

        LOG(INFO) << folly::sformat("Processing {} - {}...", frameName, camId);
        const Eigen::Vector3f center = rig[i].position.cast<float>();

        std::vector<cv::Mat_<PixelType>> cubesRef =
            generateCubemaps({rig[i]}, {colors[i]}, {disps[i]}, cubeHeight, center);
        std::vector<cv::Mat_<PixelType>> cubesRender = generateCubemaps(
            removeOne(i, rig), removeOne(i, colors), removeOne(i, disps), cubeHeight, center);

        // Create mask
        const int kColor = 0;
        const cv::Mat_<float> alpha = cv_util::extractAlpha(cubesRef[kColor]);
        const cv::Mat_<uint8_t> mask = 255 * (alpha > 0);

        // Remove color alphas
        cv::Mat_<PixelTypeNoAlpha> cubesRefColorNoAlpha = cv_util::removeAlpha(cubesRef[kColor]);
        cv::Mat_<PixelTypeNoAlpha> cubesRenderColorNoAlpha =
            cv_util::removeAlpha(cubesRender[kColor]);

        // Compute scores
        const cv::Mat_<PixelTypeNoAlpha> scoreMap = rephoto_util::computeScoreMap(
            FLAGS_method, cubesRefColorNoAlpha, cubesRenderColorNoAlpha, FLAGS_stat_radius);

        const cv::Scalar avgScore = rephoto_util::averageScore(scoreMap, mask);
        LOG(INFO) << folly::sformat(
            "{} {}: {}", camId, FLAGS_method, rephoto_util::formatResults(avgScore));
        frameScore += avgScore;

        // Plot results
        const cv::Mat_<cv::Vec3b> plot =
            rephoto_util::stackResults(cubesRef, cubesRender, scoreMap, avgScore, mask);
        const std::string filename =
            folly::sformat("{}/{}/{}.png", rephotoDir.string(), camId, frameName);
        cv_util::imwriteExceptionOnFail(filename, plot);
      }

      const int n = cameras.size() > 0 ? cameras.size() : rig.size();
      frameScore.val[0] /= n;
      frameScore.val[1] /= n;
      frameScore.val[2] /= n;
      LOG(INFO) << folly::sformat(
          "{} average {}: {}", frameName, FLAGS_method, rephoto_util::formatResults(frameScore));
      totalScore += frameScore;
    }

    totalScore.val[0] /= numFrames;
    totalScore.val[1] /= numFrames;
    totalScore.val[2] /= numFrames;
    LOG(INFO) << folly::sformat(
        "TOTAL average {}: {}", FLAGS_method, rephoto_util::formatResults(totalScore));
  }