Skip to content

Commit 49d441b

Browse files
author
admin
committed
CI
1 parent 66aab52 commit 49d441b

File tree

5 files changed

+62
-64
lines changed

5 files changed

+62
-64
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ jobs:
7171
run: bash scripts/linux_ffmpeg.rs
7272

7373
- name: export ffmpeg env
74-
run: |
75-
export FFMPEG_INCLUDE_DIR=${PWD}/tmp/ffmpeg_build/include
76-
export FFMPEG_PKG_CONFIG_PATH=${PWD}/tmp/ffmpeg_build/lib/pkgconfig
74+
run: export FFMPEG_INCLUDE_DIR=${PWD}/tmp/ffmpeg_build/include
7775

7876
- name: Setup Rust
7977
uses: dtolnay/rust-toolchain@stable

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ ndarray = { version = '0.16', default-features = true, optional = true }
4444
imageproc = { version = '0.25', default-features = true, optional = true }
4545
tch = { version = '0.18', default-features = true, optional = true}
4646
opencv = { version = '0.94', default-features = true, optional = true, features = ["clang-runtime"] }
47-
rsmpeg = { git = "https://github.com/larksuite/rsmpeg", branch = "master", default-features = true, optional = true }
47+
rsmpeg = { git = "https://github.com/larksuite/rsmpeg", branch = "master", optional = true, features = [
48+
"ffmpeg7", "link_system_ffmpeg"
49+
] }

src/with_opencv_ndarray.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
use crate::with_opencv::{MatExt as _, OpenCvElement};
22
use crate::{FromCv, IntoCv, TryFromCv, TryIntoCv};
33
use anyhow::Result;
4-
use ndarray as nd;
54
use opencv::prelude::*;
65

7-
impl<'a, A, D> TryFromCv<&'a Mat> for nd::ArrayView<'a, A, D>
6+
impl<'a, A, D> TryFromCv<&'a Mat> for ndarray::ArrayView<'a, A, D>
87
where
98
A: OpenCvElement,
10-
D: nd::Dimension,
9+
D: ndarray::Dimension,
1110
{
1211
type Error = anyhow::Error;
1312

1413
fn try_from_cv(from: &'a Mat) -> Result<Self, Self::Error> {
1514
let src_shape = from.size_with_depth();
16-
let array = nd::ArrayViewD::from_shape(src_shape, from.as_slice()?)?;
15+
let array = ndarray::ArrayViewD::from_shape(src_shape, from.as_slice()?)?;
1716
let array = array.into_dimensionality()?;
1817
Ok(array)
1918
}
2019
}
2120

22-
impl<A, D> TryFromCv<&Mat> for nd::Array<A, D>
21+
impl<A, D> TryFromCv<&Mat> for ndarray::Array<A, D>
2322
where
2423
A: OpenCvElement + Clone,
25-
D: nd::Dimension,
24+
D: ndarray::Dimension,
2625
{
2726
type Error = anyhow::Error;
2827

2928
fn try_from_cv(from: &Mat) -> Result<Self, Self::Error> {
3029
let src_shape = from.size_with_depth();
31-
let array = nd::ArrayViewD::from_shape(src_shape, from.as_slice()?)?;
30+
let array = ndarray::ArrayViewD::from_shape(src_shape, from.as_slice()?)?;
3231
let array = array.into_dimensionality()?;
3332
let array = array.into_owned();
3433
Ok(array)
3534
}
3635
}
3736

38-
impl<A, D> TryFromCv<Mat> for nd::Array<A, D>
37+
impl<A, D> TryFromCv<Mat> for ndarray::Array<A, D>
3938
where
4039
A: OpenCvElement + Clone,
41-
D: nd::Dimension,
40+
D: ndarray::Dimension,
4241
{
4342
type Error = anyhow::Error;
4443

@@ -47,15 +46,15 @@ where
4746
}
4847
}
4948

