Skip to main content

apple_vision/
lib.rs

1#![doc = include_str!("../README.md")]
2//!
3//! ---
4//!
5//! # API Documentation
6//!
7//! Safe Rust bindings for Apple's
8//! [Vision](https://developer.apple.com/documentation/vision) framework —
9//! OCR, object detection, face landmarks, and other on-device computer
10//! vision tasks.
11//!
12//! v0.16.0 adds a Tier-1 `async_api` module for one-shot OCR / face / barcode /
13//! segmentation requests while keeping the full audited Vision request surface
14//! and the split Swift bridge / coverage matrix introduced in v0.15.x.
15
16#![cfg_attr(docsrs, feature(doc_cfg))]
17
18pub mod error;
19pub mod ffi;
20pub mod geometry;
21pub mod recognized_points;
22pub mod request_base;
23pub mod sdk;
24
25#[cfg(feature = "async")]
26#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
27pub mod async_api;
28
29#[cfg(feature = "recognize_text")]
30#[cfg_attr(docsrs, doc(cfg(feature = "recognize_text")))]
31pub mod recognize_text;
32
33#[cfg(feature = "recognize_text")]
34#[cfg_attr(docsrs, doc(cfg(feature = "recognize_text")))]
35pub mod processing;
36
37#[cfg(feature = "detect_faces")]
38#[cfg_attr(docsrs, doc(cfg(feature = "detect_faces")))]
39pub mod detect_faces;
40
41#[cfg(feature = "detect_barcodes")]
42#[cfg_attr(docsrs, doc(cfg(feature = "detect_barcodes")))]
43pub mod detect_barcodes;
44
45#[cfg(feature = "saliency")]
46#[cfg_attr(docsrs, doc(cfg(feature = "saliency")))]
47pub mod saliency;
48
49#[cfg(feature = "face_landmarks")]
50#[cfg_attr(docsrs, doc(cfg(feature = "face_landmarks")))]
51pub mod face_landmarks;
52
53#[cfg(feature = "body_pose")]
54#[cfg_attr(docsrs, doc(cfg(feature = "body_pose")))]
55pub mod body_pose;
56
57#[cfg(feature = "hand_pose")]
58#[cfg_attr(docsrs, doc(cfg(feature = "hand_pose")))]
59pub mod hand_pose;
60
61#[cfg(feature = "contours")]
62#[cfg_attr(docsrs, doc(cfg(feature = "contours")))]
63pub mod contours;
64
65#[cfg(feature = "animals")]
66#[cfg_attr(docsrs, doc(cfg(feature = "animals")))]
67pub mod animals;
68
69#[cfg(feature = "classify")]
70#[cfg_attr(docsrs, doc(cfg(feature = "classify")))]
71pub mod classify;
72
73#[cfg(feature = "rectangles")]
74#[cfg_attr(docsrs, doc(cfg(feature = "rectangles")))]
75pub mod rectangles;
76
77#[cfg(feature = "horizon")]
78#[cfg_attr(docsrs, doc(cfg(feature = "horizon")))]
79pub mod horizon;
80
81#[cfg(feature = "feature_print")]
82#[cfg_attr(docsrs, doc(cfg(feature = "feature_print")))]
83pub mod feature_print;
84
85#[cfg(feature = "humans")]
86#[cfg_attr(docsrs, doc(cfg(feature = "humans")))]
87pub mod humans;
88
89#[cfg(feature = "aesthetics")]
90#[cfg_attr(docsrs, doc(cfg(feature = "aesthetics")))]
91pub mod aesthetics;
92
93#[cfg(feature = "segmentation")]
94#[cfg_attr(docsrs, doc(cfg(feature = "segmentation")))]
95pub mod segmentation;
96
97#[cfg(feature = "optical_flow")]
98#[cfg_attr(docsrs, doc(cfg(feature = "optical_flow")))]
99pub mod optical_flow;
100
101#[cfg(feature = "coreml")]
102#[cfg_attr(docsrs, doc(cfg(feature = "coreml")))]
103pub mod coreml;
104
105#[cfg(feature = "tracking")]
106#[cfg_attr(docsrs, doc(cfg(feature = "tracking")))]
107pub mod tracking;
108
109// v0.13: new request types
110pub mod animal_body_pose;
111pub mod human_body_pose_3d;
112pub mod objectness_saliency;
113pub mod person_instance_mask;
114pub mod registration;
115pub mod text_rectangles;
116pub mod trajectories;
117
118pub use error::VisionError;
119pub use geometry::{
120    element_type_size, image_point_for_face_landmark_point, image_point_for_normalized_point,
121    image_point_for_normalized_point_using_region_of_interest, image_rect_for_normalized_rect,
122    image_rect_for_normalized_rect_using_region_of_interest,
123    normalized_face_bounding_box_point_for_landmark_point, normalized_identity_rect,
124    normalized_point_for_image_point, normalized_point_for_image_point_using_region_of_interest,
125    normalized_rect_for_image_rect, normalized_rect_for_image_rect_using_region_of_interest,
126    normalized_rect_is_identity_rect, Transform3D, VisionCircle, VisionGeometryUtils, VisionPoint,
127    VisionPoint3D, VisionVector,
128};
129pub use recognized_points::{
130    HumanBodyRecognizedPoint3D, RecognizedPoint, RecognizedPoint3D, RecognizedPoints3DObservation,
131    RecognizedPointsObservation, VisionDetectedPoint, VisionRecognizedPoint,
132    VisionRecognizedPoint3D,
133};
134pub use request_base::{
135    ImageAlignmentObservation, ImageBasedRequest, ImageRegistrationRequest, NormalizedRect,
136    PixelBufferObservation, RequestProgress, RequestProgressHandler, RequestProgressProviding,
137    RequestRevisionProviding, StatefulRequest, TargetedImageRequest, TrackingLevel,
138    TrackingRequest,
139};
140pub use sdk::{
141    vision_version_number, AnimalIdentifier, BarcodeCompositeType, BarcodeSymbology, ComputeStage,
142    ElementType, ImageCropAndScaleOption, ImageOption, PointsClassification,
143    RecognizedPoint3DGroupKey, RecognizedPointGroupKey, VisionErrorCode, VISION_ERROR_DOMAIN,
144};
145
146#[cfg(feature = "recognize_text")]
147pub use processing::{
148    ImageRequestHandler, Observation, RecognizedTextObservation, Request, RequestKind,
149    SequenceRequestHandler, TimeRange, VideoCadence, VideoProcessingOptions, VideoProcessor,
150    VideoProcessorCadence, VideoProcessorFrameRateCadence, VideoProcessorRequestProcessingOptions,
151    VideoProcessorTimeIntervalCadence,
152};
153
154#[cfg(feature = "recognize_text")]
155pub use recognize_text::{
156    BoundingBox, RecognitionLevel, RecognizedText, RecognizedTextCandidate, TextRecognizer,
157};
158
159#[cfg(feature = "detect_faces")]
160pub use detect_faces::{DetectedFace, FaceDetector};
161
162#[cfg(feature = "detect_barcodes")]
163pub use detect_barcodes::{
164    detect_barcodes_in_path, BarcodeCompositeType as DetectedBarcodeCompositeType,
165    BarcodeSymbology as DetectedBarcodeSymbology, DetectedBarcode,
166};
167
168#[cfg(feature = "saliency")]
169pub use saliency::{attention_saliency_in_path, SalientRegion};
170
171#[cfg(feature = "face_landmarks")]
172pub use face_landmarks::{
173    detect_face_landmarks_in_path, FaceLandmarkRegion, FaceLandmarkRegion2D, FaceLandmarks,
174    FaceLandmarks2D, FaceLandmarksRequest, FaceObservationAccepting, FaceWithLandmarks,
175    LandmarkPoint, RequestFaceLandmarksConstellation,
176};
177
178#[cfg(feature = "body_pose")]
179pub use body_pose::{
180    detect_human_body_pose_in_path, detect_human_body_pose_observations_in_path, DetectedBodyPose,
181    HumanBodyPoseJointGroupName, HumanBodyPoseJointName, HumanBodyPoseObservation, JointPoint,
182};
183
184#[cfg(feature = "hand_pose")]
185pub use hand_pose::{
186    detect_human_hand_pose_in_path, detect_human_hand_pose_observations_in_path, DetectedHandPose,
187    HandChirality, HumanHandPoseJointGroupName, HumanHandPoseJointName, HumanHandPoseObservation,
188};
189
190#[cfg(feature = "contours")]
191pub use contours::{
192    detect_contours_in_path, detect_contours_observation_in_path, Contour, ContourOptions,
193    ContoursObservation, VisionContour,
194};
195
196#[cfg(feature = "animals")]
197pub use animals::{
198    recognize_animals_in_path, AnimalIdentifier as RecognizedAnimalIdentifier, RecognizedAnimal,
199};
200
201#[cfg(feature = "classify")]
202pub use classify::{classify_image_in_path, Classification};
203
204#[cfg(feature = "rectangles")]
205pub use rectangles::{
206    detect_document_segmentation_in_path, detect_rectangles_in_path, RectangleObservation,
207    RectangleOptions,
208};
209
210#[cfg(feature = "horizon")]
211pub use horizon::{
212    detect_horizon_in_path, detect_horizon_observation_in_path, AffineTransform, HorizonObservation,
213};
214
215#[cfg(feature = "feature_print")]
216pub use feature_print::{generate_image_feature_print_in_path, FeaturePrint};
217
218#[cfg(feature = "humans")]
219pub use humans::{detect_human_rectangles_in_path, DetectedHuman};
220
221#[cfg(feature = "aesthetics")]
222pub use aesthetics::{
223    calculate_aesthetics_scores_in_path, detect_face_capture_quality_in_path, AestheticsScores,
224    FaceCaptureQuality,
225};
226
227#[cfg(feature = "segmentation")]
228pub use segmentation::{
229    generate_foreground_instance_mask_in_path,
230    generate_foreground_instance_mask_observation_in_path, generate_person_segmentation_in_path,
231    InstanceMask, InstanceMaskObservation, SegmentationMask, SegmentationQuality,
232};
233
234#[cfg(feature = "optical_flow")]
235pub use optical_flow::{
236    generate_optical_flow_in_paths, generate_optical_flow_observation_in_paths, OpticalFlowAccuracy,
237};
238
239#[cfg(feature = "coreml")]
240pub use coreml::{
241    coreml_classify_in_path, coreml_feature_value_in_path, CoreMLFeatureValue,
242    CoreMLFeatureValueObservation, CoreMLImageCropAndScaleOption, CoreMLModel, CoreMLRequest,
243};
244
245pub use animal_body_pose::{
246    detect_animal_body_pose, AnimalBodyPoseJointGroupName, AnimalBodyPoseJointName, AnimalJoint,
247};
248pub use human_body_pose_3d::{
249    detect_human_body_pose_3d, detect_human_body_pose_3d_observations,
250    detect_human_body_recognized_points_3d, BodyHeightEstimation, HumanBodyPose3DJointGroupName,
251    HumanBodyPose3DJointName, HumanBodyPose3DObservation,
252    HumanBodyPose3DObservationHeightEstimation, HumanJoint3D,
253};
254pub use objectness_saliency::{objectness_saliency, ObjectnessRegion};
255pub use person_instance_mask::{person_instance_mask, PersonInstanceMask};
256pub use registration::{
257    register_homographic, register_homographic_observation, register_translational,
258    register_translational_observation, HomographicAlignment, TranslationalAlignment,
259};
260pub use text_rectangles::{
261    detect_text_observations, detect_text_rectangles, TextObservation, TextRect,
262    TextRectanglesRequest,
263};
264pub use trajectories::{detect_trajectories, Trajectory};
265
266#[cfg(feature = "tracking")]
267pub use tracking::{
268    HomographicImageTracker, ObjectTracker, OpticalFlowFrame, OpticalFlowTracker, RectangleTracker,
269    TrackOpticalFlowRequestComputationAccuracy, TranslationalImageTracker,
270};
271
272/// Common imports.
273pub mod prelude {
274    pub use crate::animal_body_pose::{
275        detect_animal_body_pose, AnimalBodyPoseJointGroupName, AnimalBodyPoseJointName, AnimalJoint,
276    };
277    #[cfg(feature = "animals")]
278    pub use crate::animals::{
279        recognize_animals_in_path, AnimalIdentifier as RecognizedAnimalIdentifier, RecognizedAnimal,
280    };
281    #[cfg(feature = "body_pose")]
282    pub use crate::body_pose::{
283        detect_human_body_pose_in_path, detect_human_body_pose_observations_in_path,
284        DetectedBodyPose, HumanBodyPoseJointGroupName, HumanBodyPoseJointName,
285        HumanBodyPoseObservation, JointPoint,
286    };
287    #[cfg(feature = "classify")]
288    pub use crate::classify::{classify_image_in_path, Classification};
289    #[cfg(feature = "contours")]
290    pub use crate::contours::{
291        detect_contours_in_path, detect_contours_observation_in_path, Contour, ContourOptions,
292        ContoursObservation, VisionContour,
293    };
294    #[cfg(feature = "coreml")]
295    pub use crate::coreml::{
296        coreml_classify_in_path, coreml_feature_value_in_path, CoreMLFeatureValue,
297        CoreMLFeatureValueObservation, CoreMLImageCropAndScaleOption, CoreMLModel, CoreMLRequest,
298    };
299    #[cfg(feature = "detect_barcodes")]
300    pub use crate::detect_barcodes::{
301        detect_barcodes_in_path, BarcodeCompositeType as DetectedBarcodeCompositeType,
302        BarcodeSymbology as DetectedBarcodeSymbology, DetectedBarcode,
303    };
304    #[cfg(feature = "detect_faces")]
305    pub use crate::detect_faces::{DetectedFace, FaceDetector};
306    pub use crate::error::VisionError;
307    #[cfg(feature = "face_landmarks")]
308    pub use crate::face_landmarks::{
309        detect_face_landmarks_in_path, FaceLandmarkRegion, FaceLandmarkRegion2D, FaceLandmarks,
310        FaceLandmarks2D, FaceLandmarksRequest, FaceObservationAccepting, FaceWithLandmarks,
311        LandmarkPoint, RequestFaceLandmarksConstellation,
312    };
313    #[cfg(feature = "feature_print")]
314    pub use crate::feature_print::{generate_image_feature_print_in_path, FeaturePrint};
315    pub use crate::geometry::{
316        element_type_size, image_point_for_face_landmark_point, image_point_for_normalized_point,
317        image_point_for_normalized_point_using_region_of_interest, image_rect_for_normalized_rect,
318        image_rect_for_normalized_rect_using_region_of_interest,
319        normalized_face_bounding_box_point_for_landmark_point, normalized_identity_rect,
320        normalized_point_for_image_point,
321        normalized_point_for_image_point_using_region_of_interest, normalized_rect_for_image_rect,
322        normalized_rect_for_image_rect_using_region_of_interest, normalized_rect_is_identity_rect,
323        Transform3D, VisionCircle, VisionGeometryUtils, VisionPoint, VisionPoint3D, VisionVector,
324    };
325    #[cfg(feature = "hand_pose")]
326    pub use crate::hand_pose::{
327        detect_human_hand_pose_in_path, detect_human_hand_pose_observations_in_path,
328        DetectedHandPose, HandChirality, HumanHandPoseJointGroupName, HumanHandPoseJointName,
329        HumanHandPoseObservation,
330    };
331    #[cfg(feature = "horizon")]
332    pub use crate::horizon::{
333        detect_horizon_in_path, detect_horizon_observation_in_path, AffineTransform,
334        HorizonObservation,
335    };
336    pub use crate::human_body_pose_3d::{
337        detect_human_body_pose_3d, detect_human_body_pose_3d_observations,
338        detect_human_body_recognized_points_3d, BodyHeightEstimation,
339        HumanBodyPose3DJointGroupName, HumanBodyPose3DJointName, HumanBodyPose3DObservation,
340        HumanBodyPose3DObservationHeightEstimation, HumanJoint3D,
341    };
342    #[cfg(feature = "humans")]
343    pub use crate::humans::{detect_human_rectangles_in_path, DetectedHuman};
344    #[cfg(feature = "optical_flow")]
345    pub use crate::optical_flow::{
346        generate_optical_flow_in_paths, generate_optical_flow_observation_in_paths,
347        OpticalFlowAccuracy,
348    };
349    #[cfg(feature = "recognize_text")]
350    pub use crate::processing::{
351        ImageRequestHandler, Observation, RecognizedTextObservation, Request, RequestKind,
352        SequenceRequestHandler, TimeRange, VideoCadence, VideoProcessingOptions, VideoProcessor,
353        VideoProcessorCadence, VideoProcessorFrameRateCadence,
354        VideoProcessorRequestProcessingOptions, VideoProcessorTimeIntervalCadence,
355    };
356    #[cfg(feature = "recognize_text")]
357    pub use crate::recognize_text::{
358        BoundingBox, RecognitionLevel, RecognizedText, RecognizedTextCandidate, TextRecognizer,
359    };
360    pub use crate::recognized_points::{
361        HumanBodyRecognizedPoint3D, RecognizedPoint, RecognizedPoint3D,
362        RecognizedPoints3DObservation, RecognizedPointsObservation, VisionDetectedPoint,
363        VisionRecognizedPoint, VisionRecognizedPoint3D,
364    };
365    #[cfg(feature = "rectangles")]
366    pub use crate::rectangles::{
367        detect_document_segmentation_in_path, detect_rectangles_in_path, RectangleObservation,
368        RectangleOptions,
369    };
370    pub use crate::registration::{
371        register_homographic, register_homographic_observation, register_translational,
372        register_translational_observation, HomographicAlignment, TranslationalAlignment,
373    };
374    pub use crate::request_base::{
375        ImageAlignmentObservation, ImageBasedRequest, ImageRegistrationRequest, NormalizedRect,
376        PixelBufferObservation, RequestProgress, RequestProgressHandler, RequestProgressProviding,
377        RequestRevisionProviding, StatefulRequest, TargetedImageRequest, TrackingLevel,
378        TrackingRequest,
379    };
380    #[cfg(feature = "saliency")]
381    pub use crate::saliency::{attention_saliency_in_path, SalientRegion};
382    pub use crate::sdk::{
383        vision_version_number, AnimalIdentifier, BarcodeCompositeType, BarcodeSymbology,
384        ComputeStage, ElementType, ImageCropAndScaleOption, ImageOption, PointsClassification,
385        RecognizedPoint3DGroupKey, RecognizedPointGroupKey, VisionErrorCode, VISION_ERROR_DOMAIN,
386    };
387    #[cfg(feature = "segmentation")]
388    pub use crate::segmentation::{
389        generate_foreground_instance_mask_in_path,
390        generate_foreground_instance_mask_observation_in_path,
391        generate_person_segmentation_in_path, InstanceMask, InstanceMaskObservation,
392        SegmentationMask, SegmentationQuality,
393    };
394    pub use crate::text_rectangles::{
395        detect_text_observations, detect_text_rectangles, TextObservation, TextRect,
396        TextRectanglesRequest,
397    };
398    #[cfg(feature = "tracking")]
399    pub use crate::tracking::{
400        HomographicImageTracker, ObjectTracker, OpticalFlowFrame, OpticalFlowTracker,
401        RectangleTracker, TrackOpticalFlowRequestComputationAccuracy, TranslationalImageTracker,
402    };
403}