opencv_binding_generator/settings/
generator_module_tweaks.rs

1use super::TypeRefFactory;
2use crate::type_ref::TypeRefDesc;
3use crate::SupportedModule;
4
5#[derive(Debug)]
6pub struct ModuleTweak<'l> {
7	pub generate_types: &'l [TypeRefFactory],
8}
9
10impl ModuleTweak<'_> {
11	pub fn empty() -> Self {
12		Self { generate_types: &[] }
13	}
14}
15
16pub fn generator_module_tweaks_factory(module: SupportedModule) -> ModuleTweak<'static> {
17	match module {
18		SupportedModule::Core => ModuleTweak {
19			generate_types: &[
20				TypeRefDesc::ptr_of_float,
21				// for the `field_access_on_ptr` test
22				TypeRefDesc::ptr_of_cv_keypoint,
23			],
24		},
25		SupportedModule::Aruco => ModuleTweak {
26			generate_types: &[TypeRefDesc::vector_of_cv_vec3f, TypeRefDesc::vector_of_cv_vec3d],
27		},
28		SupportedModule::CCalib => ModuleTweak {
29			generate_types: &[
30				// for cv::omnidir::calibrate objectPoints
31				TypeRefDesc::vector_of_vector_of_cv_vec3f,
32				TypeRefDesc::vector_of_vector_of_cv_vec3d,
33				TypeRefDesc::vector_of_vector_of_cv_point3f,
34				TypeRefDesc::vector_of_vector_of_cv_point3d,
35				// for cv::omnidir::calibrate imagePoints
36				TypeRefDesc::vector_of_vector_of_cv_vec2f,
37				TypeRefDesc::vector_of_vector_of_cv_point2f,
38				TypeRefDesc::vector_of_vector_of_cv_vec2d,
39				TypeRefDesc::vector_of_vector_of_cv_point2d,
40			],
41		},
42		SupportedModule::Calib3d | SupportedModule::Calib | SupportedModule::ThreeD => ModuleTweak {
43			generate_types: &[
44				// for calibrate_camera
45				TypeRefDesc::vector_of_cv_point3i,
46				TypeRefDesc::vector_of_vector_of_cv_point3i,
47				TypeRefDesc::vector_of_cv_point3f,
48				TypeRefDesc::vector_of_vector_of_cv_point3f,
49				TypeRefDesc::vector_of_cv_point3d,
50				TypeRefDesc::vector_of_vector_of_cv_point3d,
51				TypeRefDesc::vector_of_cv_vec3f,
52				TypeRefDesc::vector_of_vector_of_cv_vec3f,
53				// for solve_pnp tvec and rvec parameters
54				TypeRefDesc::vector_of_vector_of_double,
55				// for solve_pnp_ransac imagePoints parameter
56				TypeRefDesc::vector_of_cv_point2d,
57			],
58		},
59		SupportedModule::Dnn => ModuleTweak {
60			generate_types: &[TypeRefDesc::vector_of_vector_of_int], // Make sure that `Vector<MatShape>` is generated
61		},
62		SupportedModule::Features2d | SupportedModule::Features => ModuleTweak {
63			// type used in other modules, thus needs casting (https://github.com/twistedfall/opencv-rust/issues/218)
64			generate_types: &[TypeRefDesc::ptr_of_cv_feature2d],
65		},
66		SupportedModule::ImgProc => ModuleTweak {
67			generate_types: &[
68				// for findContours()
69				TypeRefDesc::vector_of_cv_vec4i,
70				TypeRefDesc::vector_of_vector_of_cv_point,
71				// for HoughLines()
72				TypeRefDesc::vector_of_cv_vec2f,
73				TypeRefDesc::vector_of_cv_vec2d,
74				TypeRefDesc::vector_of_cv_vec3f,
75				TypeRefDesc::vector_of_cv_vec3d,
76			],
77		},
78		_ => ModuleTweak::empty(),
79	}
80}