add support for more output arguments
MODIFY
examples/video_facedetect.rs
examples/video_facedetect.rs
@@ -67,7 +67,7 @@ fn run() -> opencv::Result<()> {
height: face.height * 4,
};
imgproc::rectangle(
- &frame,
+ &mut frame,
scaled_face,
core::Scalar::new(0f64, -1f64, -1f64, -1f64),
1,

MODIFY
gen_rust.py
gen_rust.py
@@ -206,8 +206,7 @@ func_rename = { # todo check if any "new" is required
"cv_UMat_type_const": "typ",
"cv_UMat_copyTo_const_Mat": "copy_to",
"cv_UMat_copyTo_const_Mat_Mat": "copy_to_masked",
- "cv_calcCovarMatrix_Mat_Mat_Mat_int_int": "calc_covar_matrix_arrays",
- "cv_calcCovarMatrix_const_Mat_int_Mat_Mat_int_int": "calc_covar_matrix",
+ "cv_calcCovarMatrix_const_Mat_int_Mat_Mat_int_int": "-", # duplicate of cv_calcCovarMatrix_Mat_Mat_Mat_int_int, but with pointers
"cv_clipLine_Size_Point_Point": "clip_line_size",
"cv_clipLine_Size2l_Point2l_Point2l": "clip_line_size_i64",
"cv_clipLine_Rect_Point_Point": "clip_line",
@@ -224,8 +223,7 @@ func_rename = { # todo check if any "new" is required
"cv_rectangle_Mat_Rect_Scalar_int_int_int": "rectangle",
"cv_repeat_Mat_int_int_Mat": "repeat_to",
"cv_repeat_Mat_int_int": "repeat",
- "cv_split_Mat_VectorOfMat": "split",
- "cv_split_Mat_Mat": "split_at",
+ "cv_split_Mat_Mat": "-", # duplicate of cv_split_Mat_VectorOfMat, but with pointers
"cv_getNumberOfCPUs": "get_number_of_cpus",
"cv_setImpl_int": "-",
"cv_setUseCollection_bool": "-",
@@ -779,7 +777,7 @@ class ArgInfo:
if len(arg_tuple) > 2:
self.defval = arg_tuple[2]
self.out = ""
- if typ in ("OutputArray", "OutputArrayOfArrays") or len(arg_tuple) > 3 and "/O" in arg_tuple[3]:
+ if typ in ("OutputArray", "OutputArrayOfArrays") or len(arg_tuple) > 3 and "/O" in arg_tuple[3] or self.type.is_by_ref and not self.type.is_const:
self.out = "O"
if typ in ("InputOutputArray", "InputOutputArrayOfArrays") or len(arg_tuple) > 3 and "/IO" in arg_tuple[3]:
self.out = "IO"
@@ -1569,10 +1567,12 @@ class TypeInfo(object):
:type is_output: bool
:rtype: str
"""
- if is_output:
- return "{}* {}".format(self.cpp_extern, var_name)
- if not self.is_by_ptr and self.is_by_ref and not self.is_const:
+ if not self.is_by_ptr:
+ if self.is_by_ref:
+ if not self.is_const:
return "{}& {}".format(self.cpp_extern, var_name)
+ elif is_output:
+ return "{}* {}".format(self.cpp_extern, var_name)
return "{} {}".format(self.cpp_extern, var_name)
def cpp_arg_func_call(self, var_name, is_output=False):
@@ -1788,9 +1788,6 @@ class BoxedClassTypeInfo(TypeInfo):
self.is_ignored = self.ci.is_ignored
self.rust_safe_id = self.ci.name
- def cpp_arg_func_decl(self, var_name, is_output=False):
- return super(BoxedClassTypeInfo, self).cpp_arg_func_decl(var_name, False)
-
def cpp_method_call_name(self, method_name):
return "reinterpret_cast<{}*>(instance)->{}".format(self.cpptype, method_name)

MODIFY
tests/dnn.rs
tests/dnn.rs
@@ -10,7 +10,7 @@ fn net() {
assert_eq!(params._type().unwrap(), "");
let blobs = params.blobs().unwrap();
assert_eq!(0, blobs.len());
- let res = net.add_layer("layer", "type", &params).unwrap();
+ let res = net.add_layer("layer", "type", &mut params).unwrap();
assert_ne!(-1, res);
assert!(!net.empty().unwrap());
}

MODIFY
tests/imgproc.rs
tests/imgproc.rs
use opencv::{
- core::{
- DataType,
- Mat,
- Scalar,
- Vec2f,
- },
+ core::{DataType, Mat, Point, Point2f, Scalar, Size, Vec2f},
imgproc,
+ types::VectorOfPoint,
};
-use opencv::core::Point2f;
#[test]
fn min_enclosing() {
@@ -22,3 +17,12 @@ fn min_enclosing() {
assert_eq!(radius, 5.0001);
assert_eq!(center, Point2f::new(15., 10.))
}
+
+#[test]
+fn ellipse() {
+ let mut pts = VectorOfPoint::new();
+ imgproc::ellipse_2_poly(Point::new(100, 100), Size::new(200, 200), 0, 45, 90, 10, &mut pts);
+ assert_eq!(6, pts.len());
+ assert_eq!(Point::new(241, 241), *pts.get(0));
+ assert_eq!(Point::new(100, 300), *pts.get(5));
+}

MODIFY
tests/mat.rs
tests/mat.rs
@@ -146,12 +146,25 @@ fn mat_operations() {
let mut src = VectorOfMat::new();
src.push(Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::all(1.)).unwrap());
src.push(Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::all(2.)).unwrap());
- let mut dst = Mat::default();
- core::merge(&src, &mut dst).unwrap();
- assert_eq!(dst.typ().unwrap(), Vec2b::typ());
- assert_eq!(dst.at_2d::<Vec2b>(0, 1).unwrap()[0], 1);
- assert_eq!(dst.at_2d::<Vec2b>(0, 2).unwrap()[1], 2);
+ let mut merged = Mat::default();
+ core::merge(&src, &mut merged).unwrap();
+ assert_eq!(merged.typ().unwrap(), Vec2b::typ());
+ assert_eq!(merged.at_2d::<Vec2b>(0, 1).unwrap()[0], 1);
+ assert_eq!(merged.at_2d::<Vec2b>(0, 2).unwrap()[1], 2);
+
+ let mut split = VectorOfMat::new();
+ core::split(&merged, &mut split).unwrap();
+ assert_eq!(2, split.len());
+ let mat = split.get(0);
+ assert_eq!(u8::typ(), mat.typ().unwrap());
+ assert_eq!(1, mat.channels().unwrap());
+ assert_eq!(1, *mat.at_2d::<u8>(0, 2).unwrap());
+ let mat = split.get(1);
+ assert_eq!(u8::typ(), mat.typ().unwrap());
+ assert_eq!(1, mat.channels().unwrap());
+ assert_eq!(2, *mat.at_2d::<u8>(0, 0).unwrap());
}
+
}

add support for more output arguments