Skip to main content

LiveTextTrackingImageView

Struct LiveTextTrackingImageView 

Source
pub struct LiveTextTrackingImageView { /* private fields */ }

Implementations§

Source§

impl LiveTextTrackingImageView

Source

pub fn new() -> Result<Self, VisionKitError>

Examples found in repository?
examples/05_live_text_interaction.rs (line 116)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101    if !ImageAnalyzer::is_supported() {
102        println!("ImageAnalyzer is not supported on this Mac");
103        return Ok(());
104    }
105
106    let asset_path = asset_path();
107    let analyzer = ImageAnalyzer::new()?;
108    let analysis = analyzer.analyze_image_at_path(
109        &asset_path,
110        ImageOrientation::Up,
111        &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112    )?;
113
114    let delegate = build_delegate()?;
115    let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116    let tracking_view = LiveTextTrackingImageView::new()?;
117    tracking_view.set_image_at_path(&asset_path)?;
118    interaction.set_tracking_image_view(Some(&tracking_view))?;
119    interaction.track_image_at_path(&asset_path)?;
120    interaction.set_analysis(&analysis)?;
121    interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122    interaction.set_selectable_items_highlighted(true)?;
123    interaction.set_contents_rect_needs_update()?;
124
125    println!("contents rect: {:?}", interaction.contents_rect()?);
126    println!("overlay text: {:?}", interaction.text());
127    println!("delegate events: {}", delegate.recorded_events()?.len());
128    println!(
129        "delegate content view set: {}",
130        interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131    );
132    match interaction.tracking_image_view()? {
133        Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134        None => println!("tracking image size: none"),
135    }
136    match LiveTextMenuTag::copy_image() {
137        Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138        Err(error) => println!("copy image tag: {error}"),
139    }
140    print_selection_state(&interaction)?;
141    print_subject_state(&interaction)?;
142    println!(
143        "live text button visible: {}",
144        interaction.live_text_button_visible()?
145    );
146    println!(
147        "supplementary hidden: {}",
148        interaction.is_supplementary_interface_hidden()?
149    );
150
151    let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152        LiveTextImageData,
153        VisionKitError,
154    > = LiveTextInteraction::image_for_subjects;
155    black_box(image_for_subjects_fn);
156    Ok(())
157}
Source

pub fn frame(&self) -> Result<Rect, VisionKitError>

Source

pub fn set_frame(&self, frame: Rect) -> Result<(), VisionKitError>

Source

pub fn set_image_at_path<P: AsRef<Path>>( &self, path: P, ) -> Result<(), VisionKitError>

Examples found in repository?
examples/05_live_text_interaction.rs (line 117)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101    if !ImageAnalyzer::is_supported() {
102        println!("ImageAnalyzer is not supported on this Mac");
103        return Ok(());
104    }
105
106    let asset_path = asset_path();
107    let analyzer = ImageAnalyzer::new()?;
108    let analysis = analyzer.analyze_image_at_path(
109        &asset_path,
110        ImageOrientation::Up,
111        &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112    )?;
113
114    let delegate = build_delegate()?;
115    let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116    let tracking_view = LiveTextTrackingImageView::new()?;
117    tracking_view.set_image_at_path(&asset_path)?;
118    interaction.set_tracking_image_view(Some(&tracking_view))?;
119    interaction.track_image_at_path(&asset_path)?;
120    interaction.set_analysis(&analysis)?;
121    interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122    interaction.set_selectable_items_highlighted(true)?;
123    interaction.set_contents_rect_needs_update()?;
124
125    println!("contents rect: {:?}", interaction.contents_rect()?);
126    println!("overlay text: {:?}", interaction.text());
127    println!("delegate events: {}", delegate.recorded_events()?.len());
128    println!(
129        "delegate content view set: {}",
130        interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131    );
132    match interaction.tracking_image_view()? {
133        Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134        None => println!("tracking image size: none"),
135    }
136    match LiveTextMenuTag::copy_image() {
137        Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138        Err(error) => println!("copy image tag: {error}"),
139    }
140    print_selection_state(&interaction)?;
141    print_subject_state(&interaction)?;
142    println!(
143        "live text button visible: {}",
144        interaction.live_text_button_visible()?
145    );
146    println!(
147        "supplementary hidden: {}",
148        interaction.is_supplementary_interface_hidden()?
149    );
150
151    let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152        LiveTextImageData,
153        VisionKitError,
154    > = LiveTextInteraction::image_for_subjects;
155    black_box(image_for_subjects_fn);
156    Ok(())
157}
Source

pub fn image_size(&self) -> Result<Option<Size>, VisionKitError>

Examples found in repository?
examples/05_live_text_interaction.rs (line 133)
100fn main() -> Result<(), Box<dyn std::error::Error>> {
101    if !ImageAnalyzer::is_supported() {
102        println!("ImageAnalyzer is not supported on this Mac");
103        return Ok(());
104    }
105
106    let asset_path = asset_path();
107    let analyzer = ImageAnalyzer::new()?;
108    let analysis = analyzer.analyze_image_at_path(
109        &asset_path,
110        ImageOrientation::Up,
111        &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
112    )?;
113
114    let delegate = build_delegate()?;
115    let interaction = LiveTextInteraction::with_delegate(&delegate)?;
116    let tracking_view = LiveTextTrackingImageView::new()?;
117    tracking_view.set_image_at_path(&asset_path)?;
118    interaction.set_tracking_image_view(Some(&tracking_view))?;
119    interaction.track_image_at_path(&asset_path)?;
120    interaction.set_analysis(&analysis)?;
121    interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
122    interaction.set_selectable_items_highlighted(true)?;
123    interaction.set_contents_rect_needs_update()?;
124
125    println!("contents rect: {:?}", interaction.contents_rect()?);
126    println!("overlay text: {:?}", interaction.text());
127    println!("delegate events: {}", delegate.recorded_events()?.len());
128    println!(
129        "delegate content view set: {}",
130        interaction.delegate()?.and_then(|value| value.content_view().ok()).flatten().is_some()
131    );
132    match interaction.tracking_image_view()? {
133        Some(view) => println!("tracking image size: {:?}", view.image_size()?),
134        None => println!("tracking image size: none"),
135    }
136    match LiveTextMenuTag::copy_image() {
137        Ok(tag) => println!("copy image tag: {}", tag.raw_value()),
138        Err(error) => println!("copy image tag: {error}"),
139    }
140    print_selection_state(&interaction)?;
141    print_subject_state(&interaction)?;
142    println!(
143        "live text button visible: {}",
144        interaction.live_text_button_visible()?
145    );
146    println!(
147        "supplementary hidden: {}",
148        interaction.is_supplementary_interface_hidden()?
149    );
150
151    let image_for_subjects_fn: fn(&LiveTextInteraction, &[LiveTextSubject]) -> Result<
152        LiveTextImageData,
153        VisionKitError,
154    > = LiveTextInteraction::image_for_subjects;
155    black_box(image_for_subjects_fn);
156    Ok(())
157}

Trait Implementations§

Source§

impl Drop for LiveTextTrackingImageView

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.