50-
impl<A, S, D> TryFromCv<&nd::ArrayBase<S, D>> for Mat
49+
impl<A, S, D> TryFromCv<&ndarray::ArrayBase<S, D>> for Mat
5150
where
5251
A: DataType,
53-
S: nd::RawData<Elem = A> + nd::Data,
54-
D: nd::Dimension,
52+
S: ndarray::RawData<Elem = A> + ndarray::Data,
53+
D: ndarray::Dimension,
5554
{
5655
type Error = anyhow::Error;
5756

58-
fn try_from_cv(from: &nd::ArrayBase<S, D>) -> Result<Self> {
57+
fn try_from_cv(from: &ndarray::ArrayBase<S, D>) -> Result<Self> {
5958
let shape_with_channels: Vec<i32> = from.shape().iter().map(|&sz| sz as i32).collect();
6059
let (channels, shape) = match shape_with_channels.split_last() {
6160
Some(split) => split,
@@ -72,15 +71,15 @@ where
7271
}
7372
}
7473

75-
impl<A, S, D> TryFromCv<nd::ArrayBase<S, D>> for Mat
74+
impl<A, S, D> TryFromCv<ndarray::ArrayBase<S, D>> for Mat
7675
where
7776
A: DataType,
78-
S: nd::RawData<Elem = A> + nd::Data,
79-
D: nd::Dimension,
77+
S: ndarray::RawData<Elem = A> + ndarray::Data,
78+
D: ndarray::Dimension,
8079
{
8180
type Error = anyhow::Error;
8281

83-
fn try_from_cv(from: nd::ArrayBase<S, D>) -> Result<Self> {
82+
fn try_from_cv(from: ndarray::ArrayBase<S, D>) -> Result<Self> {
8483
(&from).try_into_cv()
8584
}
8685
}
@@ -102,8 +101,8 @@ mod tests {
102101
let shape: Vec<usize> = (0..ndim).map(|_| rng.random_range(1..=32)).collect();
103102

104103
let in_mat = Mat::new_randn_nd::<f32>(&shape)?;
105-
let view: nd::ArrayViewD<f32> = (&in_mat).try_into_cv()?;
106-
let array: nd::ArrayD<f32> = (&in_mat).try_into_cv()?;
104+
let view: ndarray::ArrayViewD<f32> = (&in_mat).try_into_cv()?;
105+
let array: ndarray::ArrayD<f32> = (&in_mat).try_into_cv()?;
107106
let out_mat: Mat = (&array).try_into_cv()?;
108107

109108
shape
@@ -116,15 +115,15 @@ mod tests {
116115
let e1: f32 = *in_mat.at_nd(&index_cv)?;
117116

118117
// It adds an extra dimension for Mat ->
119-
// nd::ArrayView conversion.
118+
// ndarray::ArrayView conversion.
120119
let index_nd: Vec<_> = chain!(index, [0]).collect();
121120
let e2 = view[index_nd.as_slice()];
122121

123-
// It adds an extra dimension for Mat -> nd::Array
122+
// It adds an extra dimension for Mat -> ndarray::Array
124123
// conversion.
125124
let e3 = array[index_nd.as_slice()];
126125

127-
// Ensure the path Mat -> nd::Array -> Mat
126+
// Ensure the path Mat -> ndarray::Array -> Mat
128127
// preserves the values.
129128
let e4: f32 = *out_mat.at_nd(&index_cv)?;
130129

src/with_tch_image.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ impl TryFromCv<&image::DynamicImage> for TchTensorAsImage {
3636
type Error = Error;
3737

3838
fn try_from_cv(from: &image::DynamicImage) -> Result<Self, Self::Error> {
39-
use image::DynamicImage as D;
39+
use image::DynamicImage;
4040

4141
let tensor = match from {
42-
D::ImageLuma8(image) => image.into_cv(),
43-
D::ImageLumaA8(image) => image.into_cv(),
44-
D::ImageRgb8(image) => image.into_cv(),
45-
D::ImageRgba8(image) => image.into_cv(),
46-
D::ImageRgb32F(image) => image.into_cv(),
47-
D::ImageRgba32F(image) => image.into_cv(),
42+
DynamicImage::ImageLuma8(image) => image.into_cv(),
43+
DynamicImage::ImageLumaA8(image) => image.into_cv(),
44+
DynamicImage::ImageRgb8(image) => image.into_cv(),
45+
DynamicImage::ImageRgba8(image) => image.into_cv(),
46+
DynamicImage::ImageRgb32F(image) => image.into_cv(),
47+
DynamicImage::ImageRgba32F(image) => image.into_cv(),
4848
_ => anyhow::bail!("the color type {:?} is not supported", from.color()),
4949
};
5050
Ok(tensor)

src/with_tch_ndarray.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
use crate::{FromCv, TryFromCv};
22
use anyhow::{Error, Result};
3-
use ndarray as nd;
43

54
use to_ndarray_shape::*;
65
mod to_ndarray_shape {
76
use super::*;
87

98
pub trait ToNdArrayShape<D>
109
where
11-
Self::Output: Sized + Into<nd::StrideShape<D>>,
10+
Self::Output: Sized + Into<ndarray::StrideShape<D>>,
1211
{
1312
type Output;
1413
type Error;
1514

1615
fn to_ndarray_shape(&self) -> Result<Self::Output, Self::Error>;
1716
}
1817

19-
impl ToNdArrayShape<nd::IxDyn> for Vec<i64> {
18+
impl ToNdArrayShape<ndarray::IxDyn> for Vec<i64> {
2019
type Output = Vec<usize>;
2120
type Error = Error;
2221

@@ -26,7 +25,7 @@ mod to_ndarray_shape {
2625
}
2726
}
2827

29-
impl ToNdArrayShape<nd::Ix0> for Vec<i64> {
28+
impl ToNdArrayShape<ndarray::Ix0> for Vec<i64> {
3029
type Output = [usize; 0];
3130
type Error = Error;
3231

@@ -40,7 +39,7 @@ mod to_ndarray_shape {
4039
}
4140
}
4241

43-
impl ToNdArrayShape<nd::Ix1> for Vec<i64> {
42+
impl ToNdArrayShape<ndarray::Ix1> for Vec<i64> {
4443
type Output = [usize; 1];
4544
type Error = Error;
4645

@@ -53,7 +52,7 @@ mod to_ndarray_shape {
5352
}
5453
}
5554

56-
impl ToNdArrayShape<nd::Ix2> for Vec<i64> {
55+
impl ToNdArrayShape<ndarray::Ix2> for Vec<i64> {
5756
type Output = [usize; 2];
5857
type Error = Error;
5958

@@ -66,7 +65,7 @@ mod to_ndarray_shape {
6665
}
6766
}
6867

69-
impl ToNdArrayShape<nd::Ix3> for Vec<i64> {
68+
impl ToNdArrayShape<ndarray::Ix3> for Vec<i64> {
7069
type Output = [usize; 3];
7170
type Error = Error;
7271

@@ -79,7 +78,7 @@ mod to_ndarray_shape {
7978
}
8079
}
8180

82-
impl ToNdArrayShape<nd::Ix4> for Vec<i64> {
81+
impl ToNdArrayShape<ndarray::Ix4> for Vec<i64> {
8382
type Output = [usize; 4];
8483
type Error = Error;
8584

@@ -92,7 +91,7 @@ mod to_ndarray_shape {
9291
}
9392
}
9493

95-
impl ToNdArrayShape<nd::Ix5> for Vec<i64> {
94+
impl ToNdArrayShape<ndarray::Ix5> for Vec<i64> {
9695
type Output = [usize; 5];
9796
type Error = Error;
9897

@@ -111,7 +110,7 @@ mod to_ndarray_shape {
111110
}
112111
}
113112

114-
impl ToNdArrayShape<nd::Ix6> for Vec<i64> {
113+
impl ToNdArrayShape<ndarray::Ix6> for Vec<i64> {
115114
type Output = [usize; 6];
116115
type Error = Error;
117116

@@ -132,9 +131,9 @@ mod to_ndarray_shape {
132131
}
133132
}
134133

135-
impl<A, D> TryFromCv<tch::Tensor> for nd::Array<A, D>
134+
impl<A, D> TryFromCv<tch::Tensor> for ndarray::Array<A, D>
136135
where
137-
D: nd::Dimension,
136+
D: ndarray::Dimension,
138137
A: tch::kind::Element,
139138
Vec<A>: TryFrom<tch::Tensor, Error = tch::TchError>,
140139
Vec<i64>: ToNdArrayShape<D, Error = Error>,
@@ -158,9 +157,9 @@ where
158157
}
159158
}
160159

161-
impl<A, D> TryFromCv<&tch::Tensor> for nd::Array<A, D>
160+
impl<A, D> TryFromCv<&tch::Tensor> for ndarray::Array<A, D>
162161
where
163-
D: nd::Dimension,
162+
D: ndarray::Dimension,
164163
A: tch::kind::Element,
165164
Vec<A>: TryFrom<tch::Tensor, Error = tch::TchError>,
166165
Vec<i64>: ToNdArrayShape<D, Error = Error>,
@@ -172,13 +171,13 @@ where
172171
}
173172
}
174173

175-
impl<A, S, D> FromCv<&nd::ArrayBase<S, D>> for tch::Tensor
174+
impl<A, S, D> FromCv<&ndarray::ArrayBase<S, D>> for tch::Tensor
176175
where
177176
A: tch::kind::Element + Clone,
178-
S: nd::RawData<Elem = A> + nd::Data,
179-
D: nd::Dimension,
177+
S: ndarray::RawData<Elem = A> + ndarray::Data,
178+
D: ndarray::Dimension,
180179
{
181-
fn from_cv(from: &nd::ArrayBase<S, D>) -> Self {
180+
fn from_cv(from: &ndarray::ArrayBase<S, D>) -> Self {
182181
let shape: Vec<_> = from.shape().iter().map(|&s| s as i64).collect();
183182

184183
match from.as_slice() {
@@ -191,13 +190,13 @@ where
191190
}
192191
}
193192

194-
impl<A, S, D> FromCv<nd::ArrayBase<S, D>> for tch::Tensor
193+
impl<A, S, D> FromCv<ndarray::ArrayBase<S, D>> for tch::Tensor
195194
where
196195
A: tch::kind::Element + Clone,
197-
S: nd::RawData<Elem = A> + nd::Data,
198-
D: nd::Dimension,
196+
S: ndarray::RawData<Elem = A> + ndarray::Data,
197+
D: ndarray::Dimension,
199198
{
200-
fn from_cv(from: nd::ArrayBase<S, D>) -> Self {
199+
fn from_cv(from: ndarray::ArrayBase<S, D>) -> Self {
201200
Self::from_cv(&from)
202201
}
203202
}
@@ -218,7 +217,7 @@ mod tests {
218217
let s2 = 5;
219218

220219
let tensor = tch::Tensor::randn([s0, s1, s2], tch::kind::FLOAT_CPU);
221-
let array: nd::ArrayD<f32> = (&tensor).try_into_cv()?;
220+
let array: ndarray::ArrayD<f32> = (&tensor).try_into_cv()?;
222221

223222
let is_correct = itertools::iproduct!(0..s0, 0..s1, 0..s2).all(|(i0, i1, i2)| {
224223
let lhs: f32 = tensor.i((i0, i1, i2)).try_into().unwrap();
@@ -232,7 +231,7 @@ mod tests {
232231
// Array0
233232
{
234233
let tensor = tch::Tensor::randn([], tch::kind::FLOAT_CPU);
235-
let array: nd::Array0<f32> = (&tensor).try_into_cv()?;
234+
let array: ndarray::Array0<f32> = (&tensor).try_into_cv()?;
236235
let lhs: f32 = tensor.try_into().unwrap();
237236
let rhs = array[()];
238237
anyhow::ensure!(lhs == rhs, "value mismatch");
@@ -242,7 +241,7 @@ mod tests {
242241
{
243242
let s0 = 10;
244243
let tensor = tch::Tensor::randn([s0], tch::kind::FLOAT_CPU);
245-
let array: nd::Array1<f32> = (&tensor).try_into_cv()?;
244+
let array: ndarray::Array1<f32> = (&tensor).try_into_cv()?;
246245

247246
let is_correct = (0..s0).all(|ind| {
248247
let lhs: f32 = tensor.i((ind,)).try_into().unwrap();
@@ -259,7 +258,7 @@ mod tests {
259258
let s1 = 5;
260259

261260
let tensor = tch::Tensor::randn([s0, s1], tch::kind::FLOAT_CPU);
262-
let array: nd::Array2<f32> = (&tensor).try_into_cv()?;
261+
let array: ndarray::Array2<f32> = (&tensor).try_into_cv()?;
263262

264263
let is_correct = itertools::iproduct!(0..s0, 0..s1).all(|(i0, i1)| {
265264
let lhs: f32 = tensor.i((i0, i1)).try_into().unwrap();
@@ -277,7 +276,7 @@ mod tests {
277276
let s2 = 7;
278277

279278
let tensor = tch::Tensor::randn([s0, s1, s2], tch::kind::FLOAT_CPU);
280-
let array: nd::Array3<f32> = (&tensor).try_into_cv()?;
279+
let array: ndarray::Array3<f32> = (&tensor).try_into_cv()?;
281280

282281
let is_correct = itertools::iproduct!(0..s0, 0..s1, 0..s2).all(|(i0, i1, i2)| {
283282
let lhs: f32 = tensor.i((i0, i1, i2)).try_into().unwrap();
@@ -296,7 +295,7 @@ mod tests {
296295
let s3 = 11;
297296

298297
let tensor = tch::Tensor::randn([s0, s1, s2, s3], tch::kind::FLOAT_CPU);
299-
let array: nd::Array4<f32> = (&tensor).try_into_cv()?;
298+
let array: ndarray::Array4<f32> = (&tensor).try_into_cv()?;
300299

301300
let is_correct =
302301
itertools::iproduct!(0..s0, 0..s1, 0..s2, 0..s3).all(|(i0, i1, i2, i3)| {
@@ -317,7 +316,7 @@ mod tests {
317316
let s4 = 13;
318317

319318
let tensor = tch::Tensor::randn([s0, s1, s2, s3, s4], tch::kind::FLOAT_CPU);
320-
let array: nd::Array5<f32> = (&tensor).try_into_cv()?;
319+
let array: ndarray::Array5<f32> = (&tensor).try_into_cv()?;
321320

322321
let is_correct = itertools::iproduct!(0..s0, 0..s1, 0..s2, 0..s3, 0..s4).all(
323322
|(i0, i1, i2, i3, i4)| {
@@ -346,7 +345,7 @@ mod tests {
346345
let s5 = 17;
347346

348347
let tensor = tch::Tensor::randn([s0, s1, s2, s3, s4, s5], tch::kind::FLOAT_CPU);
349-
let array: nd::Array6<f32> = (&tensor).try_into_cv()?;
348+
let array: ndarray::Array6<f32> = (&tensor).try_into_cv()?;
350349

351350
let is_correct = itertools::iproduct!(0..s0, 0..s1, 0..s2, 0..s3, 0..s4, 0..s5).all(
352351
|(i0, i1, i2, i3, i4, i5)| {
@@ -377,7 +376,7 @@ mod tests {
377376
let s1 = 3;
378377
let s2 = 4;
379378

380-
let array = nd::Array3::<f32>::from_shape_simple_fn([s0, s1, s2], || rng.random());
379+
let array = ndarray::Array3::<f32>::from_shape_simple_fn([s0, s1, s2], || rng.random());
381380
let array = array.reversed_axes();
382381

383382
let tensor = tch::Tensor::from_cv(&array);

0 commit comments

Comments
 (0)