pub struct LiveTextTrackingImageView { /* private fields */ }Implementations§
Source§impl LiveTextTrackingImageView
impl LiveTextTrackingImageView
Sourcepub fn new() -> Result<Self, VisionKitError>
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}pub fn frame(&self) -> Result<Rect, VisionKitError>
pub fn set_frame(&self, frame: Rect) -> Result<(), VisionKitError>
Sourcepub fn set_image_at_path<P: AsRef<Path>>(
&self,
path: P,
) -> Result<(), VisionKitError>
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}Sourcepub fn image_size(&self) -> Result<Option<Size>, VisionKitError>
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
impl Drop for LiveTextTrackingImageView
Auto Trait Implementations§
impl Freeze for LiveTextTrackingImageView
impl RefUnwindSafe for LiveTextTrackingImageView
impl !Send for LiveTextTrackingImageView
impl !Sync for LiveTextTrackingImageView
impl Unpin for LiveTextTrackingImageView
impl UnsafeUnpin for LiveTextTrackingImageView
impl UnwindSafe for LiveTextTrackingImageView
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