pub struct ImageAnalyzer { /* private fields */ }Implementations§
Source§impl ImageAnalyzer
impl ImageAnalyzer
Sourcepub fn new() -> Result<Self, VisionKitError>
pub fn new() -> Result<Self, VisionKitError>
Examples found in repository?
examples/06_image_analysis.rs (line 18)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 if !ImageAnalyzer::is_supported() {
14 println!("ImageAnalyzer is not supported on this Mac");
15 return Ok(());
16 }
17
18 let analyzer = ImageAnalyzer::new()?;
19 let analysis = analyzer.analyze_cg_image_at_path(
20 asset_path(),
21 ImageOrientation::Up,
22 &ImageAnalyzerConfiguration::new(
23 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
24 ),
25 )?;
26
27 println!(
28 "has text results: {}",
29 analysis.has_results(ImageAnalysisTypes::TEXT)?
30 );
31 println!("transcript: {}", analysis.transcript()?);
32 Ok(())
33}More examples
examples/04_image_analyzer.rs (line 27)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let configuration = ImageAnalyzerConfiguration::new(
14 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
15 )
16 .with_locales(["en-US"]);
17 println!(
18 "supported OCR languages: {}",
19 ImageAnalyzer::supported_text_recognition_languages()?.len()
20 );
21
22 if !ImageAnalyzer::is_supported() {
23 println!("ImageAnalyzer is not supported on this Mac");
24 return Ok(());
25 }
26
27 let analyzer = ImageAnalyzer::new()?;
28 let asset_path = asset_path();
29 let analyses = [
30 (
31 "imageAt:url",
32 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
33 ),
34 (
35 "nsimage",
36 analyzer.analyze_ns_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
37 ),
38 (
39 "cgimage",
40 analyzer.analyze_cg_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
41 ),
42 (
43 "ciimage",
44 analyzer.analyze_ci_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
45 ),
46 (
47 "pixelBuffer",
48 analyzer.analyze_pixel_buffer_at_path(
49 &asset_path,
50 ImageOrientation::Up,
51 &configuration,
52 )?,
53 ),
54 ];
55
56 for (label, analysis) in analyses {
57 println!("{label}: {}", analysis.transcript()?);
58 }
59 Ok(())
60}examples/02_framework_smoke.rs (line 36)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}examples/05_live_text_interaction.rs (line 107)
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 is_supported() -> bool
pub fn is_supported() -> bool
Examples found in repository?
examples/06_image_analysis.rs (line 13)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 if !ImageAnalyzer::is_supported() {
14 println!("ImageAnalyzer is not supported on this Mac");
15 return Ok(());
16 }
17
18 let analyzer = ImageAnalyzer::new()?;
19 let analysis = analyzer.analyze_cg_image_at_path(
20 asset_path(),
21 ImageOrientation::Up,
22 &ImageAnalyzerConfiguration::new(
23 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
24 ),
25 )?;
26
27 println!(
28 "has text results: {}",
29 analysis.has_results(ImageAnalysisTypes::TEXT)?
30 );
31 println!("transcript: {}", analysis.transcript()?);
32 Ok(())
33}More examples
examples/04_image_analyzer.rs (line 22)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let configuration = ImageAnalyzerConfiguration::new(
14 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
15 )
16 .with_locales(["en-US"]);
17 println!(
18 "supported OCR languages: {}",
19 ImageAnalyzer::supported_text_recognition_languages()?.len()
20 );
21
22 if !ImageAnalyzer::is_supported() {
23 println!("ImageAnalyzer is not supported on this Mac");
24 return Ok(());
25 }
26
27 let analyzer = ImageAnalyzer::new()?;
28 let asset_path = asset_path();
29 let analyses = [
30 (
31 "imageAt:url",
32 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
33 ),
34 (
35 "nsimage",
36 analyzer.analyze_ns_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
37 ),
38 (
39 "cgimage",
40 analyzer.analyze_cg_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
41 ),
42 (
43 "ciimage",
44 analyzer.analyze_ci_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
45 ),
46 (
47 "pixelBuffer",
48 analyzer.analyze_pixel_buffer_at_path(
49 &asset_path,
50 ImageOrientation::Up,
51 &configuration,
52 )?,
53 ),
54 ];
55
56 for (label, analysis) in analyses {
57 println!("{label}: {}", analysis.transcript()?);
58 }
59 Ok(())
60}examples/02_framework_smoke.rs (line 14)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}examples/05_live_text_interaction.rs (line 101)
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 supported_text_recognition_languages() -> Result<Vec<String>, VisionKitError>
pub fn supported_text_recognition_languages() -> Result<Vec<String>, VisionKitError>
Examples found in repository?
examples/04_image_analyzer.rs (line 19)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let configuration = ImageAnalyzerConfiguration::new(
14 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
15 )
16 .with_locales(["en-US"]);
17 println!(
18 "supported OCR languages: {}",
19 ImageAnalyzer::supported_text_recognition_languages()?.len()
20 );
21
22 if !ImageAnalyzer::is_supported() {
23 println!("ImageAnalyzer is not supported on this Mac");
24 return Ok(());
25 }
26
27 let analyzer = ImageAnalyzer::new()?;
28 let asset_path = asset_path();
29 let analyses = [
30 (
31 "imageAt:url",
32 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
33 ),
34 (
35 "nsimage",
36 analyzer.analyze_ns_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
37 ),
38 (
39 "cgimage",
40 analyzer.analyze_cg_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
41 ),
42 (
43 "ciimage",
44 analyzer.analyze_ci_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
45 ),
46 (
47 "pixelBuffer",
48 analyzer.analyze_pixel_buffer_at_path(
49 &asset_path,
50 ImageOrientation::Up,
51 &configuration,
52 )?,
53 ),
54 ];
55
56 for (label, analysis) in analyses {
57 println!("{label}: {}", analysis.transcript()?);
58 }
59 Ok(())
60}More examples
examples/02_framework_smoke.rs (line 24)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}Sourcepub fn analyze_image_at_path<P: AsRef<Path>>(
&self,
path: P,
orientation: ImageOrientation,
configuration: &ImageAnalyzerConfiguration,
) -> Result<ImageAnalysis, VisionKitError>
pub fn analyze_image_at_path<P: AsRef<Path>>( &self, path: P, orientation: ImageOrientation, configuration: &ImageAnalyzerConfiguration, ) -> Result<ImageAnalysis, VisionKitError>
Examples found in repository?
examples/04_image_analyzer.rs (line 32)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let configuration = ImageAnalyzerConfiguration::new(
14 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
15 )
16 .with_locales(["en-US"]);
17 println!(
18 "supported OCR languages: {}",
19 ImageAnalyzer::supported_text_recognition_languages()?.len()
20 );
21
22 if !ImageAnalyzer::is_supported() {
23 println!("ImageAnalyzer is not supported on this Mac");
24 return Ok(());
25 }
26
27 let analyzer = ImageAnalyzer::new()?;
28 let asset_path = asset_path();
29 let analyses = [
30 (
31 "imageAt:url",
32 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
33 ),
34 (
35 "nsimage",
36 analyzer.analyze_ns_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
37 ),
38 (
39 "cgimage",
40 analyzer.analyze_cg_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
41 ),
42 (
43 "ciimage",
44 analyzer.analyze_ci_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
45 ),
46 (
47 "pixelBuffer",
48 analyzer.analyze_pixel_buffer_at_path(
49 &asset_path,
50 ImageOrientation::Up,
51 &configuration,
52 )?,
53 ),
54 ];
55
56 for (label, analysis) in analyses {
57 println!("{label}: {}", analysis.transcript()?);
58 }
59 Ok(())
60}More examples
examples/02_framework_smoke.rs (line 43)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 println!("== VisionKit.framework smoke ==");
14 println!("ImageAnalyzer supported: {}", ImageAnalyzer::is_supported());
15 println!(
16 "document camera available on macOS: {}",
17 VNDocumentCameraViewController::is_available_on_current_platform()?
18 );
19 println!(
20 "data scanner available on macOS: {}",
21 DataScannerViewController::is_available_on_current_platform()?
22 );
23
24 let languages = ImageAnalyzer::supported_text_recognition_languages()?;
25 println!("supported OCR languages: {}", languages.len());
26 println!(
27 "sample OCR languages: {:?}",
28 languages.iter().take(10).collect::<Vec<_>>()
29 );
30
31 if !ImageAnalyzer::is_supported() {
32 println!("ImageAnalyzer is not supported on this Mac");
33 return Ok(());
34 }
35
36 let analyzer = ImageAnalyzer::new()?;
37 let configuration = ImageAnalyzerConfiguration::new(
38 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
39 )
40 .with_locales(["en-US"]);
41 let asset_path = asset_path();
42 let analysis =
43 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?;
44
45 println!(
46 "has text results: {}",
47 analysis.has_results(ImageAnalysisTypes::TEXT)?
48 );
49 let transcript = analysis.transcript()?;
50 println!("transcript: {transcript:?}");
51
52 let interaction = LiveTextInteraction::new()?;
53 interaction.track_image_at_path(&asset_path)?;
54 interaction.set_analysis(&analysis)?;
55 println!(
56 "overlay preferred types: {}",
57 interaction.preferred_interaction_types()?.bits()
58 );
59 let overlay_text = interaction.text();
60 println!("overlay text: {overlay_text:?}");
61 Ok(())
62}examples/05_live_text_interaction.rs (lines 108-112)
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 analyze_ns_image_at_path<P: AsRef<Path>>(
&self,
path: P,
orientation: ImageOrientation,
configuration: &ImageAnalyzerConfiguration,
) -> Result<ImageAnalysis, VisionKitError>
pub fn analyze_ns_image_at_path<P: AsRef<Path>>( &self, path: P, orientation: ImageOrientation, configuration: &ImageAnalyzerConfiguration, ) -> Result<ImageAnalysis, VisionKitError>
Examples found in repository?
examples/04_image_analyzer.rs (line 36)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let configuration = ImageAnalyzerConfiguration::new(
14 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
15 )
16 .with_locales(["en-US"]);
17 println!(
18 "supported OCR languages: {}",
19 ImageAnalyzer::supported_text_recognition_languages()?.len()
20 );
21
22 if !ImageAnalyzer::is_supported() {
23 println!("ImageAnalyzer is not supported on this Mac");
24 return Ok(());
25 }
26
27 let analyzer = ImageAnalyzer::new()?;
28 let asset_path = asset_path();
29 let analyses = [
30 (
31 "imageAt:url",
32 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
33 ),
34 (
35 "nsimage",
36 analyzer.analyze_ns_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
37 ),
38 (
39 "cgimage",
40 analyzer.analyze_cg_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
41 ),
42 (
43 "ciimage",
44 analyzer.analyze_ci_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
45 ),
46 (
47 "pixelBuffer",
48 analyzer.analyze_pixel_buffer_at_path(
49 &asset_path,
50 ImageOrientation::Up,
51 &configuration,
52 )?,
53 ),
54 ];
55
56 for (label, analysis) in analyses {
57 println!("{label}: {}", analysis.transcript()?);
58 }
59 Ok(())
60}Sourcepub fn analyze_cg_image_at_path<P: AsRef<Path>>(
&self,
path: P,
orientation: ImageOrientation,
configuration: &ImageAnalyzerConfiguration,
) -> Result<ImageAnalysis, VisionKitError>
pub fn analyze_cg_image_at_path<P: AsRef<Path>>( &self, path: P, orientation: ImageOrientation, configuration: &ImageAnalyzerConfiguration, ) -> Result<ImageAnalysis, VisionKitError>
Examples found in repository?
examples/06_image_analysis.rs (lines 19-25)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 if !ImageAnalyzer::is_supported() {
14 println!("ImageAnalyzer is not supported on this Mac");
15 return Ok(());
16 }
17
18 let analyzer = ImageAnalyzer::new()?;
19 let analysis = analyzer.analyze_cg_image_at_path(
20 asset_path(),
21 ImageOrientation::Up,
22 &ImageAnalyzerConfiguration::new(
23 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
24 ),
25 )?;
26
27 println!(
28 "has text results: {}",
29 analysis.has_results(ImageAnalysisTypes::TEXT)?
30 );
31 println!("transcript: {}", analysis.transcript()?);
32 Ok(())
33}More examples
examples/04_image_analyzer.rs (line 40)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let configuration = ImageAnalyzerConfiguration::new(
14 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
15 )
16 .with_locales(["en-US"]);
17 println!(
18 "supported OCR languages: {}",
19 ImageAnalyzer::supported_text_recognition_languages()?.len()
20 );
21
22 if !ImageAnalyzer::is_supported() {
23 println!("ImageAnalyzer is not supported on this Mac");
24 return Ok(());
25 }
26
27 let analyzer = ImageAnalyzer::new()?;
28 let asset_path = asset_path();
29 let analyses = [
30 (
31 "imageAt:url",
32 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
33 ),
34 (
35 "nsimage",
36 analyzer.analyze_ns_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
37 ),
38 (
39 "cgimage",
40 analyzer.analyze_cg_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
41 ),
42 (
43 "ciimage",
44 analyzer.analyze_ci_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
45 ),
46 (
47 "pixelBuffer",
48 analyzer.analyze_pixel_buffer_at_path(
49 &asset_path,
50 ImageOrientation::Up,
51 &configuration,
52 )?,
53 ),
54 ];
55
56 for (label, analysis) in analyses {
57 println!("{label}: {}", analysis.transcript()?);
58 }
59 Ok(())
60}Sourcepub fn analyze_ci_image_at_path<P: AsRef<Path>>(
&self,
path: P,
orientation: ImageOrientation,
configuration: &ImageAnalyzerConfiguration,
) -> Result<ImageAnalysis, VisionKitError>
pub fn analyze_ci_image_at_path<P: AsRef<Path>>( &self, path: P, orientation: ImageOrientation, configuration: &ImageAnalyzerConfiguration, ) -> Result<ImageAnalysis, VisionKitError>
Examples found in repository?
examples/04_image_analyzer.rs (line 44)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let configuration = ImageAnalyzerConfiguration::new(
14 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
15 )
16 .with_locales(["en-US"]);
17 println!(
18 "supported OCR languages: {}",
19 ImageAnalyzer::supported_text_recognition_languages()?.len()
20 );
21
22 if !ImageAnalyzer::is_supported() {
23 println!("ImageAnalyzer is not supported on this Mac");
24 return Ok(());
25 }
26
27 let analyzer = ImageAnalyzer::new()?;
28 let asset_path = asset_path();
29 let analyses = [
30 (
31 "imageAt:url",
32 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
33 ),
34 (
35 "nsimage",
36 analyzer.analyze_ns_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
37 ),
38 (
39 "cgimage",
40 analyzer.analyze_cg_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
41 ),
42 (
43 "ciimage",
44 analyzer.analyze_ci_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
45 ),
46 (
47 "pixelBuffer",
48 analyzer.analyze_pixel_buffer_at_path(
49 &asset_path,
50 ImageOrientation::Up,
51 &configuration,
52 )?,
53 ),
54 ];
55
56 for (label, analysis) in analyses {
57 println!("{label}: {}", analysis.transcript()?);
58 }
59 Ok(())
60}Sourcepub fn analyze_pixel_buffer_at_path<P: AsRef<Path>>(
&self,
path: P,
orientation: ImageOrientation,
configuration: &ImageAnalyzerConfiguration,
) -> Result<ImageAnalysis, VisionKitError>
pub fn analyze_pixel_buffer_at_path<P: AsRef<Path>>( &self, path: P, orientation: ImageOrientation, configuration: &ImageAnalyzerConfiguration, ) -> Result<ImageAnalysis, VisionKitError>
Examples found in repository?
examples/04_image_analyzer.rs (lines 48-52)
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 let configuration = ImageAnalyzerConfiguration::new(
14 ImageAnalysisTypes::TEXT | ImageAnalysisTypes::MACHINE_READABLE_CODE,
15 )
16 .with_locales(["en-US"]);
17 println!(
18 "supported OCR languages: {}",
19 ImageAnalyzer::supported_text_recognition_languages()?.len()
20 );
21
22 if !ImageAnalyzer::is_supported() {
23 println!("ImageAnalyzer is not supported on this Mac");
24 return Ok(());
25 }
26
27 let analyzer = ImageAnalyzer::new()?;
28 let asset_path = asset_path();
29 let analyses = [
30 (
31 "imageAt:url",
32 analyzer.analyze_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
33 ),
34 (
35 "nsimage",
36 analyzer.analyze_ns_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
37 ),
38 (
39 "cgimage",
40 analyzer.analyze_cg_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
41 ),
42 (
43 "ciimage",
44 analyzer.analyze_ci_image_at_path(&asset_path, ImageOrientation::Up, &configuration)?,
45 ),
46 (
47 "pixelBuffer",
48 analyzer.analyze_pixel_buffer_at_path(
49 &asset_path,
50 ImageOrientation::Up,
51 &configuration,
52 )?,
53 ),
54 ];
55
56 for (label, analysis) in analyses {
57 println!("{label}: {}", analysis.transcript()?);
58 }
59 Ok(())
60}Trait Implementations§
Source§impl Drop for ImageAnalyzer
impl Drop for ImageAnalyzer
Auto Trait Implementations§
impl Freeze for ImageAnalyzer
impl RefUnwindSafe for ImageAnalyzer
impl !Send for ImageAnalyzer
impl !Sync for ImageAnalyzer
impl Unpin for ImageAnalyzer
impl UnsafeUnpin for ImageAnalyzer
impl UnwindSafe for ImageAnalyzer
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