|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 David Cattermole. |
| 3 | + * |
| 4 | + * This file is part of mmSolver. |
| 5 | + * |
| 6 | + * mmSolver is free software: you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU Lesser General Public License as |
| 8 | + * published by the Free Software Foundation, either version 3 of the |
| 9 | + * License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * mmSolver is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with mmSolver. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + * ==================================================================== |
| 19 | + * |
| 20 | + * OpenMVG API wrapper for OpenMVG functionality. |
| 21 | + * This provides a clean C API to decouple Maya code from OpenMVG. |
| 22 | + */ |
| 23 | + |
| 24 | +#ifndef MMSOLVERLIBS_OPENMVG_WRAPPER_H |
| 25 | +#define MMSOLVERLIBS_OPENMVG_WRAPPER_H |
| 26 | + |
| 27 | +#include <cstddef> |
| 28 | +#include <cstdint> |
| 29 | + |
| 30 | +namespace mmsolverlibs { |
| 31 | +namespace openmvg { |
| 32 | + |
| 33 | +// Forward declarations for opaque types |
| 34 | +struct HomographyMatrix; |
| 35 | +struct RelativePoseInfo; |
| 36 | +struct CameraIntrinsics; |
| 37 | +struct Pose3; |
| 38 | + |
| 39 | +// Point structures |
| 40 | +struct Point2d { |
| 41 | + double x; |
| 42 | + double y; |
| 43 | +}; |
| 44 | + |
| 45 | +struct Point3d { |
| 46 | + double x; |
| 47 | + double y; |
| 48 | + double z; |
| 49 | +}; |
| 50 | + |
| 51 | +// Homography functions |
| 52 | +HomographyMatrix* homography_matrix_new(); |
| 53 | +void homography_matrix_free(HomographyMatrix* matrix); |
| 54 | + |
| 55 | +bool compute_homography(std::int32_t image_width_a, std::int32_t image_width_b, |
| 56 | + std::int32_t image_height_a, |
| 57 | + std::int32_t image_height_b, |
| 58 | + const Point2d* marker_coords_a, |
| 59 | + std::size_t num_markers_a, |
| 60 | + const Point2d* marker_coords_b, |
| 61 | + std::size_t num_markers_b, |
| 62 | + HomographyMatrix* homography_matrix); |
| 63 | + |
| 64 | +bool robust_homography( |
| 65 | + const double* x1_data, std::size_t x1_rows, std::size_t x1_cols, |
| 66 | + const double* x2_data, std::size_t x2_rows, std::size_t x2_cols, |
| 67 | + HomographyMatrix* homography_matrix, std::uint32_t image_width_1, |
| 68 | + std::uint32_t image_height_1, std::uint32_t image_width_2, |
| 69 | + std::uint32_t image_height_2, std::uint32_t max_iteration_count); |
| 70 | + |
| 71 | +// Camera relative pose functions |
| 72 | +RelativePoseInfo* relative_pose_info_new(); |
| 73 | +void relative_pose_info_free(RelativePoseInfo* info); |
| 74 | + |
| 75 | +CameraIntrinsics* camera_intrinsics_new_pinhole(std::uint32_t width, |
| 76 | + std::uint32_t height, |
| 77 | + double focal_length, double ppx, |
| 78 | + double ppy); |
| 79 | +void camera_intrinsics_free(CameraIntrinsics* intrinsics); |
| 80 | + |
| 81 | +bool robust_relative_pose( |
| 82 | + const CameraIntrinsics* intrinsics1, const CameraIntrinsics* intrinsics2, |
| 83 | + const double* x1_data, std::size_t x1_rows, std::size_t x1_cols, |
| 84 | + const double* x2_data, std::size_t x2_rows, std::size_t x2_cols, |
| 85 | + RelativePoseInfo* relative_pose_info, std::uint32_t image_width_1, |
| 86 | + std::uint32_t image_height_1, std::uint32_t image_width_2, |
| 87 | + std::uint32_t image_height_2, std::uint32_t max_iteration_count); |
| 88 | + |
| 89 | +bool compute_relative_pose( |
| 90 | + std::int32_t image_width_a, std::int32_t image_width_b, |
| 91 | + std::int32_t image_height_a, std::int32_t image_height_b, |
| 92 | + double focal_length_pix_a, double focal_length_pix_b, double ppx_pix_a, |
| 93 | + double ppx_pix_b, double ppy_pix_a, double ppy_pix_b, |
| 94 | + const Point2d* marker_coords_a, std::size_t num_markers_a, |
| 95 | + const Point2d* marker_coords_b, std::size_t num_markers_b, |
| 96 | + RelativePoseInfo* relative_pose_info, Point3d* triangulated_points, |
| 97 | + std::size_t* num_triangulated_points); |
| 98 | + |
| 99 | +// Camera from known points (PnP) functions |
| 100 | +Pose3* pose3_new(); |
| 101 | +void pose3_free(Pose3* pose); |
| 102 | + |
| 103 | +bool solve_pnp_p3p_nordberg(const Point3d* world_points, |
| 104 | + std::size_t num_world_points, |
| 105 | + const Point2d* image_points, |
| 106 | + std::size_t num_image_points, |
| 107 | + const CameraIntrinsics* intrinsics, Pose3* pose, |
| 108 | + std::uint32_t max_iteration_count); |
| 109 | + |
| 110 | +// Utility functions for extracting data from opaque types |
| 111 | +bool homography_matrix_get_data(const HomographyMatrix* matrix, double* data); |
| 112 | +bool relative_pose_info_get_rotation(const RelativePoseInfo* info, |
| 113 | + double* rotation_matrix); |
| 114 | +bool relative_pose_info_get_translation(const RelativePoseInfo* info, |
| 115 | + double* translation_vector); |
| 116 | +bool pose3_get_rotation(const Pose3* pose, double* rotation_matrix); |
| 117 | +bool pose3_get_translation(const Pose3* pose, double* translation_vector); |
| 118 | + |
| 119 | +} // namespace openmvg |
| 120 | +} // namespace mmsolverlibs |
| 121 | + |
| 122 | +#endif // MMSOLVERLIBS_OPENMVG_WRAPPER_H |
0 commit comments