opencv_binding_generator/settings/
func_companion_tweak.rs

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
use std::collections::HashMap;

use crate::func::FuncMatcher;

pub type FuncCompanionTweak = FuncMatcher<'static, CompanionTweak>;

#[derive(Debug, Clone, Copy)]
pub enum CompanionTweak {
	/// Don't generate the `*_def` function companion
	SkipDefault,
}

pub fn func_companion_tweak_factory(module: &str) -> FuncCompanionTweak {
	match module {
		"dnn" => dnn_factory(),
		"text" => text_factory(),
		_ => FuncCompanionTweak::empty(),
	}
}

fn dnn_factory() -> FuncCompanionTweak {
	FuncMatcher::create(HashMap::from([(
		"cv::dnn::Graph::append", // 2 functions with the same name and same non-default arguments lead to the name clash and ambiguous call in C++
		vec![
			(pred!(mut, ["layer", "outnames"]), CompanionTweak::SkipDefault),
			(pred!(mut, ["layer", "outname"]), CompanionTweak::SkipDefault),
		],
	)]))
}

fn text_factory() -> FuncCompanionTweak {
	FuncMatcher::create(HashMap::from([(
		"cv::text::OCRBeamSearchDecoder::create",
		vec![(
			pred!(
				mut,
				[
					"classifier",
					"vocabulary",
					"transition_probabilities_table",
					"emission_probabilities_table",
					"mode",
					"beam_size"
				],
			),
			CompanionTweak::SkipDefault, // with OpenCV 4.2 this leads to https://github.com/twistedfall/opencv-rust/issues/505
		)],
	)]))
}

impl CompanionTweak {
	pub fn skip_default(&self) -> bool {
		match self {
			CompanionTweak::SkipDefault => true,
		}
	}
}