pub struct TensorImageRef<'a> { /* private fields */ }Expand description
A borrowed view of an image tensor for zero-copy preprocessing.
TensorImageRef wraps a borrowed &mut Tensor<u8> instead of owning it,
enabling zero-copy operations where the HAL writes directly into an external
tensor (e.g., a model’s pre-allocated input buffer).
§Examples
ⓘ
// Create a borrowed tensor image wrapping the model's input tensor
let mut dst = TensorImageRef::from_borrowed_tensor(
model.input_tensor(0),
PLANAR_RGB,
)?;
// Preprocess directly into the model's input buffer
processor.convert(&src_image, &mut dst, Rotation::None, Flip::None, Crop::default())?;
// Run inference - no copy needed!
model.run()?;Implementations§
Source§impl<'a> TensorImageRef<'a>
impl<'a> TensorImageRef<'a>
Sourcepub fn from_borrowed_tensor(
tensor: &'a mut Tensor<u8>,
fourcc: FourCharCode,
) -> Result<Self>
pub fn from_borrowed_tensor( tensor: &'a mut Tensor<u8>, fourcc: FourCharCode, ) -> Result<Self>
Creates a TensorImageRef from a borrowed tensor reference.
The tensor shape must match the expected format:
- For planar formats (e.g., PLANAR_RGB): shape is
[channels, height, width] - For interleaved formats (e.g., RGB, RGBA): shape is
[height, width, channels]
§Arguments
tensor- A mutable reference to the tensor to wrapfourcc- The pixel format of the image
§Returns
A Result containing the TensorImageRef or an error if the tensor
shape doesn’t match the expected format.
Sourcepub fn fourcc(&self) -> FourCharCode
pub fn fourcc(&self) -> FourCharCode
Returns the FourCC code representing the image format.
Sourcepub fn row_stride(&self) -> usize
pub fn row_stride(&self) -> usize
Returns the row stride in bytes.
Trait Implementations§
Source§impl<'a> Debug for TensorImageRef<'a>
impl<'a> Debug for TensorImageRef<'a>
Source§impl TensorImageDst for TensorImageRef<'_>
impl TensorImageDst for TensorImageRef<'_>
Source§fn tensor_mut(&mut self) -> &mut Tensor<u8>
fn tensor_mut(&mut self) -> &mut Tensor<u8>
Returns a mutable reference to the underlying tensor.
Source§fn fourcc(&self) -> FourCharCode
fn fourcc(&self) -> FourCharCode
Returns the FourCC code representing the image format.
Source§fn row_stride(&self) -> usize
fn row_stride(&self) -> usize
Returns the row stride in bytes.
Auto Trait Implementations§
impl<'a> Freeze for TensorImageRef<'a>
impl<'a> RefUnwindSafe for TensorImageRef<'a>
impl<'a> Send for TensorImageRef<'a>
impl<'a> Sync for TensorImageRef<'a>
impl<'a> Unpin for TensorImageRef<'a>
impl<'a> !UnwindSafe for TensorImageRef<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.