mve
mve copied to clipboard
mve fails on filenames with spaces
Hi! I'm running the active version of mve in the ODM docker container.
From this, I have an intermediate nvm file with a set of images generated through ODM wherein the filenames contain spaces.
When mve attempts to load this file, it introduces an error on https://github.com/simonfuhrmann/mve/blob/2106a5b0aef61a7f744551510b1b4c5d8e3be594/libs/mve/bundle_io.cc#L112 where the filename is interpreted as ending on the first space, then gobbling up and turning the remainder of the nvm file into garbage. We can handle this case by some trial and error handling in bundle_io at the above location:
//Gobble up any leading whitespace
in >> std::ws;
//Read a full line of camera details
std::string camline = std::getline(in, camline);
std::istringstream line(camline);
//Read out parts of the filename until we find an actual file
line >> nvm_cam.filename;
while(!std::ifstream(nvm_cam.filename)) {
std::string tmp;
line >> tmp;
nvm_cam.filename += " " + tmp;
if(!line) break;
}
if(!line) {
//We've gobbled up the whole camera line searching for a missing file, so skip it.
//Since later data may be dependent on the camera ordering however,
//we still push the invalid camera and parameter bundle. There may be other ways
//to handle this.
nvm_cam.filename = "<invalid camera, file not found: '" + nvm_cam.filename + "'>";
bundle_cams.push_back(bundle_cam); nvm_cams.push_back(nvm_cam);
continue;
}
//Replace remaining uses of 'in' within the loop with 'line'
With this, mve should be able to handle this weakness in the nvm file format without breaking otherwise correct files nor fail disastrously on missing camera files.
To fully avoid any inconsistencies (given that nvm doesn't have any escape characters), we would have to go one step further and parse a camera line in reverse, extracting each numeric token and then interpreting the remainder as a file name. I think this may be overkill though.
Thanks for reporting, I will take a closer look.