use std::os::raw::{c_char, c_void};
use libc::{ptrdiff_t, size_t};
use crate::{Error, Result, core, sys, types};
pub const SFM_DISTORTION_MODEL_DIVISION: i32 = 1;
pub const SFM_DISTORTION_MODEL_POLYNOMIAL: i32 = 0;
pub const SFM_IO_BUNDLER: i32 = 0;
pub const SFM_IO_OPENMVG: i32 = 3;
pub const SFM_IO_OPENSFM: i32 = 2;
pub const SFM_IO_THEIASFM: i32 = 4;
pub const SFM_IO_VISUALSFM: i32 = 1;
pub const SFM_REFINE_FOCAL_LENGTH: i32 = (1 << 0);
pub const SFM_REFINE_PRINCIPAL_POINT: i32 = (1 << 1);
pub const SFM_REFINE_RADIAL_DISTORTION_K1: i32 = (1 << 2);
pub const SFM_REFINE_RADIAL_DISTORTION_K2: i32 = (1 << 4);
#[repr(C)]
#[derive(Copy,Clone,Debug,PartialEq)]
pub struct libmv_CameraIntrinsicsOptions {
pub distortion_model: i32,
pub image_width: i32,
pub image_height: i32,
pub focal_length: f64,
pub principal_point_x: f64,
pub principal_point_y: f64,
pub polynomial_k1: f64,
pub polynomial_k2: f64,
pub polynomial_k3: f64,
pub polynomial_p1: f64,
pub polynomial_p2: f64,
pub division_k1: f64,
pub division_k2: f64,
}
#[repr(C)]
#[derive(Copy,Clone,Debug,PartialEq)]
pub struct libmv_ReconstructionOptions {
pub keyframe1: i32,
pub keyframe2: i32,
pub refine_intrinsics: i32,
pub select_keyframes: i32,
pub verbosity_level: i32,
}
pub fn k_rt_from_projection(p: &core::Mat, k: &mut core::Mat, r: &mut core::Mat, t: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_KRtFromProjection_Mat_Mat_Mat_Mat(p.as_raw_Mat(), k.as_raw_Mat(), r.as_raw_Mat(), t.as_raw_Mat()) }.into_result()
}
pub fn apply_transformation_to_points(points: &core::Mat, t: &core::Mat, transformed_points: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_applyTransformationToPoints_Mat_Mat_Mat(points.as_raw_Mat(), t.as_raw_Mat(), transformed_points.as_raw_Mat()) }.into_result()
}
pub fn compute_orientation(x1: &types::VectorOfMat, x2: &types::VectorOfMat, r: &mut core::Mat, t: &mut core::Mat, s: f64) -> Result<()> {
unsafe { sys::cv_sfm_computeOrientation_VectorOfMat_VectorOfMat_Mat_Mat_double(x1.as_raw_VectorOfMat(), x2.as_raw_VectorOfMat(), r.as_raw_Mat(), t.as_raw_Mat(), s) }.into_result()
}
pub fn depth(r: &core::Mat, t: &core::Mat, x: &core::Mat) -> Result<f64> {
unsafe { sys::cv_sfm_depth_Mat_Mat_Mat(r.as_raw_Mat(), t.as_raw_Mat(), x.as_raw_Mat()) }.into_result()
}
pub fn essential_from_fundamental(f: &core::Mat, k1: &core::Mat, k2: &core::Mat, e: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_essentialFromFundamental_Mat_Mat_Mat_Mat(f.as_raw_Mat(), k1.as_raw_Mat(), k2.as_raw_Mat(), e.as_raw_Mat()) }.into_result()
}
pub fn essential_from_rt(r1: &core::Mat, t1: &core::Mat, r2: &core::Mat, t2: &core::Mat, e: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_essentialFromRt_Mat_Mat_Mat_Mat_Mat(r1.as_raw_Mat(), t1.as_raw_Mat(), r2.as_raw_Mat(), t2.as_raw_Mat(), e.as_raw_Mat()) }.into_result()
}
pub fn euclidean_to_homogeneous(src: &core::Mat, dst: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_euclideanToHomogeneous_Mat_Mat(src.as_raw_Mat(), dst.as_raw_Mat()) }.into_result()
}
pub fn fundamental_from_correspondences7_point_robust(x1: &core::Mat, x2: &core::Mat, max_error: f64, f: &mut core::Mat, inliers: &mut core::Mat, outliers_probability: f64) -> Result<f64> {
unsafe { sys::cv_sfm_fundamentalFromCorrespondences7PointRobust_Mat_Mat_double_Mat_Mat_double(x1.as_raw_Mat(), x2.as_raw_Mat(), max_error, f.as_raw_Mat(), inliers.as_raw_Mat(), outliers_probability) }.into_result()
}
pub fn fundamental_from_correspondences8_point_robust(x1: &core::Mat, x2: &core::Mat, max_error: f64, f: &mut core::Mat, inliers: &mut core::Mat, outliers_probability: f64) -> Result<f64> {
unsafe { sys::cv_sfm_fundamentalFromCorrespondences8PointRobust_Mat_Mat_double_Mat_Mat_double(x1.as_raw_Mat(), x2.as_raw_Mat(), max_error, f.as_raw_Mat(), inliers.as_raw_Mat(), outliers_probability) }.into_result()
}
pub fn fundamental_from_essential(e: &core::Mat, k1: &core::Mat, k2: &core::Mat, f: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_fundamentalFromEssential_Mat_Mat_Mat_Mat(e.as_raw_Mat(), k1.as_raw_Mat(), k2.as_raw_Mat(), f.as_raw_Mat()) }.into_result()
}
pub fn fundamental_from_projections(p1: &core::Mat, p2: &core::Mat, f: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_fundamentalFromProjections_Mat_Mat_Mat(p1.as_raw_Mat(), p2.as_raw_Mat(), f.as_raw_Mat()) }.into_result()
}
pub fn homogeneous_to_euclidean(src: &core::Mat, dst: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_homogeneousToEuclidean_Mat_Mat(src.as_raw_Mat(), dst.as_raw_Mat()) }.into_result()
}
pub fn import_reconstruction(file: &str, rs: &mut types::VectorOfMat, ts: &mut types::VectorOfMat, ks: &mut types::VectorOfMat, points3d: &mut core::Mat, file_format: i32) -> Result<()> {
string_arg!(file);
unsafe { sys::cv_sfm_importReconstruction_String_VectorOfMat_VectorOfMat_VectorOfMat_Mat_int(file.as_ptr(), rs.as_raw_VectorOfMat(), ts.as_raw_VectorOfMat(), ks.as_raw_VectorOfMat(), points3d.as_raw_Mat(), file_format) }.into_result()
}
pub fn isotropic_preconditioner_from_points(points: &core::Mat, t: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_isotropicPreconditionerFromPoints_Mat_Mat(points.as_raw_Mat(), t.as_raw_Mat()) }.into_result()
}
pub fn mean_and_variance_along_rows(a: &core::Mat, mean: &mut core::Mat, variance: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_meanAndVarianceAlongRows_Mat_Mat_Mat(a.as_raw_Mat(), mean.as_raw_Mat(), variance.as_raw_Mat()) }.into_result()
}
pub fn motion_from_essential_choose_solution(rs: &types::VectorOfMat, ts: &types::VectorOfMat, k1: &core::Mat, x1: &core::Mat, k2: &core::Mat, x2: &core::Mat) -> Result<i32> {
unsafe { sys::cv_sfm_motionFromEssentialChooseSolution_VectorOfMat_VectorOfMat_Mat_Mat_Mat_Mat(rs.as_raw_VectorOfMat(), ts.as_raw_VectorOfMat(), k1.as_raw_Mat(), x1.as_raw_Mat(), k2.as_raw_Mat(), x2.as_raw_Mat()) }.into_result()
}
pub fn motion_from_essential(e: &core::Mat, rs: &mut types::VectorOfMat, ts: &mut types::VectorOfMat) -> Result<()> {
unsafe { sys::cv_sfm_motionFromEssential_Mat_VectorOfMat_VectorOfMat(e.as_raw_Mat(), rs.as_raw_VectorOfMat(), ts.as_raw_VectorOfMat()) }.into_result()
}
pub fn normalize_fundamental(f: &core::Mat, f_normalized: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_normalizeFundamental_Mat_Mat(f.as_raw_Mat(), f_normalized.as_raw_Mat()) }.into_result()
}
pub fn normalize_isotropic_points(points: &core::Mat, normalized_points: &mut core::Mat, t: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_normalizeIsotropicPoints_Mat_Mat_Mat(points.as_raw_Mat(), normalized_points.as_raw_Mat(), t.as_raw_Mat()) }.into_result()
}
pub fn normalize_points(points: &core::Mat, normalized_points: &mut core::Mat, t: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_normalizePoints_Mat_Mat_Mat(points.as_raw_Mat(), normalized_points.as_raw_Mat(), t.as_raw_Mat()) }.into_result()
}
pub fn normalized_eight_point_solver(x1: &core::Mat, x2: &core::Mat, f: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_normalizedEightPointSolver_Mat_Mat_Mat(x1.as_raw_Mat(), x2.as_raw_Mat(), f.as_raw_Mat()) }.into_result()
}
pub fn preconditioner_from_points(points: &core::Mat, t: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_preconditionerFromPoints_Mat_Mat(points.as_raw_Mat(), t.as_raw_Mat()) }.into_result()
}
pub fn projection_from_k_rt(k: &core::Mat, r: &core::Mat, t: &core::Mat, p: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_projectionFromKRt_Mat_Mat_Mat_Mat(k.as_raw_Mat(), r.as_raw_Mat(), t.as_raw_Mat(), p.as_raw_Mat()) }.into_result()
}
pub fn projections_from_fundamental(f: &core::Mat, p1: &mut core::Mat, p2: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_projectionsFromFundamental_Mat_Mat_Mat(f.as_raw_Mat(), p1.as_raw_Mat(), p2.as_raw_Mat()) }.into_result()
}
pub fn reconstruct(points2d: &types::VectorOfMat, rs: &mut core::Mat, ts: &mut core::Mat, k: &mut core::Mat, points3d: &mut core::Mat, is_projective: bool) -> Result<()> {
unsafe { sys::cv_sfm_reconstruct_VectorOfMat_Mat_Mat_Mat_Mat_bool(points2d.as_raw_VectorOfMat(), rs.as_raw_Mat(), ts.as_raw_Mat(), k.as_raw_Mat(), points3d.as_raw_Mat(), is_projective) }.into_result()
}
pub fn reconstruct_1(points2d: &types::VectorOfMat, ps: &mut core::Mat, points3d: &mut core::Mat, k: &mut core::Mat, is_projective: bool) -> Result<()> {
unsafe { sys::cv_sfm_reconstruct_VectorOfMat_Mat_Mat_Mat_bool(points2d.as_raw_VectorOfMat(), ps.as_raw_Mat(), points3d.as_raw_Mat(), k.as_raw_Mat(), is_projective) }.into_result()
}
pub fn reconstruct_2(images: &types::VectorOfString, rs: &mut core::Mat, ts: &mut core::Mat, k: &mut core::Mat, points3d: &mut core::Mat, is_projective: bool) -> Result<()> {
unsafe { sys::cv_sfm_reconstruct_VectorOfString_Mat_Mat_Mat_Mat_bool(images.as_raw_VectorOfString(), rs.as_raw_Mat(), ts.as_raw_Mat(), k.as_raw_Mat(), points3d.as_raw_Mat(), is_projective) }.into_result()
}
pub fn reconstruct_3(images: &types::VectorOfString, ps: &mut core::Mat, points3d: &mut core::Mat, k: &mut core::Mat, is_projective: bool) -> Result<()> {
unsafe { sys::cv_sfm_reconstruct_VectorOfString_Mat_Mat_Mat_bool(images.as_raw_VectorOfString(), ps.as_raw_Mat(), points3d.as_raw_Mat(), k.as_raw_Mat(), is_projective) }.into_result()
}
pub fn relative_camera_motion(r1: &core::Mat, t1: &core::Mat, r2: &core::Mat, t2: &core::Mat, r: &mut core::Mat, t: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_relativeCameraMotion_Mat_Mat_Mat_Mat_Mat_Mat(r1.as_raw_Mat(), t1.as_raw_Mat(), r2.as_raw_Mat(), t2.as_raw_Mat(), r.as_raw_Mat(), t.as_raw_Mat()) }.into_result()
}
pub fn skew(x: &core::Mat) -> Result<core::Mat> {
unsafe { sys::cv_sfm_skew_Mat(x.as_raw_Mat()) }.into_result().map(|ptr| core::Mat { ptr })
}
pub fn triangulate_points(points2d: &types::VectorOfMat, projection_matrices: &types::VectorOfMat, points3d: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_triangulatePoints_VectorOfMat_VectorOfMat_Mat(points2d.as_raw_VectorOfMat(), projection_matrices.as_raw_VectorOfMat(), points3d.as_raw_Mat()) }.into_result()
}
pub trait BaseSFM {
#[inline(always)] fn as_raw_BaseSFM(&self) -> *mut c_void;
fn run(&mut self, points2d: &types::VectorOfMat) -> Result<()> {
unsafe { sys::cv_sfm_BaseSFM_run_VectorOfMat(self.as_raw_BaseSFM(), points2d.as_raw_VectorOfMat()) }.into_result()
}
fn run_1(&mut self, points2d: &types::VectorOfMat, k: &mut core::Mat, rs: &mut core::Mat, ts: &mut core::Mat, points3d: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_BaseSFM_run_VectorOfMat_Mat_Mat_Mat_Mat(self.as_raw_BaseSFM(), points2d.as_raw_VectorOfMat(), k.as_raw_Mat(), rs.as_raw_Mat(), ts.as_raw_Mat(), points3d.as_raw_Mat()) }.into_result()
}
fn run_2(&mut self, images: &types::VectorOfString) -> Result<()> {
unsafe { sys::cv_sfm_BaseSFM_run_VectorOfString(self.as_raw_BaseSFM(), images.as_raw_VectorOfString()) }.into_result()
}
fn run_3(&mut self, images: &types::VectorOfString, k: &mut core::Mat, rs: &mut core::Mat, ts: &mut core::Mat, points3d: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_BaseSFM_run_VectorOfString_Mat_Mat_Mat_Mat(self.as_raw_BaseSFM(), images.as_raw_VectorOfString(), k.as_raw_Mat(), rs.as_raw_Mat(), ts.as_raw_Mat(), points3d.as_raw_Mat()) }.into_result()
}
fn get_error(&self) -> Result<f64> {
unsafe { sys::cv_sfm_BaseSFM_getError_const(self.as_raw_BaseSFM()) }.into_result()
}
fn get_points(&mut self, points3d: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_BaseSFM_getPoints_Mat(self.as_raw_BaseSFM(), points3d.as_raw_Mat()) }.into_result()
}
fn get_intrinsics(&self) -> Result<core::Mat> {
unsafe { sys::cv_sfm_BaseSFM_getIntrinsics_const(self.as_raw_BaseSFM()) }.into_result().map(|ptr| core::Mat { ptr })
}
fn get_cameras(&mut self, rs: &mut core::Mat, ts: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_BaseSFM_getCameras_Mat_Mat(self.as_raw_BaseSFM(), rs.as_raw_Mat(), ts.as_raw_Mat()) }.into_result()
}
fn set_reconstruction_options(&mut self, libmv_reconstruction_options: crate::sfm::libmv_ReconstructionOptions) -> Result<()> {
unsafe { sys::cv_sfm_BaseSFM_setReconstructionOptions_libmv_ReconstructionOptions(self.as_raw_BaseSFM(), libmv_reconstruction_options) }.into_result()
}
fn set_camera_intrinsic_options(&mut self, libmv_camera_intrinsics_options: crate::sfm::libmv_CameraIntrinsicsOptions) -> Result<()> {
unsafe { sys::cv_sfm_BaseSFM_setCameraIntrinsicOptions_libmv_CameraIntrinsicsOptions(self.as_raw_BaseSFM(), libmv_camera_intrinsics_options) }.into_result()
}
}
pub struct SFMLibmvEuclideanReconstruction {
#[doc(hidden)] pub(crate) ptr: *mut c_void
}
impl Drop for crate::sfm::SFMLibmvEuclideanReconstruction {
fn drop(&mut self) {
unsafe { sys::cv_SFMLibmvEuclideanReconstruction_delete(self.ptr) };
}
}
impl crate::sfm::SFMLibmvEuclideanReconstruction {
#[inline(always)] pub fn as_raw_SFMLibmvEuclideanReconstruction(&self) -> *mut c_void { self.ptr }
pub unsafe fn from_raw_ptr(ptr: *mut c_void) -> Self {
Self { ptr }
}
}
unsafe impl Send for SFMLibmvEuclideanReconstruction {}
impl crate::sfm::BaseSFM for SFMLibmvEuclideanReconstruction {
#[inline(always)] fn as_raw_BaseSFM(&self) -> *mut c_void { self.ptr }
}
impl SFMLibmvEuclideanReconstruction {
pub fn run(&mut self, points2d: &types::VectorOfMat) -> Result<()> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_run_VectorOfMat(self.as_raw_SFMLibmvEuclideanReconstruction(), points2d.as_raw_VectorOfMat()) }.into_result()
}
pub fn run_1(&mut self, points2d: &types::VectorOfMat, k: &mut core::Mat, rs: &mut core::Mat, ts: &mut core::Mat, points3d: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_run_VectorOfMat_Mat_Mat_Mat_Mat(self.as_raw_SFMLibmvEuclideanReconstruction(), points2d.as_raw_VectorOfMat(), k.as_raw_Mat(), rs.as_raw_Mat(), ts.as_raw_Mat(), points3d.as_raw_Mat()) }.into_result()
}
pub fn run_2(&mut self, images: &types::VectorOfString) -> Result<()> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_run_VectorOfString(self.as_raw_SFMLibmvEuclideanReconstruction(), images.as_raw_VectorOfString()) }.into_result()
}
pub fn run_3(&mut self, images: &types::VectorOfString, k: &mut core::Mat, rs: &mut core::Mat, ts: &mut core::Mat, points3d: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_run_VectorOfString_Mat_Mat_Mat_Mat(self.as_raw_SFMLibmvEuclideanReconstruction(), images.as_raw_VectorOfString(), k.as_raw_Mat(), rs.as_raw_Mat(), ts.as_raw_Mat(), points3d.as_raw_Mat()) }.into_result()
}
pub fn get_error(&self) -> Result<f64> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_getError_const(self.as_raw_SFMLibmvEuclideanReconstruction()) }.into_result()
}
pub fn get_points(&mut self, points3d: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_getPoints_Mat(self.as_raw_SFMLibmvEuclideanReconstruction(), points3d.as_raw_Mat()) }.into_result()
}
pub fn get_intrinsics(&self) -> Result<core::Mat> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_getIntrinsics_const(self.as_raw_SFMLibmvEuclideanReconstruction()) }.into_result().map(|ptr| core::Mat { ptr })
}
pub fn get_cameras(&mut self, rs: &mut core::Mat, ts: &mut core::Mat) -> Result<()> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_getCameras_Mat_Mat(self.as_raw_SFMLibmvEuclideanReconstruction(), rs.as_raw_Mat(), ts.as_raw_Mat()) }.into_result()
}
pub fn set_reconstruction_options(&mut self, libmv_reconstruction_options: crate::sfm::libmv_ReconstructionOptions) -> Result<()> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_setReconstructionOptions_libmv_ReconstructionOptions(self.as_raw_SFMLibmvEuclideanReconstruction(), libmv_reconstruction_options) }.into_result()
}
pub fn set_camera_intrinsic_options(&mut self, libmv_camera_intrinsics_options: crate::sfm::libmv_CameraIntrinsicsOptions) -> Result<()> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_setCameraIntrinsicOptions_libmv_CameraIntrinsicsOptions(self.as_raw_SFMLibmvEuclideanReconstruction(), libmv_camera_intrinsics_options) }.into_result()
}
pub fn create(camera_instrinsic_options: crate::sfm::libmv_CameraIntrinsicsOptions, reconstruction_options: crate::sfm::libmv_ReconstructionOptions) -> Result<types::PtrOfSFMLibmvEuclideanReconstruction> {
unsafe { sys::cv_sfm_SFMLibmvEuclideanReconstruction_create_libmv_CameraIntrinsicsOptions_libmv_ReconstructionOptions(camera_instrinsic_options, reconstruction_options) }.into_result().map(|ptr| types::PtrOfSFMLibmvEuclideanReconstruction { ptr })
}
}
impl libmv_CameraIntrinsicsOptions {
pub fn new(_distortion_model: i32, _focal_length: f64, _principal_point_x: f64, _principal_point_y: f64, _polynomial_k1: f64, _polynomial_k2: f64, _polynomial_k3: f64, _polynomial_p1: f64, _polynomial_p2: f64) -> Result<crate::sfm::libmv_CameraIntrinsicsOptions> {
unsafe { sys::cv_sfm_libmv_CameraIntrinsicsOptions_libmv_CameraIntrinsicsOptions_int_double_double_double_double_double_double_double_double(_distortion_model, _focal_length, _principal_point_x, _principal_point_y, _polynomial_k1, _polynomial_k2, _polynomial_k3, _polynomial_p1, _polynomial_p2) }.into_result()
}
}
impl libmv_ReconstructionOptions {
pub fn new(_keyframe1: i32, _keyframe2: i32, _refine_intrinsics: i32, _select_keyframes: i32, _verbosity_level: i32) -> Result<crate::sfm::libmv_ReconstructionOptions> {
unsafe { sys::cv_sfm_libmv_ReconstructionOptions_libmv_ReconstructionOptions_int_int_int_int_int(_keyframe1, _keyframe2, _refine_intrinsics, _select_keyframes, _verbosity_level) }.into_result()
}
}