Skip to main content

SamMaskDecoder

Trait SamMaskDecoder 

Source
pub trait SamMaskDecoder: Send + Sync {
    // Required method
    fn decode<'life0, 'life1, 'async_trait>(
        &'life0 self,
        masks: &'life1 [SamMask],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<bool>>, VisionError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
}
Available on crate features sam and vision only.
Expand description

Decodes sam-3.1 mask payloads into row-major rasters of height × width bits.

Meta’s payload is base85 text around an arithmetic-coded body whose model is defined only by Meta’s own parser, @meta-sam/parser, published under the SAM License. The Apache-2.0 crates hold no SAM-licensed code: a SamSegmenter without a decoder answers with each object’s box in source pixels; with one, with its mask. MaskDecoderChoice picks ExternalMaskDecoder or, with feature sam-codec, LicensedMaskDecoder; any other implementation is installed with SamSegmenter::with_mask_decoder.

§Example

use adk_vision::sam::{SamMask, SamMaskDecoder};

/// Every mask is solid: its box is the object.
struct Solid;

#[async_trait::async_trait]
impl SamMaskDecoder for Solid {
    async fn decode(&self, masks: &[SamMask]) -> adk_vision::Result<Vec<Vec<bool>>> {
        Ok(masks.iter().map(|m| vec![true; (m.width * m.height) as usize]).collect())
    }
}

Required Methods§

Source

fn decode<'life0, 'life1, 'async_trait>( &'life0 self, masks: &'life1 [SamMask], ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<bool>>, VisionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

One row-major raster of height × width bits per mask, in order.

§Errors

The decoder’s failure; the segmenter refuses the answer rather than guess.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§