Permalink
Switch branches/tags
BendyBones GPU_data_request GPencil_EditStrokes GPencil_Editing_Stage3 GPencil_FillStrokes HMD_viewport KTX_support PSketch UI-experiments UI-graphical-redesign alembic_pointcache alembic animsys2 apricot asset-engine asset-experiments bake-cycles benchmark bge_components blender-tiles blender-v2.79-release blender-v2.79a-release blender-v2.79b-release blender2.4 blender2.5 blender2.8-workbench blender2.8_snap_gizmo blender2.8 bmesh clay-engine cloth-improvements cloth collada-2 collada collada2.8 compositor-2016 custom-manipulators custom-normals-bmesh cycles-ptex-49 cycles-tiles-rework cycles_bvh8 cycles_camera_nodes cycles_cryptomatte cycles_disney_brdf cycles_disney_bsdf_transmittance cycles_embree cycles_panorama_experiments cycles_refactor cycles_split_kernel cycles_texture_cache cycles datablock_idprops decklink depsgraph_refactor dyntopo_holes epic-navigation etch-a-ton experimental-build experimental_gp_weight fcurves-simplify fluid-mantaflow fluidcontrol fracture_modifier-master fracture_modifier free-refcount-ids ge_dev ge_dome ge_eigen2 ge_2df_textures gooseberry_farm gooseberry greasepencil-object gsoc-2018-many-light-sampling gsoc2016-improved_extrusion gtest-staging hair_guides_grooming hair_guides hair_object harmonic-skeleton id_copy_refactor id_override_static input_method_editor interactive_physics layer-manager layers libmv_prediction master merwin-spacenav meshdata_transfer missing-libs modern-nle modern-vse2.8 motion_curve_fix multi_previews_id multiview ndof object_nodes openvdb orange overscan particles_refactor pbr-viewport pie-menus projection-paint readfile_doversions_after_linking render-layers render25 sculpt25 sim_physics smoke2 smooth-fcurves snap_system_clip_planes soc-2008-jaguarandi soc-2008-mxcurioni soc-2008-nicholasbishop soc-2008-quorn soc-2009-aligorith soc-2009-chingachgook soc-2009-imbusy soc-2009-jaguarandi soc-2009-kazanbas soc-2010-aligorith soc-2010-jwilkins soc-2010-merwin soc-2010-nexyon soc-2010-nicks soc-2010-nicolasbishop soc-2011-carrot soc-2011-cucumber soc-2011-garlic soc-2011-pepper soc-2011-radish soc-2011-tomato soc-2012-bratwurst soc-2012-fried_chicken soc-2012-sushi soc-2012-swiss_cheese soc-2013-bge soc-2013-cycles_volume soc-2013-depsgraph_eval soc-2013-depsgraph_mt soc-2013-dingto soc-2013-motion_track soc-2013-paint soc-2013-rigid_body_sim soc-2013-sketch_mesh soc-2013-ui_replay soc-2013-viewport_fx soc-2014-bge soc-2014-cycles soc-2014-fluid soc-2014-nurbs soc-2014-remesh soc-2014-shapekey soc-2014-viewport_context soc-2014-viewport_fx soc-2016-cycles_denoising soc-2016-cycles_images soc-2016-multiview soc-2016-pbvh-painting soc-2016-sculpt_tools soc-2016-uv_tools soc-2017-normal-tools soc-2017-package_manager soc-2017-sculpting_brush soc-2017-sculpting_improvements soc-2017-vertex_paint soc-2018-bevel soc-2018-cycles-volumes soc-2018-hair-shader-fixes soc-2018-hair-shader soc-2018-npr soundsystem split-kernel-faster-building strand_editmode strand_nodes surface-deform-modifier temp-cycles-denoising temp-cycles-microdisplacement temp-cycles-opencl-staging temp-decklink temp-drawcontext temp-dynamic-overrides temp-eeveelightcache temp-fracture-modifier-2.8 temp-ghash-experiments temp-ghash-setops temp-group-collections temp-keymap-changes temp-keymap-save temp-layers-ui-table temp-modifier-rm-cddm temp-object-multi-mode temp-openjpeg21 temp-openjpeg23 temp-outliner-visibility temp-render-depsgraph temp-scene-obedit-remove temp-ssr temp-sybren-cow-ocean temp-sybren-modifier-nonmesh temp-sybren-particles temp-sybren-poselib temp-tab_drag_drop temp-udim-images temp-ui-layout-2.8 temp-ui-widget-refactor temp-unified-collections temp-volume-object temp-workspace-addons temp-workspace-object-mode-removal temp-workspace_active_object temp-workspace_mode temp_bge_moto temp_cryptomatte temp_cycles_split_kernel temp_depsgraph_split_ubereval temp_display_optimization temp_facegroups temp_localview_split temp_motionpaths temp_remove_particles temp_remove_pointcache temp_textedit_comment_toggling temp_viewport_fx_merge terrible_consequencer texture_nodes_refactor tile tiles-scheduler tmp-COW_InsertKeyframe_Fix tmp-CollectionsAnim tmp-TimelineHeaderButtonsStretching tmp-b28-motionpath-drawing tmp-static-override-insertion topbar transform-manipulators ui_layout_gridflow uiTable unlock_task_scheduler userpref_redesign uv_unwrapping_slim_algorithm uv_unwrapping_slim_and_ceres vertex_paint_pbvh vgroup_modifiers viewport_bvh_select viewport_experiments viewport_generic_engine volume25
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
132 lines (117 sloc) 6.04 KB
// Copyright (c) 2014 libmv authors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#ifndef LIBMV_SIMPLE_PIPELINE_DISTORTION_MODELS_H_
#define LIBMV_SIMPLE_PIPELINE_DISTORTION_MODELS_H_
namespace libmv {
enum DistortionModelType {
DISTORTION_MODEL_POLYNOMIAL,
DISTORTION_MODEL_DIVISION
};
// Invert camera intrinsics on the image point to get normalized coordinates.
// This inverts the radial lens distortion to a point which is in image pixel
// coordinates to get normalized coordinates.
void InvertPolynomialDistortionModel(const double focal_length_x,
const double focal_length_y,
const double principal_point_x,
const double principal_point_y,
const double k1,
const double k2,
const double k3,
const double p1,
const double p2,
const double image_x,
const double image_y,
double *normalized_x,
double *normalized_y);
// Apply camera intrinsics to the normalized point to get image coordinates.
// This applies the radial lens distortion to a point which is in normalized
// camera coordinates (i.e. the principal point is at (0, 0)) to get image
// coordinates in pixels. Templated for use with autodifferentiation.
template <typename T>
inline void ApplyPolynomialDistortionModel(const T &focal_length_x,
const T &focal_length_y,
const T &principal_point_x,
const T &principal_point_y,
const T &k1,
const T &k2,
const T &k3,
const T &p1,
const T &p2,
const T &normalized_x,
const T &normalized_y,
T *image_x,
T *image_y) {
T x = normalized_x;
T y = normalized_y;
// Apply distortion to the normalized points to get (xd, yd).
T r2 = x*x + y*y;
T r4 = r2 * r2;
T r6 = r4 * r2;
T r_coeff = (T(1) + k1*r2 + k2*r4 + k3*r6);
T xd = x * r_coeff + T(2)*p1*x*y + p2*(r2 + T(2)*x*x);
T yd = y * r_coeff + T(2)*p2*x*y + p1*(r2 + T(2)*y*y);
// Apply focal length and principal point to get the final image coordinates.
*image_x = focal_length_x * xd + principal_point_x;
*image_y = focal_length_y * yd + principal_point_y;
}
// Invert camera intrinsics on the image point to get normalized coordinates.
// This inverts the radial lens distortion to a point which is in image pixel
// coordinates to get normalized coordinates.
//
// Uses division distortion model.
void InvertDivisionDistortionModel(const double focal_length_x,
const double focal_length_y,
const double principal_point_x,
const double principal_point_y,
const double k1,
const double k2,
const double image_x,
const double image_y,
double *normalized_x,
double *normalized_y);
// Apply camera intrinsics to the normalized point to get image coordinates.
// This applies the radial lens distortion to a point which is in normalized
// camera coordinates (i.e. the principal point is at (0, 0)) to get image
// coordinates in pixels. Templated for use with autodifferentiation.
//
// Uses division distortion model.
template <typename T>
inline void ApplyDivisionDistortionModel(const T &focal_length_x,
const T &focal_length_y,
const T &principal_point_x,
const T &principal_point_y,
const T &k1,
const T &k2,
const T &normalized_x,
const T &normalized_y,
T *image_x,
T *image_y) {
T x = normalized_x;
T y = normalized_y;
T r2 = x*x + y*y;
T r4 = r2 * r2;
T xd = x / (T(1) + k1 * r2 + k2 * r4);
T yd = y / (T(1) + k1 * r2 + k2 * r4);
// Apply focal length and principal point to get the final image coordinates.
*image_x = focal_length_x * xd + principal_point_x;
*image_y = focal_length_y * yd + principal_point_y;
}
} // namespace libmv
#endif // LIBMV_SIMPLE_PIPELINE_DISTORTION_MODELS_H_