in source/rig/RigAnalyzer.cpp [375:437]
void saveEquirect(const std::string& filename, const Camera::Rig& rig) {
const int kPixelsPerDegree = 5;
const int kDimX = 360 * kPixelsPerDegree;
const int kDimY = 180 * kPixelsPerDegree;
std::ofstream file(filename, std::ios::binary);
file << "P2" << std::endl;
file << kDimX << " " << kDimY << std::endl;
if (FLAGS_show_timing) {
file << 256 << std::endl;
} else {
file << rig.size() << std::endl;
}
double holes = 0;
double maxMin = 0;
double aveMin = 0;
for (int y = 0; y < kDimY; ++y) {
// latitude goes from pi/2 down to -pi/2
Camera::Real lat = M_PI / 2 - (y + 0.5) / kDimY * M_PI;
for (int x = 0; x < kDimX; ++x) {
// lon goes from -pi up to pi
Camera::Real lon = -M_PI + (x + 0.5) / kDimX * 2 * M_PI;
Camera::Vector3 direction(cos(lat) * cos(lon), cos(lat) * sin(lon), sin(lat));
std::vector<float> timing(rig.size());
int count = 0;
for (const Camera& camera : rig) {
Camera::Vector2 p;
if (camera.sees(direction * FLAGS_overlap_distance, p)) {
// Normalized timing distance assuming all the cameras'
// pixel clocks are synced and single line activated/reset rolling
// shutter.
timing[count] = p.y() / camera.resolution.y();
// Count this camera
++count;
}
}
double minTimingDiff = 1.0;
double maxTimingDiff = 0.0;
for (int i = 0; i < count; ++i) {
for (int j = i + 1; j < count; ++j) {
const double timingDiff = std::abs(timing[i] - timing[j]);
minTimingDiff = std::min(minTimingDiff, timingDiff);
maxTimingDiff = std::max(maxTimingDiff, timingDiff);
}
}
maxMin = std::max(maxMin, minTimingDiff);
aveMin += minTimingDiff;
if (FLAGS_show_timing) {
const int timeWeightedCount = int((1.0 - minTimingDiff) * 255.0);
file << timeWeightedCount << " ";
} else {
file << count << " ";
}
holes += (0 == count) ? 1 : 0;
}
file << std::endl;
}
const float kFrameRate = 60.0f; // 60 fps
const float kFrameTime = 1000.0f / kFrameRate; // in milliseconds
LOG(INFO) << "Holes found (in pixels) = " << holes;
LOG(INFO) << "Max of min timing distance = " << kFrameTime * maxMin << "ms";
LOG(INFO) << "Ave of min timing distance = " << kFrameTime * aveMin / (kDimX * kDimY) << "ms";
}