MCPcopy Create free account
hub / github.com/city-super/Octree-GS / colmapSave

Function colmapSave

SIBR_viewers/src/core/scene/ParseData.cpp:317–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315 }
316
317 void colmapSave(const std::string& filename, const std::vector<InputCamera::Ptr>& xformPath, float scale) {
318 // save as colmap images.txt file
319 sibr::Matrix3f converter;
320 converter << 1, 0, 0,
321 0, -1, 0,
322 0, 0, -1;
323
324 std::ofstream outputColmapPath, outputColmapPathCams;
325 std::string colmapPathCams = parentDirectory(filename) + std::string("/cameras.txt");
326
327 std::cerr << std::endl;
328 std::cerr << std::endl;
329 std::cerr << "Writing colmap path to " << parentDirectory(filename) << std::endl;
330
331 outputColmapPath.open(filename);
332 if (!outputColmapPath.good())
333 SIBR_ERR << "Cant open output file " << filename << std::endl;
334 outputColmapPathCams.open(colmapPathCams);
335
336 outputColmapPathCams << "# Camera list with one line of data per camera:" << std::endl;
337 outputColmapPathCams << "# CAMERA_ID, MODEL, WIDTH, HEIGHT, PARAMS[]" << std::endl;
338 outputColmapPathCams << "# Number of cameras: " << xformPath.size() << std::endl;
339
340 SIBR_WRG << "No focal x given making it equal to focaly * aspect ratio; use result at own risk. Should have a colmap dataset as input" << std::endl;
341
342 for (int i = 0; i < xformPath.size(); i++) {
343 float focalx = xformPath[i]->focal() * xformPath[i]->aspect(); // use aspect ratio
344 outputColmapPathCams << i + 1 << " PINHOLE " << xformPath[i]->w() * scale << " " << xformPath[i]->h() * scale
345 << " " << xformPath[i]->focal() * scale << " " << focalx * scale
346 << " " << xformPath[i]->w() * scale * 0.5 << " " << xformPath[i]->h() * scale * 0.5 << std::endl;
347 }
348
349
350 outputColmapPath << "# Image list with two lines of data per image:" << std::endl;
351 outputColmapPath << "# IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME" << std::endl;
352 outputColmapPath << "# POINTS2D[] as (X, Y, POINT3D_ID)" << std::endl;
353 for (int i = 0; i < xformPath.size(); i++) {
354 sibr::Matrix3f tmp = xformPath[i]->rotation().toRotationMatrix() * converter;
355 sibr::Matrix3f Qinv = tmp.transpose();
356 sibr::Quaternionf q = quatFromMatrix(Qinv);
357 sibr::Vector3f t = -Qinv * xformPath[i]->position();
358
359 outputColmapPath << (i + 1) << " " << q.w() << " " << -q.x() << " " << -q.y() << " " << -q.z() << " " <<
360 t.x() << " " << t.y() << " " << t.z() << " " << (i + 1) << " " << xformPath[i]->name() << std::endl;
361 outputColmapPath << std::endl; // empty line, no points
362 }
363 outputColmapPath.close();
364 outputColmapPathCams.close();
365 }
366
367 void ParseData::getParsedChunkedData(const std::string& dataset_path)
368 {

Callers 1

getParsedChunkedDataMethod · 0.70

Calls 11

parentDirectoryFunction · 0.85
quatFromMatrixFunction · 0.85
focalMethod · 0.80
aspectMethod · 0.80
sizeMethod · 0.45
wMethod · 0.45
hMethod · 0.45
rotationMethod · 0.45
positionMethod · 0.45
nameMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected