MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
bundler_intrinsics.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
12
15
16void
17Intrinsics::compute (mve::Scene::Ptr scene, ViewportList* viewports)
18{
19 if (scene == nullptr)
20 throw std::invalid_argument("Null scene given");
21 if (viewports == nullptr)
22 throw std::invalid_argument("No viewports given");
23 if (viewports->size() != scene->get_views().size())
24 throw std::invalid_argument("Viewports/scene size mismatch");
25
26 mve::Scene::ViewList const& views = scene->get_views();
27 for (std::size_t i = 0; i < views.size(); ++i)
28 {
29 if (views[i] == nullptr)
30 continue;
31
32 switch (this->opts.intrinsics_source)
33 {
34 case FROM_EXIF:
35 this->init_from_exif(views[i], &viewports->at(i));
36 break;
37 case FROM_VIEWS:
38 this->init_from_views(views[i], &viewports->at(i));
39 break;
40 default:
41 throw std::invalid_argument("Invalid intrinsics source");
42 }
43 }
44
45 /* Print unknown camera models. */
46 if (!this->unknown_cameras.empty())
47 {
48 std::cout << "Camera models not in database:" << std::endl;
49 for (auto item : this->unknown_cameras)
50 std::cout << " " << item.first << ": " << item.second << std::endl;
51 }
52}
53
54void
55Intrinsics::init_from_exif (mve::View::Ptr view, Viewport* viewport)
56{
57 /* Try to get EXIF data. */
58 if (this->opts.exif_embedding.empty())
59 {
60 std::cout << "Warning: No EXIF information for view "
61 << view->get_id() << ", using fallback!" << std::endl;
62 this->fallback_focal_length(viewport);
63 return;
64 }
65
66 mve::ByteImage::Ptr exif_data = view->get_blob(this->opts.exif_embedding);
67 if (exif_data == nullptr)
68 {
69 std::cout << "Warning: No EXIF embedding for view "
70 << view->get_id() << ", using fallback!" << std::endl;
71 this->fallback_focal_length(viewport);
72 return;
73 }
74
76 FocalLengthEstimate estimate;
77 try
78 {
79 exif = mve::image::exif_extract(exif_data->get_byte_pointer(),
80 exif_data->get_byte_size(), false);
81 estimate = sfm::extract_focal_length(exif);
82 viewport->focal_length = estimate.first;
83 }
84 catch (std::exception& e)
85 {
86 std::cout << "Warning: " << e.what() << std::endl;
88 }
89
90 /* Print warning in case extraction failed. */
91 if (estimate.second == FOCAL_LENGTH_FALLBACK_VALUE)
92 {
93 std::cout << "Warning: Using fallback focal length for view "
94 << view->get_id() << "." << std::endl;
95 if (!exif.camera_maker.empty() && !exif.camera_model.empty())
96 {
97 std::cout << " Maker: " << exif.camera_maker
98 << ", Model: " << exif.camera_model << std::endl;
99
100 std::string key = exif.camera_maker + " " + exif.camera_model;
101 this->unknown_cameras[key] += 1;
102 }
103 }
104}
105
106void
107Intrinsics::init_from_views (mve::View::Ptr view, Viewport* viewport)
108{
109 mve::CameraInfo const& camera = view->get_camera();
110 if (camera.flen == 0.0f)
111 {
112 std::cout << "Warning: View " << view->get_id()
113 << " has zero focal length. Using fallback." << std::endl;
114 this->fallback_focal_length(viewport);
115 return;
116 }
117
118 /* Sets the focal length, radial distortion and principal point from the view. */
119 viewport->focal_length = camera.flen;
120 viewport->radial_distortion[0] = camera.dist[0];
121 viewport->radial_distortion[1] = camera.dist[1];
122 viewport->principal_point[0] = camera.ppoint[0];
123 viewport->principal_point[1] = camera.ppoint[1];
124}
125
126void
127Intrinsics::fallback_focal_length (Viewport* viewport)
128{
131 viewport->focal_length = estimate.first;
132}
133
std::shared_ptr< Image< T > > Ptr
Definition image.h:42
std::shared_ptr< Scene > Ptr
Definition scene.h:37
std::vector< View::Ptr > ViewList
Definition scene.h:38
std::shared_ptr< View > Ptr
Definition view.h:68
ExifInfo exif_extract(char const *data, std::size_t len, bool is_jpeg)
Function to extract a (selected) EXIF tags from binary data.
std::vector< Viewport > ViewportList
The list of all viewports considered for bundling.
std::pair< float, FocalLengthMethod > FocalLengthEstimate
Datatype for the focal length estimate which reports the normalized focal length as well as the metho...
std::pair< float, FocalLengthMethod > extract_focal_length(mve::image::ExifInfo const &exif)
Extracts the focal length from the EXIF tags of an image.
#define SFM_BUNDLER_NAMESPACE_END
Definition defines.h:17
#define SFM_BUNDLER_NAMESPACE_BEGIN
Definition defines.h:16
#define SFM_NAMESPACE_END
Definition defines.h:14
#define SFM_NAMESPACE_BEGIN
Definition defines.h:13
Per-view camera information with various helper functions.
Definition camera.h:24
float ppoint[2]
Principal point in x- and y-direction.
Definition camera.h:158
float flen
Focal length.
Definition camera.h:156
float dist[2]
Image distortion parameters.
Definition camera.h:162
EXIF information.
Definition image_exif.h:32
std::string camera_maker
Camera manufacturer.
Definition image_exif.h:36
std::string camera_model
Camera model.
Definition image_exif.h:38
Per-viewport information.
float focal_length
Initial focal length estimate for the image.