Expand description
§visionkit-rs
Safe Rust bindings for Apple’s VisionKit.framework on macOS.
Status: v0.2.0 covers
ImageAnalyzer,ImageAnalysis, a headless-friendlyLiveTextInteractionwrapper over macOSImageAnalysisOverlayView, and ships explicit availability metadata for the iOS-only document-camera / Data Scanner / recognized-item areas.
§Quick start
use visionkit::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
if !ImageAnalyzer::is_supported() {
println!("ImageAnalyzer is not supported on this Mac");
return Ok(());
}
let analyzer = ImageAnalyzer::new()?;
let configuration = ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT)
.with_locales(["en-US"]);
let analysis = analyzer.analyze_image_at_path(
"examples/assets/live_text.png",
ImageOrientation::Up,
&configuration,
)?;
let interaction = LiveTextInteraction::new()?;
interaction.track_image_at_path("examples/assets/live_text.png")?;
interaction.set_analysis(&analysis)?;
println!("transcript: {}", analysis.transcript()?);
println!("live text overlay text: {}", interaction.text()?);
Ok(())
}§Highlights
ImageAnalyzer::is_supportedandsupported_text_recognition_languagesImageAnalyzerConfiguration,ImageAnalysisTypes, andImageOrientation- File-path based analysis through every public macOS analyzer overload: URL,
NSImage,CGImage,CIImage, andCVPixelBuffer ImageAnalysis::transcriptandhas_resultsLiveTextInteractioncontrol over macOSImageAnalysisOverlayViewstate and inspectionVNDocumentCameraViewController,DataScannerViewController,RecognizedText,Barcode, andRecognizedItemavailability metadata on macOS
§Availability
ImageAnalyzer,ImageAnalysis, andLiveTextInteractionare available on macOS 13+.LiveTextInteraction::textandselected_textrequire macOS 14+ because Apple introduced those overlay accessors after macOS 13.VNDocumentCameraViewController,DataScannerViewController,RecognizedText,Barcode, andRecognizedItemare iOS-only Apple APIs. On macOS, this crate exposes them as structured availability metadata instead of pretending they exist.
§Examples
cargo run --example 01_vn_document_camera_view_controller
cargo run --example 02_framework_smoke
cargo run --example 03_data_scanner_view_controller
cargo run --example 04_image_analyzer
cargo run --example 05_live_text_interaction
cargo run --example 06_image_analysis
cargo run --example 07_recognized_text
cargo run --example 08_barcode
cargo run --example 09_recognized_itemSee COVERAGE.md for the audited VisionKit API matrix.
§License
Licensed under either of Apache-2.0 or MIT at your option.
Re-exports§
pub use barcode::Barcode;pub use data_scanner_view_controller::DataScannerViewController;pub use error::VisionKitError;pub use image_analysis::ImageAnalysis;pub use image_analyzer::ImageAnalysisTypes;pub use image_analyzer::ImageAnalyzer;pub use image_analyzer::ImageAnalyzerConfiguration;pub use image_analyzer::ImageOrientation;pub use live_text_interaction::EdgeInsets;pub use live_text_interaction::LiveTextInteraction;pub use live_text_interaction::LiveTextInteractionTypes;pub use live_text_interaction::Rect;pub use recognized_item::RecognizedItem;pub use recognized_text::RecognizedText;pub use support::AreaSupportInfo;pub use vn_document_camera_view_controller::VNDocumentCameraViewController;