Skip to content

Commit 84f76c2

Browse files
committed
Cleanup
1 parent b9565e7 commit 84f76c2

File tree

14 files changed

+89
-77
lines changed

14 files changed

+89
-77
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
semantics.
1010
* Some constructors have received `_mut` suffix where appropriate.
1111
* Unsafe `Mat` constructors (`*_with_data`) have received `_unsafe` suffix and safe versions have been introduced that return
12-
`BoxedRef`/`BoxedRefMut`
12+
`BoxedRef`/`BoxedRefMut`. Consequently, `Mat::from_slice_rows_cols` was replaced by `Mat::new_rows_cols_with_data`, note the
13+
different order and types of the arguments.
1314
* `MatSize::new` is now unsafe and accepts a pointer.
1415

1516
* 0.90.0

binding-generator/src/element.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ impl DefaultElement {
6060
| EntityKind::ClassTemplate
6161
| EntityKind::ClassTemplatePartialSpecialization
6262
| EntityKind::FunctionTemplate
63-
| EntityKind::Method => {
63+
| EntityKind::Method
64+
| EntityKind::FunctionDecl => {
6465
// handle anonymous enums inside classes and anonymous namespaces
6566
if let Some(parent_name) = parent.get_name() {
6667
parts.push(parent_name);

binding-generator/src/func.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl Element for Func<'_, '_> {
629629
};
630630
is_unavailable
631631
|| settings::FUNC_EXCLUDE.contains(identifier.as_str())
632-
|| (self.is_generic())
632+
|| self.is_generic()
633633
|| self.arguments().iter().any(|a| a.type_ref().exclude_kind().is_ignored())
634634
|| kind.as_operator().map_or(false, |(_, kind)| match kind {
635635
OperatorKind::Unsupported => true,

binding-generator/src/settings.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ pub static PRIMITIVE_TYPEDEFS: Lazy<HashMap<&str, (&str, &str)>> = Lazy::new(||
8585

8686
pub static STATIC_MODULES: Lazy<BTreeSet<&str>> = Lazy::new(|| BTreeSet::from(["core", "sys", "types"]));
8787

88+
/// Types that can be used as `Mat` element
89+
/// cpp_name(Reference)
8890
pub static DATA_TYPES: Lazy<HashSet<&str>> = Lazy::new(|| {
8991
HashSet::from([
9092
"unsigned char",

ci/msrv.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ rustc --version
1010
rustc --print=cfg
1111

1212
cargo update
13-
rm -vf examples/cuda.rs # no CUDA support in CI
1413
cargo check -vv --all-targets --all-features --workspace --tests

ci/script.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ if [[ "${OPENCV_VERSION:-}" != "4.9.0" ]]; then
5353
rm -vf tests/*_only_latest_opencv.rs
5454
rm -vf examples/dnn_face_detect.rs examples/gapi_api_example.rs examples/text_detection.rs
5555
fi
56-
# the following examples don't work in CI
57-
rm -vf examples/cuda.rs
5856

5957
echo "=== Current directory: $(pwd)"
6058
echo "=== Environment variable dump:"

examples/cuda.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::{env, time};
2+
use time::Instant;
23

3-
use opencv::core::{GpuMat, Size};
4+
use opencv::core::Size;
45
use opencv::prelude::*;
5-
use opencv::{core, cudafilters, cudaimgproc, imgcodecs, imgproc, Result};
6+
use opencv::{core, imgcodecs, imgproc, Result};
67

78
const ITERATIONS: usize = 100;
89

@@ -25,40 +26,36 @@ fn main() -> Result<()> {
2526
}
2627
);
2728
println!("Timing CPU implementation... ");
28-
let img = imgcodecs::imread(&img_file, imgcodecs::IMREAD_COLOR)?;
29-
let start = time::Instant::now();
29+
let img = imgcodecs::imread_def(&img_file)?;
30+
let start = Instant::now();
3031
for _ in 0..ITERATIONS {
3132
let mut gray = Mat::default();
32-
imgproc::cvt_color(&img, &mut gray, imgproc::COLOR_BGR2GRAY, 0)?;
33+
imgproc::cvt_color_def(&img, &mut gray, imgproc::COLOR_BGR2GRAY)?;
3334
let mut blurred = Mat::default();
34-
imgproc::gaussian_blur(&gray, &mut blurred, Size::new(7, 7), 1.5, 0., core::BORDER_DEFAULT)?;
35+
imgproc::gaussian_blur_def(&gray, &mut blurred, Size::new(7, 7), 1.5)?;
3536
let mut edges = Mat::default();
36-
imgproc::canny(&blurred, &mut edges, 0., 50., 3, false)?;
37+
imgproc::canny_def(&blurred, &mut edges, 0., 50.)?;
3738
}
3839
println!("{:#?}", start.elapsed());
40+
#[cfg(all(ocvrs_has_module_cudafilters, ocvrs_has_module_cudaimgproc))]
3941
if cuda_available {
42+
use opencv::core::GpuMat;
43+
use opencv::{cudafilters, cudaimgproc};
44+
4045
println!("Timing CUDA implementation... ");
41-
let img = imgcodecs::imread(&img_file, imgcodecs::IMREAD_COLOR)?;
46+
let img = imgcodecs::imread_def(&img_file)?;
4247
let mut img_gpu = GpuMat::new_def()?;
4348
img_gpu.upload(&img)?;
4449
let mut stream = core::Stream::default()?;
45-
let start = time::Instant::now();
50+
let start = Instant::now();
4651
for _ in 0..ITERATIONS {
4752
let mut gray = GpuMat::new_def()?;
4853
cudaimgproc::cvt_color(&img_gpu, &mut gray, imgproc::COLOR_BGR2GRAY, 0, &mut stream)?;
4954
let mut blurred = GpuMat::new_def()?;
50-
let mut filter = cudafilters::create_gaussian_filter(
51-
gray.typ()?,
52-
blurred.typ()?,
53-
Size::new(7, 7),
54-
1.5,
55-
0.,
56-
core::BORDER_DEFAULT,
57-
core::BORDER_DEFAULT,
58-
)?;
55+
let mut filter = cudafilters::create_gaussian_filter_def(gray.typ()?, blurred.typ()?, Size::new(7, 7), 1.5)?;
5956
filter.apply(&gray, &mut blurred, &mut stream)?;
6057
let mut edges = GpuMat::new_def()?;
61-
let mut detector = cudaimgproc::create_canny_edge_detector(0., 50., 3, false)?;
58+
let mut detector = cudaimgproc::create_canny_edge_detector_def(0., 50.)?;
6259
detector.detect(&blurred, &mut edges, &mut stream)?;
6360
stream.wait_for_completion()?;
6461
}

src/manual/core/input_output_array.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -194,80 +194,56 @@ impl<const N: usize> ToInputArray for [u8; N] {
194194
}
195195
}
196196

197-
impl<T> ToInputArray for BoxedRef<'_, T>
198-
where
199-
T: Boxed + ToInputArray,
200-
{
197+
impl<T: Boxed + ToInputArray> ToInputArray for BoxedRef<'_, T> {
201198
#[inline]
202199
fn input_array(&self) -> Result<BoxedRef<_InputArray>> {
203200
self.reference.input_array()
204201
}
205202
}
206203

207-
impl<T> ToInputArray for &BoxedRef<'_, T>
208-
where
209-
T: Boxed + ToInputArray,
210-
{
204+
impl<T: Boxed + ToInputArray> ToInputArray for &BoxedRef<'_, T> {
211205
#[inline]
212206
fn input_array(&self) -> Result<BoxedRef<_InputArray>> {
213207
(*self).input_array()
214208
}
215209
}
216210

217-
impl<T> ToInputArray for BoxedRefMut<'_, T>
218-
where
219-
T: Boxed + ToInputArray,
220-
{
211+
impl<T: Boxed + ToInputArray> ToInputArray for BoxedRefMut<'_, T> {
221212
#[inline]
222213
fn input_array(&self) -> Result<BoxedRef<_InputArray>> {
223214
self.reference.input_array()
224215
}
225216
}
226217

227-
impl<T> ToInputArray for &BoxedRefMut<'_, T>
228-
where
229-
T: Boxed + ToInputArray,
230-
{
218+
impl<T: Boxed + ToInputArray> ToInputArray for &BoxedRefMut<'_, T> {
231219
#[inline]
232220
fn input_array(&self) -> Result<BoxedRef<_InputArray>> {
233221
(*self).input_array()
234222
}
235223
}
236224

237-
impl<T> ToOutputArray for BoxedRefMut<'_, T>
238-
where
239-
T: Boxed + ToOutputArray,
240-
{
225+
impl<T: Boxed + ToOutputArray> ToOutputArray for BoxedRefMut<'_, T> {
241226
#[inline]
242227
fn output_array(&mut self) -> Result<BoxedRefMut<_OutputArray>> {
243228
self.reference.output_array()
244229
}
245230
}
246231

247-
impl<T> ToOutputArray for &mut BoxedRefMut<'_, T>
248-
where
249-
T: Boxed + ToOutputArray,
250-
{
232+
impl<T: Boxed + ToOutputArray> ToOutputArray for &mut BoxedRefMut<'_, T> {
251233
#[inline]
252234
fn output_array(&mut self) -> Result<BoxedRefMut<_OutputArray>> {
253235
(*self).output_array()
254236
}
255237
}
256238

257-
impl<T> ToInputOutputArray for BoxedRefMut<'_, T>
258-
where
259-
T: Boxed + ToInputOutputArray,
260-
{
239+
impl<T: Boxed + ToInputOutputArray> ToInputOutputArray for BoxedRefMut<'_, T> {
261240
#[inline]
262241
fn input_output_array(&mut self) -> Result<BoxedRefMut<_InputOutputArray>> {
263242
self.reference.input_output_array()
264243
}
265244
}
266245

267-
impl<T> ToInputOutputArray for &mut BoxedRefMut<'_, T>
268-
where
269-
T: Boxed + ToInputOutputArray,
270-
{
246+
impl<T: Boxed + ToInputOutputArray> ToInputOutputArray for &mut BoxedRefMut<'_, T> {
271247
#[inline]
272248
fn input_output_array(&mut self) -> Result<BoxedRefMut<_InputOutputArray>> {
273249
(*self).input_output_array()

src/manual/core/mat.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ fn match_is_continuous(mat: &(impl MatTraitConst + ?Sized)) -> Result<()> {
100100

101101
#[inline]
102102
fn match_length(sizes: &[i32], len: usize) -> Result<()> {
103+
if sizes.is_empty() {
104+
return Err(Error::new(core::StsUnmatchedSizes, "Dimensions must not be empty"));
105+
}
103106
let data_len = i32::try_from(len)?;
104107
if sizes.iter().product::<i32>() != data_len {
105108
let msg = if sizes.len() == 2 {
106109
format!(
107-
"The length of the slice: {data_len} must match the passed row count: {rows} and column count: {cols} exactly",
110+
"The length of the slice: {data_len} must match the passed row: {rows} and column: {cols} counts exactly",
108111
rows = sizes[0],
109112
cols = sizes[1],
110113
)
@@ -204,7 +207,7 @@ impl Mat {
204207
Ok(out)
205208
}
206209

207-
/// Create a new `Mat` from a single-dimensional slice with custom shape
210+
/// Create a new `Mat` that references a single-dimensional slice with custom shape
208211
#[inline]
209212
pub fn new_rows_cols_with_data<T: DataType>(rows: i32, cols: i32, data: &[T]) -> Result<BoxedRef<Self>> {
210213
match_length(&[rows, cols], data.len())?;
@@ -214,6 +217,7 @@ impl Mat {
214217
Ok(<BoxedRef<Mat>>::from(m))
215218
}
216219

220+
/// Create a new `Mat` that references a single-dimensional slice with custom shape
217221
#[inline]
218222
pub fn new_rows_cols_with_data_mut<T: DataType>(rows: i32, cols: i32, data: &mut [T]) -> Result<BoxedRefMut<Self>> {
219223
match_length(&[rows, cols], data.len())?;
@@ -222,27 +226,31 @@ impl Mat {
222226
Ok(<BoxedRefMut<Mat>>::from(m))
223227
}
224228

229+
/// Create a new `Mat` that references a single-dimensional slice with custom shape
225230
#[inline]
226231
pub fn new_size_with_data<T: DataType>(size: Size, data: &[T]) -> Result<BoxedRef<Self>> {
227232
match_length(&[size.width, size.height], data.len())?;
228233
let m = unsafe { Self::new_size_with_data_unsafe_def(size, T::opencv_type(), data.as_ptr().cast::<c_void>().cast_mut()) }?;
229234
Ok(<BoxedRef<Mat>>::from(m))
230235
}
231236

237+
/// Create a new `Mat` that references a single-dimensional slice with custom shape
232238
#[inline]
233239
pub fn new_size_with_data_mut<T: DataType>(size: Size, data: &mut [T]) -> Result<BoxedRefMut<Self>> {
234240
match_length(&[size.width, size.height], data.len())?;
235241
let m = unsafe { Self::new_size_with_data_unsafe_def(size, T::opencv_type(), data.as_mut_ptr().cast::<c_void>()) }?;
236242
Ok(<BoxedRefMut<Mat>>::from(m))
237243
}
238244

245+
/// Create a new `Mat` that references a single-dimensional slice with custom shape
239246
#[inline]
240247
pub fn new_nd_with_data<'data, T: DataType>(sizes: &[i32], data: &'data [T]) -> Result<BoxedRef<'data, Self>> {
241248
match_length(sizes, data.len())?;
242249
let m = unsafe { Self::new_nd_with_data_unsafe_def(sizes, T::opencv_type(), data.as_ptr().cast::<c_void>().cast_mut()) }?;
243250
Ok(<BoxedRef<Mat>>::from(m))
244251
}
245252

253+
/// Create a new `Mat` that references a single-dimensional slice with custom shape
246254
#[inline]
247255
pub fn new_nd_with_data_mut<'data, T: DataType>(sizes: &[i32], data: &'data mut [T]) -> Result<BoxedRefMut<'data, Self>> {
248256
match_length(sizes, data.len())?;

src/manual/core/vector/vector_extern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::core::Vector;
22
use crate::platform_types::size_t;
33
use crate::traits::OpenCVType;
4-
use crate::{extern_arg_send, extern_container_send, extern_receive, extern_send};
4+
use crate::{extern_arg_send, extern_container_send, extern_receive};
55

66
/// This trait is implemented by any type that can be stored inside `Vector`.
77
///

0 commit comments

Comments
 (0)