1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::os::raw::{c_char, c_double, c_int, c_uchar, c_void};

#[repr(C)]
pub(crate) struct cv_return_value_double {
    pub(crate) is_cv_exception: c_char,
    pub(crate) is_other_exception: c_char,
    pub(crate) result: c_double,
}

#[repr(C)]
pub(crate) struct cv_return_value_bool {
    pub(crate) is_cv_exception: c_char,
    pub(crate) is_other_exception: c_char,
    pub(crate) result: bool,
}

#[repr(C)]
pub(crate) struct cv_return_value_slice {
    pub(crate) is_cv_exception: c_char,
    pub(crate) is_other_exception: c_char,
    pub(crate) ptr: *mut c_void,
    pub(crate) num_elements: c_int,
}

extern "C" {
    pub(crate) fn calibrate_camera(
        image_count: c_int,
        object_points: *const c_double,
        image_points: *const c_double,
        point_counts: *const c_int,
        imgWidth: c_int,
        imgHeight: c_int,
        camera_matrix: *mut c_double,
        distortion_coeffs: *mut c_double,
        rotation_matrices: *mut c_double,
        translation_vectors: *mut c_double,
    ) -> cv_return_value_double;

    pub(crate) fn find_chessboard_corners_inner(
        frame_data_rgb: *const c_uchar,
        frame_width: c_int,
        frame_height: c_int,
        pattern_width: c_int,
        pattern_height: c_int,
        result: *mut c_void,
    ) -> cv_return_value_bool;

    pub(crate) fn vec_point2f_new() -> *mut c_void;
    pub(crate) fn vec_point2f_delete(result: *mut c_void);
    pub(crate) fn vec_point2f_slice(result: *mut c_void) -> cv_return_value_slice;

    pub(crate) fn solve_pnp(
        n_points: c_int,
        object_points: *const c_double,
        image_points: *const c_double,
        camera_matrix: *const c_double,
        distortion_coeffs: *const c_double,
        rvec: *mut c_double,
        tvec: *mut c_double,
        pose_method: c_int,
    ) -> cv_return_value_bool;

    pub(crate) fn ippe() -> c_int;
    pub(crate) fn epnp() -> c_int;

}