RTMV scene format: http://www.cs.umd.edu/~mmeshry/projects/rtmv |--sceneX |--images |--xxx.jpg |--xxx.jpg .... |--outputs (optional) |--depthxxxx.exr |--normalxxxx.exr .... |--transforms.json
| 360 | // .... |
| 361 | // |--transforms.json |
| 362 | bool ParseSceneNerfstudio(Scene& scene, const String& strPath) |
| 363 | { |
| 364 | const nlohmann::json data = nlohmann::json::parse(std::ifstream(strPath + NERFSTUDIO_TRANSFORMS)); |
| 365 | if (data.empty()) |
| 366 | return false; |
| 367 | // parse camera |
| 368 | const cv::Size resolution(data["w"].get<uint32_t>(), data["h"].get<uint32_t>()); |
| 369 | const IIndex platformID = scene.platforms.size(); |
| 370 | Platform& platform = scene.platforms.emplace_back(); |
| 371 | Platform::Camera& camera = platform.cameras.emplace_back(); |
| 372 | camera.K = KMatrix::IDENTITY; |
| 373 | camera.R = RMatrix::IDENTITY; |
| 374 | camera.C = CMatrix::ZERO; |
| 375 | camera.K(0,0) = data["fl_x"].get<REAL>(); |
| 376 | camera.K(1,1) = data["fl_y"].get<REAL>(); |
| 377 | camera.K(0,2) = data["cx"].get<REAL>(); |
| 378 | camera.K(1,2) = data["cy"].get<REAL>(); |
| 379 | const String cameraModel = data["camera_model"].get<std::string>(); |
| 380 | if (cameraModel == "SIMPLE_PINHOLE") { |
| 381 | } else |
| 382 | // check ZERO radial distortion for all "PERSPECTIVE" type cameras |
| 383 | if (cameraModel == "PINHOLE" || cameraModel == "SIMPLE_RADIAL" || cameraModel == "RADIAL" || cameraModel == "OPENCV") { |
| 384 | const REAL k1 = data["k1"].get<REAL>(); |
| 385 | const REAL k2 = data["k2"].get<REAL>(); |
| 386 | const REAL p1 = data["p1"].get<REAL>(); |
| 387 | const REAL p2 = data["p2"].get<REAL>(); |
| 388 | if (k1 != 0 || k2 != 0 || p1 != 0 || p2 != 0) { |
| 389 | VERBOSE("error: radial distortion not supported"); |
| 390 | return false; |
| 391 | } |
| 392 | } else { |
| 393 | VERBOSE("error: camera model not supported"); |
| 394 | return false; |
| 395 | } |
| 396 | // parse images |
| 397 | const nlohmann::json& frames = data["frames"]; |
| 398 | for (const nlohmann::json& frame: frames) { |
| 399 | // set image |
| 400 | // frames expected to be ordered in JSON |
| 401 | const IIndex imageID = scene.images.size(); |
| 402 | const String strFileName(strPath + frame["file_path"].get<std::string>().c_str()); |
| 403 | Image& imageData = scene.images.emplace_back(); |
| 404 | imageData.platformID = platformID; |
| 405 | imageData.cameraID = 0; // only one camera per platform supported by this format |
| 406 | imageData.poseID = NO_ID; |
| 407 | imageData.ID = imageID; |
| 408 | imageData.name = strFileName; |
| 409 | ASSERT(Util::isFullPath(imageData.name)); |
| 410 | // set image resolution |
| 411 | imageData.width = resolution.width; |
| 412 | imageData.height = resolution.height; |
| 413 | imageData.scale = 1; |
| 414 | // load camera pose |
| 415 | imageData.poseID = platform.poses.size(); |
| 416 | Platform::Pose& pose = platform.poses.emplace_back(); |
| 417 | const auto Ps = frame["transform_matrix"].get<std::vector<std::vector<double>>>(); |
| 418 | Eigen::Matrix4d P{ |
| 419 | {Ps[0][0], Ps[0][1], Ps[0][2], Ps[0][3]}, |
no test coverage detected