Skip to content

Commit

Permalink
[software] SfMInit_ImageListing (Deal with images with empty Brand/Mo…
Browse files Browse the repository at this point in the history
…del field, group option is working fine with View with unknown intrinsic Ids). #336
  • Loading branch information
pmoulon committed Jul 8, 2015
1 parent bc940bb commit 6577eed
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 59 deletions.
90 changes: 48 additions & 42 deletions src/openMVG/exif/exif_IO_EasyExif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Exif_IO_EasyExif : public Exif_IO
{
// Read the file into a buffer
FILE *fp = fopen(sFileName.c_str(), "rb");
if (!fp) {
return false;
if (!fp) {
return false;
}
fseek(fp, 0, SEEK_END);
unsigned long fsize = ftell(fp);
Expand All @@ -45,7 +45,7 @@ class Exif_IO_EasyExif : public Exif_IO
bHaveExifInfo_ = false;
else
bHaveExifInfo_ = true;

return bHaveExifInfo_;
}

Expand All @@ -67,18 +67,24 @@ class Exif_IO_EasyExif : public Exif_IO
std::string getBrand() const
{
std::string sbrand = exifInfo_.Make;
// remove leading and trailing spaces
sbrand.erase(0, sbrand.find_first_not_of(' '));
sbrand.erase(sbrand.find_last_not_of(' '));
if (!sbrand.empty())
{
// remove leading and trailing spaces
sbrand.erase(0, sbrand.find_first_not_of(' '));
sbrand.erase(sbrand.find_last_not_of(' '));
}
return sbrand;
}

std::string getModel() const
{
std::string smodel = exifInfo_.Model;
// remove leading and trailing spaces
smodel.erase(0, smodel.find_first_not_of(' '));
smodel.erase(smodel.find_last_not_of(' '));
if (!smodel.empty())
{
// remove leading and trailing spaces
smodel.erase(0, smodel.find_first_not_of(' '));
smodel.erase(smodel.find_last_not_of(' '));
}
return smodel;
}

Expand All @@ -98,41 +104,41 @@ class Exif_IO_EasyExif : public Exif_IO
{
std::ostringstream os;
os
<< "Camera make : " << exifInfo_.Make
<< "Camera model : " << exifInfo_.Model
<< "Software : " << exifInfo_.Software
<< "Bits per sample : " << exifInfo_.BitsPerSample
<< "Image width : " << exifInfo_.ImageWidth
<< "Image height : " << exifInfo_.ImageHeight
<< "Image description : " << exifInfo_.ImageDescription
<< "Image orientation : " << exifInfo_.Orientation
<< "Image copyright : " << exifInfo_.Copyright
<< "Image date/time : " << exifInfo_.DateTime
<< "Original date/time: " << exifInfo_.DateTimeOriginal
<< "Digitize date/time: " << exifInfo_.DateTimeDigitized
<< "Subsecond time : " << exifInfo_.SubSecTimeOriginal
<< "Exposure time : 1/time " << (unsigned) (1.0/exifInfo_.ExposureTime)
<< "F-stop : " << exifInfo_.FNumber
<< "ISO speed : " << exifInfo_.ISOSpeedRatings
<< "Subject distance : " << exifInfo_.SubjectDistance
<< "Exposure bias : EV" << exifInfo_.ExposureBiasValue
<< "Flash used? : " << exifInfo_.Flash
<< "Metering mode : " << exifInfo_.MeteringMode
<< "Lens focal length : mm\n" << exifInfo_.FocalLength
<< "35mm focal length : mm\n" << exifInfo_.FocalLengthIn35mm
<< "Camera make : " << exifInfo_.Make << "\n"
<< "Camera model : " << exifInfo_.Model << "\n"
<< "Software : " << exifInfo_.Software << "\n"
<< "Bits per sample : " << exifInfo_.BitsPerSample << "\n"
<< "Image width : " << exifInfo_.ImageWidth << "\n"
<< "Image height : " << exifInfo_.ImageHeight << "\n"
<< "Image description : " << exifInfo_.ImageDescription << "\n"
<< "Image orientation : " << exifInfo_.Orientation << "\n"
<< "Image copyright : " << exifInfo_.Copyright << "\n"
<< "Image date/time : " << exifInfo_.DateTime << "\n"
<< "Original date/time: " << exifInfo_.DateTimeOriginal << "\n"
<< "Digitize date/time: " << exifInfo_.DateTimeDigitized << "\n"
<< "Subsecond time : " << exifInfo_.SubSecTimeOriginal << "\n"
<< "Exposure time : 1/time " << (unsigned) (1.0/exifInfo_.ExposureTime) << "\n"
<< "F-stop : " << exifInfo_.FNumber << "\n"
<< "ISO speed : " << exifInfo_.ISOSpeedRatings << "\n"
<< "Subject distance : " << exifInfo_.SubjectDistance << "\n"
<< "Exposure bias : EV" << exifInfo_.ExposureBiasValue << "\n"
<< "Flash used? : " << exifInfo_.Flash << "\n"
<< "Metering mode : " << exifInfo_.MeteringMode << "\n"
<< "Lens focal length : mm\n" << exifInfo_.FocalLength << "\n"
<< "35mm focal length : mm\n" << exifInfo_.FocalLengthIn35mm << "\n"
<< "GPS Latitude : deg ( deg, min, sec )\n" << "("
<< exifInfo_.GeoLocation.Latitude << ", "
<< exifInfo_.GeoLocation.LatComponents.degrees << ", "
<< exifInfo_.GeoLocation.LatComponents.minutes << ", "
<< exifInfo_.GeoLocation.LatComponents.seconds << ", "
<< exifInfo_.GeoLocation.LatComponents.direction << ")"
<< exifInfo_.GeoLocation.Latitude << ", "
<< exifInfo_.GeoLocation.LatComponents.degrees << ", "
<< exifInfo_.GeoLocation.LatComponents.minutes << ", "
<< exifInfo_.GeoLocation.LatComponents.seconds << ", "
<< exifInfo_.GeoLocation.LatComponents.direction << ")" << "\n"
<< "GPS Longitude : deg ( deg, min, sec )\n" << "("
<< exifInfo_.GeoLocation.Longitude << ", "
<< exifInfo_.GeoLocation.LonComponents.degrees << ", "
<< exifInfo_.GeoLocation.LonComponents.minutes << ", "
<< exifInfo_.GeoLocation.LonComponents.seconds << ", "
<< exifInfo_.GeoLocation.LonComponents.direction << ")"
<< "GPS Altitude : m" << exifInfo_.GeoLocation.Altitude;
<< exifInfo_.GeoLocation.Longitude << ", "
<< exifInfo_.GeoLocation.LonComponents.degrees << ", "
<< exifInfo_.GeoLocation.LonComponents.minutes << ", "
<< exifInfo_.GeoLocation.LonComponents.seconds << ", "
<< exifInfo_.GeoLocation.LonComponents.direction << ")" << "\n"
<< "GPS Altitude : m" << exifInfo_.GeoLocation.Altitude << "\n";
return os.str();
}

Expand Down
42 changes: 25 additions & 17 deletions src/software/SfM/main_SfMInit_ImageListing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ int main(int argc, char **argv)

bool b_Group_camera_model = true;

double focalPixPermm = -1.0;
double focal_pixels = -1.0;

cmd.add( make_option('i', sImageDir, "imageDirectory") );
cmd.add( make_option('d', sfileDatabase, "sensorWidthDatabase") );
cmd.add( make_option('o', sOutputDir, "outputDirectory") );
cmd.add( make_option('f', focalPixPermm, "focal") );
cmd.add( make_option('f', focal_pixels, "focal") );
cmd.add( make_option('k', sKmatrix, "intrinsics") );
cmd.add( make_option('c', i_User_camera_model, "camera_model") );
cmd.add( make_option('g', b_Group_camera_model, "group_camera_model") );
Expand Down Expand Up @@ -109,7 +109,7 @@ int main(int argc, char **argv)
<< "--imageDirectory " << sImageDir << std::endl
<< "--sensorWidthDatabase " << sfileDatabase << std::endl
<< "--outputDirectory " << sOutputDir << std::endl
<< "--focal " << focalPixPermm << std::endl
<< "--focal " << focal_pixels << std::endl
<< "--intrinsics " << sKmatrix << std::endl
<< "--camera_model " << i_User_camera_model << std::endl
<< "--group_camera_model " << b_Group_camera_model << std::endl;
Expand Down Expand Up @@ -147,7 +147,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}

