0.25.0 add support for using Scalar as InputArray
MODIFY
Cargo.toml
Cargo.toml
@@ -6,7 +6,7 @@ repository = "https://github.com/twistedfall/opencv-rust"
readme = "README.md"
keywords = [ "opencv", "vision" ]
license = "MIT"
-version = "0.24.5"
+version = "0.25.0"
edition = "2018"
authors = ["Mathieu Poumeyrol <kali@zoy.org>", "Pro <twisted.fall@gmail.com>"]
build = "build.rs"

MODIFY
README.md
README.md
@@ -36,17 +36,17 @@ files or `-dev` packages.
Update your Cargo.toml
```toml
-opencv = "0.24"
+opencv = "0.25"
```
Select OpenCV version if different from default in Cargo.toml:
```toml
-opencv = {version = "0.24", default-features = false, features = ["opencv-41"]}
+opencv = {version = "0.25", default-features = false, features = ["opencv-41"]}
```
And enable usage of `contrib` modules:
```toml
-opencv = {version = "0.24", default-features = false, features = ["opencv-41", "contrib"]}
+opencv = {version = "0.25", default-features = false, features = ["opencv-41", "contrib"]}
```
Import prelude

MODIFY
src/manual/core/vec.rs
src/manual/core/vec.rs
use std::ops::{Deref, DerefMut};
+use crate::{
+ core::{_InputArray, ToInputArray},
+ Result,
+ sys,
+};
+
pub use self::{scalar::ValidScalarType, vec::ValidVecType};
// additional modules needed because valid_types! introduces module named "private"
@@ -63,3 +69,22 @@ impl<T: ValidScalarType> Scalar_<T> {
Self([v0, v1, v2, v3])
}
}
+
+impl ToInputArray for Scalar_<f64> {
+ fn input_array(&self) -> Result<_InputArray> {
+ let me = self;
+ cpp!(unsafe [me as "const ScalarWrapper*"] -> sys::cv_return_value_const_void_X as "cv_return_value_void_X" {
+ try {
+ return { Error::Code::StsOk, NULL, new _InputArray(*reinterpret_cast<const cv::Scalar*>(me)) };
+ } CVRS_CATCH(cv_return_value_void_X)
+ }).into_result()
+ .map(|ptr| _InputArray { ptr })
+ }
+}
+
+impl ToInputArray for &Scalar_<f64> {
+ #[inline]
+ fn input_array(&self) -> Result<_InputArray> {
+ (*self).input_array()
+ }
+}

MODIFY
tests/core.rs
tests/core.rs
use opencv::{
- core::{self, CV_32S, CV_32SC3, CV_64F, CV_64FC1, CV_8U, CV_8UC2, MAKETYPE, Moments},
- core::{Point2f, RotatedRect, Size2f},
+ core::{self, CV_32S, CV_32SC3, CV_64F, CV_64FC1, CV_8U, CV_8UC2, MAKETYPE, Moments, Point2f, RotatedRect, Scalar, Size2f},
+ prelude::*,
Result,
+ types::VectorOfMat,
};
#[test]
@@ -39,3 +40,24 @@ fn rotated_rect() -> Result<()> {
assert_eq!(Point2f::new(50., 150.), pts[3]);
Ok(())
}
+
+#[test]
+fn in_range() -> Result<()> {
+ let mut cs = VectorOfMat::new();
+ cs.push(Mat::from_slice_2d(&[
+ &[1., 2., 3.],
+ &[4., 5., 6.],
+ &[7., 8., 9.],
+ ])?);
+ cs.push(Mat::from_slice_2d(&[
+ &[11., 12., 13.],
+ &[14., 15., 16.],
+ &[17., 18., 19.],
+ ])?);
+ let mut m = Mat::default()?;
+ core::merge(&cs, &mut m)?;
+ let mut out = Mat::default()?;
+ core::in_range(&m, &Scalar::new(2., 10., 0., 0.), &Scalar::new(6., 15., 0., 0.), &mut out)?;
+ assert_eq!(&[0, 255, 255, 255, 255, 0, 0, 0, 0], &out.data_typed::<u8>()?);
+ Ok(())
+}

0.25.0 add support for using Scalar as InputArray