allow converting instance of _InputOutputArray to underlying classes, fixes
MODIFY
src/manual/core/input_output_array.rs
src/manual/core/input_output_array.rs
use crate::{
- core::{_InputArray, _InputOutputArray, _OutputArray},
+ core::{_InputArray, _InputOutputArray, _InputOutputArrayTrait, _OutputArray},
Result,
+ sys,
};
/// Trait to serve as a replacement for `InputArray` in C++ OpenCV
@@ -46,3 +47,39 @@ pub trait ToOutputArray {
pub trait ToInputOutputArray {
fn input_output_array(&mut self) -> Result<_InputOutputArray>;
}
+
+impl<T: _InputOutputArrayTrait> ToInputArray for T {
+ fn input_array(&self) -> Result<_InputArray> {
+ let me = self.as_raw__InputOutputArray();
+ cpp!(unsafe [me as "cv::_InputOutputArray*"] -> sys::cv_return_value_const_void_X as "cv_return_value_const_void_X" {
+ try {
+ return { Error::Code::StsOk, NULL, new _InputArray(*me) };
+ } CVRS_CATCH(cv_return_value_const_void_X)
+ }).into_result()
+ .map(|ptr| _InputArray { ptr })
+ }
+}
+
+impl ToOutputArray for _InputOutputArray {
+ fn output_array(&mut self) -> Result<_OutputArray> {
+ let me = self.as_raw__InputOutputArray();
+ cpp!(unsafe [me as "cv::_InputOutputArray*"] -> sys::cv_return_value_const_void_X as "cv_return_value_const_void_X" {
+ try {
+ return { Error::Code::StsOk, NULL, new _OutputArray(*me) };
+ } CVRS_CATCH(cv_return_value_const_void_X)
+ }).into_result()
+ .map(|ptr| _OutputArray { ptr })
+ }
+}
+
+impl ToInputOutputArray for _InputOutputArray {
+ fn input_output_array(&mut self) -> Result<_InputOutputArray> {
+ let me = self.as_raw__InputOutputArray();
+ cpp!(unsafe [me as "cv::_InputOutputArray*"] -> sys::cv_return_value_const_void_X as "cv_return_value_const_void_X" {
+ try {
+ return { Error::Code::StsOk, NULL, new _InputOutputArray(*me) };
+ } CVRS_CATCH(cv_return_value_const_void_X)
+ }).into_result()
+ .map(|ptr| _InputOutputArray { ptr })
+ }
+}

MODIFY
tests/input_output_array.rs
tests/input_output_array.rs
+use matches::assert_matches;
+
use opencv::{
core::{self, Mat, Scalar, UMatUsageFlags},
prelude::*,
@@ -58,3 +60,13 @@ fn input_output_array() -> Result<()> {
Ok(())
}
+
+#[test]
+fn no_array() -> Result<()> {
+ use self::core::no_array;
+ assert_eq!(Scalar::all(0.), core::sum(&no_array()?)?);
+ assert_matches!(core::complete_symm(&mut no_array()?, false), Ok(()));
+ let m = Mat::new_rows_cols_with_default(1, 1, u16::typ(), Scalar::all(0.))?;
+ assert_matches!(core::mean_std_dev(&m, &mut no_array()?, &mut no_array()?, &no_array()?), Ok(()));
+ Ok(())
+}

allow converting instance of _InputOutputArray to underlying classes, fixes #62