if (sKmatrix.size() > 0 && focalPixPermm != -1.0)
if (sKmatrix.size() > 0 && focal_pixels != -1.0)
{
std::cerr << "\nCannot combine -f and -k options" << std::endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -193,21 +193,26 @@ int main(int argc, char **argv)
height = imgHeader.height;
ppx = width / 2.0;
ppy = height / 2.0;

std::unique_ptr<Exif_IO> exifReader(new Exif_IO_EasyExif());
exifReader->open( sImageFilename );

// Consider the case where focal is provided manually
if ( !exifReader->doesHaveExifInfo() || focalPixPermm != -1)
const bool bHaveValidExifMetadata =
exifReader->doesHaveExifInfo()
&& !exifReader->getBrand().empty()
&& !exifReader->getModel().empty();

// Consider the case where the focal is provided manually
if ( !bHaveValidExifMetadata || focal_pixels != -1)
{
if (sKmatrix.size() > 0) // Known user calibration K matrix
{
if (!checkIntrinsicStringValidity(sKmatrix, focal, ppx, ppy))
focal = -1.0;
}
else // User provided focal lenght value
if (focalPixPermm != -1 )
focal = focalPixPermm;
else // User provided focal length value
if (focal_pixels != -1 )
focal = focal_pixels;
}
else // If image contains meta data
{
Expand Down Expand Up @@ -276,7 +281,7 @@ int main(int argc, char **argv)
}
else
{
// Add the intrinsic to the sfm_container
// Add the defined intrinsic to the sfm_container
intrinsics[v.id_intrinsic] = intrinsic;
}

Expand Down Expand Up @@ -334,17 +339,20 @@ int main(int argc, char **argv)
++iterView)
{
View * v = iterView->second.get();
v->id_intrinsic = old_new_reindex[v->id_intrinsic];
// Update the Id only if a corresponding index exists
if (old_new_reindex.count(v->id_intrinsic))
v->id_intrinsic = old_new_reindex[v->id_intrinsic];
}
}

// Store SfM_Data views & intrinsic data
if (Save(
if (!Save(
sfm_data,
stlplus::create_filespec( sOutputDir, "sfm_data.json" ).c_str(),
ESfM_Data(VIEWS|INTRINSICS))
)
ESfM_Data(VIEWS|INTRINSICS)))
{
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}

0 comments on commit 6577eed

Please sign in to comment.