Improve Input/OutputArray
MODIFY
binding-generator/src/string_ext.rs
binding-generator/src/string_ext.rs
@@ -334,15 +334,23 @@ pub trait StrExt {
impl StrExt for str {
fn to_snake_case(&self) -> String {
static R1: Lazy<Regex> = Lazy::new(|| Regex::new(r#"([^_])([A-Z][a-z]+)"#).expect("Can't compile regex"));
+ let out = R1.replace_all(self, "${1}_$2");
+
static R2: Lazy<Regex> = Lazy::new(|| Regex::new(r#"([a-z0-9])([A-Z])"#).expect("Can't compile regex"));
+ let out = R2.replace_all(&out, "${1}_$2");
+
static R3: Lazy<Regex> = Lazy::new(|| Regex::new(r#"\B([23])_(D)\b"#).expect("Can't compile regex"));
+ let out = R3.replace_all(&out, "_$1$2");
+
static R4: Lazy<Regex> = Lazy::new(|| Regex::new(r#"_(P[n3])_(P)"#).expect("Can't compile regex"));
+ let out = R4.replace_all(&out, "_$1$2");
+
static R5: Lazy<Regex> = Lazy::new(|| Regex::new(r#"Open_(CL|Gl|VX)"#).expect("Can't compile regex"));
- let out = R1.replace_all(self, "${1}_${2}");
- let out = R2.replace_all(&out, "${1}_${2}");
- let out = R3.replace_all(&out, "_${1}${2}");
- let out = R4.replace_all(&out, "_${1}${2}");
- let out = R5.replace_all(&out, "Open${1}");
+ let out = R5.replace_all(&out, "Open$1");
+
+ static R6: Lazy<Regex> = Lazy::new(|| Regex::new(r#"U_Mat"#).expect("Can't compile regex"));
+ let out = R6.replace_all(&out, "UMat");
+
out.to_lowercase()
}

MODIFY
binding-generator/src/test.rs
binding-generator/src/test.rs
@@ -393,7 +393,12 @@ fn detect_indent() {
#[test]
fn to_snake_case() {
- assert_eq!("get_path_to_application", "getPathToApplication".to_snake_case())
+ assert_eq!("get_path_to_application", "getPathToApplication".to_snake_case());
+ assert_eq!("solve_p3p", "solveP3P".to_snake_case());
+ assert_eq!("solve_pnp", "solvePnP".to_snake_case());
+ assert_eq!("reproject_image_to_3d", "reprojectImageTo3D".to_snake_case());
+ assert_eq!("filter_2d", "filter2D".to_snake_case());
+ assert_eq!("is_umat", "isUMat".to_snake_case());
}
#[test]

MODIFY
src/manual/core/input_output_array.rs
src/manual/core/input_output_array.rs
use std::os::raw::c_void;
use crate::{
- core::{_InputArray, _InputOutputArray, _InputOutputArrayTrait, _OutputArray},
+ core::{_InputArray, _InputArrayTrait, _InputOutputArray, _InputOutputArrayTrait, _OutputArray, _OutputArrayTrait},
Result,
sys,
};
@@ -50,19 +50,19 @@ pub trait ToInputOutputArray {
fn input_output_array(&mut self) -> Result<_InputOutputArray>;
}
-impl<T: _InputOutputArrayTrait> ToInputArray for T {
+impl<T: _InputArrayTrait> ToInputArray for T {
fn input_array(&self) -> Result<_InputArray> {
- extern "C" { fn cv_InputOutputArray_input_array(instance: *mut c_void) -> sys::Result<*mut c_void>; }
- unsafe { cv_InputOutputArray_input_array(self.as_raw__InputOutputArray()) }
+ extern "C" { fn cv_InputArray_input_array(instance: *mut c_void) -> sys::Result<*mut c_void>; }
+ unsafe { cv_InputArray_input_array(self.as_raw__InputArray()) }
.into_result()
.map(|ptr| _InputArray { ptr })
}
}
-impl<T: _InputOutputArrayTrait> ToOutputArray for T {
+impl<T: _OutputArrayTrait> ToOutputArray for T {
fn output_array(&mut self) -> Result<_OutputArray> {
- extern "C" { fn cv_InputOutputArray_output_array(instance: *mut c_void) -> sys::Result<*mut c_void>; }
- unsafe { cv_InputOutputArray_output_array(self.as_raw__InputOutputArray()) }
+ extern "C" { fn cv_OutputArray_output_array(instance: *mut c_void) -> sys::Result<*mut c_void>; }
+ unsafe { cv_OutputArray_output_array(self.as_raw__OutputArray()) }
.into_result()
.map(|ptr| _OutputArray { ptr })
}

MODIFY
src_cpp/manual-core.cpp
src_cpp/manual-core.cpp
@@ -5,13 +5,13 @@ template struct Result<cv::Size>;
template struct Result<const unsigned char*>;
extern "C" {
- Result<void*> cv_InputOutputArray_input_array(cv::_InputOutputArray* instance) {
+ Result<void*> cv_InputArray_input_array(cv::_InputArray* instance) {
try {
return Ok<void*>(new cv::_InputArray(*instance));
} OCVRS_CATCH(Result<void*>)
}
- Result<void*> cv_InputOutputArray_output_array(cv::_InputOutputArray* instance) {
+ Result<void*> cv_OutputArray_output_array(cv::_OutputArray* instance) {
try {
return Ok<void*>(new cv::_OutputArray(*instance));
} OCVRS_CATCH(Result<void*>)

MODIFY
tests/input_output_array.rs
tests/input_output_array.rs
use matches::assert_matches;
use opencv::{
- core::{self, Scalar, UMatUsageFlags},
+ core::{self, Matx12d, Scalar, ToInputArray, UMat, UMatUsageFlags},
prelude::*,
Result,
types::{VectorOff64, VectorOfu8},
@@ -11,6 +11,23 @@ use opencv::core::ACCESS_READ;
#[cfg(feature = "opencv-4")]
use opencv::core::AccessFlag::ACCESS_READ;
+#[test]
+fn input_array() -> Result<()> {
+ let mat = Mat::new_rows_cols_with_default(10, 10, u8::typ(), Scalar::all(1.))?;
+ let input_array = mat.input_array()?;
+ assert_eq!(Scalar::from(100.), core::sum_elems(&input_array)?);
+ Ok(())
+}
+
+#[test]
+fn input_output_array_types() -> Result<()> {
+ assert!(Mat::default()?.input_array()?.is_mat()?);
+ assert!(VectorOfu8::new().input_array()?.is_vector()?);
+ assert!(Matx12d::default().input_array()?.is_matx()?);
+ assert!(UMat::new_rows_cols_with_default(1, 1, u8::typ(), Scalar::from(8.), UMatUsageFlags::USAGE_DEFAULT)?.input_array()?.is_umat()?);
+ Ok(())
+}
+
#[test]
fn input_output_array() -> Result<()> {
{
@@ -18,7 +35,7 @@ fn input_output_array() -> Result<()> {
let umat = Mat::new_rows_cols_with_default(1, 3, u8::typ(), Scalar::all(3.))?.get_umat(ACCESS_READ, UMatUsageFlags::USAGE_DEFAULT)?;
{
let mut trg = VectorOfu8::new();
- core::add(&mat_expr, &umat, &mut trg, &Mat::default()?, -1)?;
+ core::add(&mat_expr, &umat, &mut trg, &core::no_array()?, -1)?;
assert_eq!(3, trg.len());
assert_eq!(4, trg.get(0)?);
assert_eq!(4, trg.get(1)?);
@@ -27,7 +44,7 @@ fn input_output_array() -> Result<()> {
{
let mut trg = VectorOfu8::new();
- core::add(&&mat_expr, &&umat, &mut &mut trg, &Mat::default()?, -1)?;
+ core::add(&&mat_expr, &&umat, &mut &mut trg, &core::no_array()?, -1)?;
assert_eq!(3, trg.len());
assert_eq!(4, trg.get(0)?);
assert_eq!(4, trg.get(1)?);
@@ -37,7 +54,7 @@ fn input_output_array() -> Result<()> {
{
let mut t = VectorOff64::new();
- core::add(&2.5, &4., &mut t, &Mat::default()?, -1)?;
+ core::add(&2.5, &4., &mut t, &core::no_array()?, -1)?;
assert_eq!(6.5, t.get(0)?);
}

Improve Input/OutputArray