pub struct TextRecognizer { /* private fields */ }recognize_text only.Expand description
OCR engine.
§Examples
use apple_vision::recognize_text::{TextRecognizer, RecognitionLevel};
let recognizer = TextRecognizer::new()
.with_recognition_level(RecognitionLevel::Accurate)
.with_language_correction(true);
let observations = recognizer.recognize_in_path("/tmp/screenshot.png")?;
for obs in &observations {
println!("{:.2} {:?}: {}", obs.confidence, obs.bounding_box, obs.text);
}Implementations§
Source§impl TextRecognizer
impl TextRecognizer
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct with the Vision defaults: accurate mode + language correction enabled.
pub const fn with_recognition_level(self, level: RecognitionLevel) -> Self
pub const fn with_language_correction(self, enabled: bool) -> Self
Sourcepub fn recognize_in_path(
&self,
path: impl AsRef<Path>,
) -> Result<Vec<RecognizedText>, VisionError>
pub fn recognize_in_path( &self, path: impl AsRef<Path>, ) -> Result<Vec<RecognizedText>, VisionError>
Recognise text in the image at path. Supports any format
CoreGraphics’ ImageIO can read (PNG, JPEG, HEIC, TIFF, …).
Returns observations in Vision’s natural ordering (top-down, left-to-right after layout analysis).
§Errors
Returns VisionError::InvalidArgument if path contains an
interior NUL byte, VisionError::ImageLoadFailed if the image
can’t be read, or VisionError::RequestFailed if Vision rejects
the request.
Sourcepub fn recognize_in_pixel_buffer(
&self,
pixel_buffer: &CVPixelBuffer,
) -> Result<Vec<RecognizedText>, VisionError>
pub fn recognize_in_pixel_buffer( &self, pixel_buffer: &CVPixelBuffer, ) -> Result<Vec<RecognizedText>, VisionError>
Recognise text in a CVPixelBuffer
directly, without a PNG round-trip. This is the zero-copy path for
live capture pipelines (screencapturekit / videotoolbox decoder /
AVCaptureSession).
§Errors
Returns VisionError::RequestFailed if Vision rejects the buffer
(e.g. unsupported pixel format).
Trait Implementations§
Source§impl Clone for TextRecognizer
impl Clone for TextRecognizer
Source§fn clone(&self) -> TextRecognizer
fn clone(&self) -> TextRecognizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more