enable more functionality in dnn module
MODIFY
gen_rust.py
gen_rust.py
@@ -11,7 +11,6 @@ from pprint import pformat
from string import Template
-# fixme Net methods consume self, should probably take reference
# fixme returning MatAllocator (trait) by reference is bad, check knearestneighbour
# fixme add getcpufeaturesline
@@ -92,7 +91,10 @@ decls_manual_pre = {
("class cv.KeyPoint", "", ["/Ghost", "/Simple"], []),
("class cv.RotatedRect", "", ["/Ghost"], []),
("class cv.TermCriteria", "", ["/Ghost"], []),
- ]
+ ],
+ "dnn": [
+ ("class cv.dnn.LayerParams", "", ["/Ghost"], []),
+ ],
}
# dict of decls to inject after doing header parsing
@@ -101,7 +103,10 @@ decls_manual_pre = {
decls_manual_post = {
"core": [
("cv.Mat.size", "Size", ["/C"], []),
- ]
+ ],
+ "dnn": [
+ ("cv.dnn.LayerParams.LayerParams", "", [], []),
+ ],
}
# dict of functions to rename or skip, key is FuncInfo.identifier, value is new name ("+" will be replaces by old name) or "-" to skip
@@ -447,6 +452,7 @@ type_replace = {
"_InputArray": "cv::Mat",
"_OutputArray": "cv::Mat",
"_InputOutputArray": "cv::Mat",
+ "vector_Mat": "vector<cv::Mat>",
"_Range": "cv::Range",
"Point_<int>": "Point2i",
"Point_<int64>": "Point2l",
@@ -601,6 +607,11 @@ forced_class_trait = {
"cv::dnn::Layer",
}
+# set of types that must not be treated as simple, most probably will be treated as boxed, elements are ClassInfo.fullname
+force_class_not_simple = {
+ "cv::dnn::Net", # marked as Simple, but it's actually boxed
+}
+
# dict of reserved Rust keywords and their replacement to be used in var, function and class names
# key: reserved keyword
# value: replacement
@@ -1177,7 +1188,7 @@ class ClassInfo(GeneralInfo):
if len(decl) > 5:
self.comment = decl[5].encode("ascii", "ignore")
for m in decl[2]:
- if m == "/Simple" or m == "/Map":
+ if (m == "/Simple" or m == "/Map") and self.fullname not in force_class_not_simple:
self.is_simple = True
if m == "/Hidden":
self.is_ignored = True
@@ -1185,7 +1196,9 @@ class ClassInfo(GeneralInfo):
self.is_ghost = True
if m == "/Callback":
self.is_callback = True
- if self.classpath and self.gen.get_class(self.classpath).is_ignored:
+ if self.classpath:
+ ci = self.gen.get_class(self.classpath)
+ if ci is not None and ci.is_ignored:
self.is_ignored = True
self.nested_cname = self.fullname.replace("::", "_")

MODIFY
hdr_parser.py
hdr_parser.py
@@ -800,7 +800,7 @@ class CppHeaderParser(object):
if (context == "struct" or context == "class") and end_token == ";" and stmt:
# looks like it's member declaration; append the members to the class declaration
class_decl = stack_top[self.CLASS_DECL]
- if "CV_PROP" in stmt or class_decl[0] in ("class cv.Mat", "class cv.RotatedRect", "class cv.TermCriteria", "class cv.Range"): # or (class_decl and ("/Map" in class_decl[2])):
+ if "CV_PROP" in stmt or class_decl[0] in ("class cv.Mat", "class cv.RotatedRect", "class cv.TermCriteria", "class cv.Range", "class cv.dnn.LayerParams"): # or (class_decl and ("/Map" in class_decl[2])):
var_modlist = []
if "CV_PROP_RW" in stmt:
var_modlist.append("/RW")

ADD
tests/dnn.rs
+use opencv::dnn::{Net, LayerParams};
+
+#[test]
+fn net() {
+ let mut net = Net::new().unwrap();
+ assert!(net.empty().unwrap());
+ net.enable_fusion(false).unwrap();
+ let mut params = LayerParams::new().unwrap();
+ assert_eq!(params.name().unwrap(), "");
+ assert_eq!(params._type().unwrap(), "");
+ let blobs = params.blobs().unwrap();
+ assert_eq!(0, blobs.len());
+ let res = net.add_layer("layer", "type", &params).unwrap();
+ assert_ne!(-1, res);
+ assert!(!net.empty().unwrap());
+}

enable more functionality in dnn module