#[cfg(feature = "image_0-23")] mod with_image_0_23 { use crate::image; use crate::tch; use crate::{common::*, FromCv, IntoCv, TchTensorAsImage, TchTensorImageShape, TryFromCv}; use std::ops::Deref; impl
FromCv<&image::ImageBuffer
> for TchTensorAsImage
where
P: image::Pixel + 'static,
P::Subpixel: 'static + tch::kind::Element,
Container: Deref ) -> Self {
let (width, height) = from.dimensions();
let channels = P::CHANNEL_COUNT;
let tensor =
tch::Tensor::from_slice(&*from).view([width as i64, height as i64, channels as i64]);
TchTensorAsImage {
tensor,
kind: TchTensorImageShape::Whc,
}
}
}
impl FromCv ) -> Self {
Self::from_cv(&from)
}
}
impl TryFromCv<&image::DynamicImage> for TchTensorAsImage {
type Error = Error;
fn try_from_cv(from: &image::DynamicImage) -> Result FromCv<&image::ImageBuffer > for TchTensorAsImage
where
P: image::Pixel + 'static,
P::Subpixel: 'static + tch::kind::Element,
Container: Deref ) -> Self {
let (width, height) = from.dimensions();
let channels = P::CHANNEL_COUNT;
let tensor =
tch::Tensor::from_slice(&*from).view([width as i64, height as i64, channels as i64]);
TchTensorAsImage {
tensor,
kind: TchTensorImageShape::Whc,
}
}
}
impl FromCv ) -> Self {
Self::from_cv(&from)
}
}
impl TryFromCv<&image::DynamicImage> for TchTensorAsImage {
type Error = Error;
fn try_from_cv(from: &image::DynamicImage) -> Result