Blender V4.3
reconstruction_scale.cc
Go to the documentation of this file.
1// Copyright (c) 2013 libmv authors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to
5// deal in the Software without restriction, including without limitation the
6// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7// sell copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19// IN THE SOFTWARE.
20
23
24namespace libmv {
25
29
30 // Calculate center of the mass of all cameras.
31 Vec3 cameras_mass_center = Vec3::Zero();
32 for (int i = 0; i < all_cameras.size(); ++i) {
33 cameras_mass_center += all_cameras[i].t;
34 }
35 cameras_mass_center /= all_cameras.size();
36
37 // Find the most distant camera from the mass center.
38 double max_distance = 0.0;
39 for (int i = 0; i < all_cameras.size(); ++i) {
40 double distance = (all_cameras[i].t - cameras_mass_center).squaredNorm();
41 if (distance > max_distance) {
42 max_distance = distance;
43 }
44 }
45
46 if (max_distance == 0.0) {
47 LG << "Cameras position variance is too small, cannot rescale";
48 return;
49 }
50
51 double scale_factor = 1.0 / sqrt(max_distance);
52
53 // Rescale cameras positions.
54 for (int i = 0; i < all_cameras.size(); ++i) {
55 int image = all_cameras[i].image;
57 camera->t = camera->t * scale_factor;
58 }
59
60 // Rescale points positions.
61 for (int i = 0; i < all_points.size(); ++i) {
62 int track = all_points[i].track;
64 point->X = point->X * scale_factor;
65 }
66}
67
68} // namespace libmv
sqrt(x)+1/max(0
vector< ProjectivePoint > AllPoints() const
Returns all points.
vector< ProjectiveCamera > AllCameras() const
Returns all cameras.
ProjectivePoint * PointForTrack(int track)
Returns a pointer to the point corresponding to track.
ProjectiveCamera * CameraForImage(int image)
Returns a pointer to the camera corresponding to image.
const ProjectiveReconstruction & reconstruction
Definition intersect.cc:198
#define LG
void EuclideanScaleToUnity(EuclideanReconstruction *reconstruction)
Eigen::Vector3d Vec3
Definition numeric.h:106
float distance(float a, float b)