Skip to main content

ImageAnalyzerConfiguration

Struct ImageAnalyzerConfiguration 

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

Implementations§

Source§

impl ImageAnalyzerConfiguration

Source

pub fn new(analysis_types: ImageAnalysisTypes) -> Self

Examples found in repository?
examples/06_image_analysis.rs (lines 22-24)
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
Hide additional examples
examples/05_live_text_interaction.rs (line 23)
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 asset_path = asset_path();
19    let analyzer = ImageAnalyzer::new()?;
20    let analysis = analyzer.analyze_image_at_path(
21        &asset_path,
22        ImageOrientation::Up,
23        &ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT),
24    )?;
25
26    let interaction = LiveTextInteraction::new()?;
27    interaction.track_image_at_path(&asset_path)?;
28    interaction.set_analysis(&analysis)?;
29    interaction.set_preferred_interaction_types(LiveTextInteractionTypes::AUTOMATIC_TEXT_ONLY)?;
30    interaction.set_selectable_items_highlighted(true)?;
31    let rect = interaction.contents_rect()?;
32    println!("contents rect: {rect:?}");
33    let overlay_text = interaction.text();
34    println!("overlay text: {overlay_text:?}");
35    println!(
36        "live text button visible: {}",
37        interaction.live_text_button_visible()?
38    );
39    println!(
40        "supplementary hidden: {}",
41        interaction.is_supplementary_interface_hidden()?
42    );
43    Ok(())
44}
examples/04_image_analyzer.rs (lines 13-15)
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 (lines 37-39)
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}
Source

pub fn analysis_types(&self) -> ImageAnalysisTypes

Source

pub fn locales(&self) -> &[String]

Source

pub fn with_locales<I, S>(self, locales: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Examples found in repository?
examples/04_image_analyzer.rs (line 16)
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
Hide additional examples
examples/02_framework_smoke.rs (line 40)
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}

Trait Implementations§

Source§

impl Clone for ImageAnalyzerConfiguration

Source§

fn clone(&self) -> ImageAnalyzerConfiguration

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ImageAnalyzerConfiguration

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ImageAnalyzerConfiguration

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ImageAnalyzerConfiguration

Source§

fn eq(&self, other: &ImageAnalyzerConfiguration) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ImageAnalyzerConfiguration

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ImageAnalyzerConfiguration

Source§

impl StructuralPartialEq for ImageAnalyzerConfiguration

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,