pub struct AVDepthData { /* private fields */ }AVDepthData only.Expand description
An object wrapping a map of disparity or depth pixel data, plus metadata.
“Depth Data” is a generic term for a map of pixel data containing depth-related information. AVDepthData wraps a disparity or depth map and provides conversion methods, focus information, and camera calibration data to aid in using the map for rendering or computer vision tasks. CoreVideo supports the following four depth data pixel formats: kCVPixelFormatType_DisparityFloat16 = ‘hdis’ kCVPixelFormatType_DisparityFloat32 = ‘fdis’ kCVPixelFormatType_DepthFloat16 = ‘hdep’ kCVPixelFormatType_DepthFloat32 = ‘fdep’
The disparity formats describe normalized shift values when comparing two images. Units are 1/meters: ( pixelShift / (pixelFocalLength * baselineInMeters) ). The depth formats describe the distance to an object in meters.
Disparity / depth maps are generated from camera images containing non-rectilinear data. Camera lenses have small imperfections that cause small distortions in their resultant images compared to a pinhole camera. AVDepthData maps contain non-rectilinear (non-distortion-corrected) data as well. Their values are warped to match the lens distortion characteristics present in their accompanying YUV image. Therefore an AVDepthData map can be used as a proxy for depth when rendering effects to its accompanying image, but not to correlate points in 3D space. In order to use AVDepthData for computer vision tasks, you should use its accompanying camera calibration data to rectify the depth data (see AVCameraCalibrationData).
When capturing depth data from a camera using AVCaptureDepthDataOutput, AVDepthData objects are delivered to your AVCaptureDepthDataOutputDelegate in a streaming fashion. When capturing depth data along with photos using AVCapturePhotoOutput, depth data is delivered to your AVCapturePhotoCaptureDelegate as a property of an AVCapturePhoto (see -[AVCapturePhotoCaptureDelegate captureOutput:didFinishProcessingPhoto:error:]). When working with image files containing depth information, AVDepthData may be instantiated using information obtained from ImageIO. When editing images containing depth information, derivative AVDepthData objects may be instantiated reflecting the edits that have been performed.
See also Apple’s documentation
Implementations§
Source§impl AVDepthData
impl AVDepthData
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
pub unsafe fn new() -> Retained<Self>
Sourcepub unsafe fn depthDataFromDictionaryRepresentation_error(
image_source_aux_data_info_dictionary: &NSDictionary,
) -> Result<Retained<Self>, Retained<NSError>>
pub unsafe fn depthDataFromDictionaryRepresentation_error( image_source_aux_data_info_dictionary: &NSDictionary, ) -> Result<Retained<Self>, Retained<NSError>>
Returns an AVDepthData instance from depth information in an image file.
Parameter imageSourceAuxDataInfoDictionary: A dictionary of primitive depth-related information obtained from CGImageSourceCopyAuxiliaryDataInfoAtIndex.
Parameter outError: On return, if the depth data cannot be created, points to an NSError describing the problem.
Returns: An AVDepthData instance, or nil if the auxiliary data info dictionary was malformed.
When using ImageIO framework’s CGImageSource API to read from a HEIF or JPEG file containing depth data, AVDepthData can be instantiated using the result of CGImageSourceCopyAuxiliaryDataInfoAtIndex, which returns a CFDictionary of primitive map information.
§Safety
image_source_aux_data_info_dictionary generic should be of the correct type.
Sourcepub unsafe fn depthDataByConvertingToDepthDataType(
&self,
depth_data_type: u32,
) -> Retained<Self>
pub unsafe fn depthDataByConvertingToDepthDataType( &self, depth_data_type: u32, ) -> Retained<Self>
Returns a converted, derivative AVDepthData instance in the specified depthDataType.
Parameter depthDataType: The OSType of depthData object to which you’d like to convert. Must be present in availableDepthDataTypes.
Returns: An AVDepthData instance.
This method throws an NSInvalidArgumentException if you pass an unrecognized depthDataType. See
Sourcepub unsafe fn depthDataByApplyingExifOrientation(
&self,
exif_orientation: CGImagePropertyOrientation,
) -> Retained<Self>
Available on crate feature objc2-image-io only.
pub unsafe fn depthDataByApplyingExifOrientation( &self, exif_orientation: CGImagePropertyOrientation, ) -> Retained<Self>
objc2-image-io only.Returns a derivative AVDepthData instance in which the specified Exif orientation has been applied.
Parameter exifOrientation: One of the 8 standard Exif orientation tags expressing how the depth data should be rotated / mirrored.
Returns: An AVDepthData instance.
When applying simple 90 degree rotation or mirroring edits to media containing depth data, you may use this initializer to create a derivative copy of the depth in which the specified orientation is applied to both the underlying pixel map data and the camera calibration data. This method throws an NSInvalidArgumentException if you pass an unrecognized exifOrientation.
Sourcepub unsafe fn depthDataByReplacingDepthDataMapWithPixelBuffer_error(
&self,
pixel_buffer: &CVPixelBuffer,
) -> Result<Retained<Self>, Retained<NSError>>
Available on crate feature objc2-core-video only.
pub unsafe fn depthDataByReplacingDepthDataMapWithPixelBuffer_error( &self, pixel_buffer: &CVPixelBuffer, ) -> Result<Retained<Self>, Retained<NSError>>
objc2-core-video only.Returns an AVDepthData instance wrapping the replacement depth data map pixel buffer.
Parameter pixelBuffer: A pixel buffer containing depth data information in one of the 4 supported disparity / depth pixel formats.
Parameter outError: On return, if the depth data cannot be created, points to an NSError describing the problem.
Returns: An AVDepthData instance, or nil if the pixel buffer is malformed.
When applying complex edits to media containing depth data, you may create a derivative map with arbitrary transforms applied to it, then use this initializer to create a new AVDepthData. Note that this new depth data object has no camera calibration data, so its cameraCalibrationData property always returns nil.
Sourcepub unsafe fn availableDepthDataTypes(&self) -> Retained<NSArray<NSNumber>>
pub unsafe fn availableDepthDataTypes(&self) -> Retained<NSArray<NSNumber>>
Specifies which depth data pixel formats may be used with depthDataByConvertingToDepthDataType:.
This property presents the available pixel format types as an array of NSNumbers, each wrapping an OSType (CV pixel format type).
Sourcepub unsafe fn dictionaryRepresentationForAuxiliaryDataType(
&self,
out_aux_data_type: Option<&mut Option<Retained<NSString>>>,
) -> Option<Retained<NSDictionary>>
pub unsafe fn dictionaryRepresentationForAuxiliaryDataType( &self, out_aux_data_type: Option<&mut Option<Retained<NSString>>>, ) -> Option<Retained<NSDictionary>>
Returns a dictionary of primitive map information to be used when writing an image file with depth data.
Parameter outAuxDataType: On output, either kCGImageAuxiliaryDataTypeDisparity or kCGImageAuxiliaryDataTypeDepth, depending on the depth data’s file.
Returns: A dictionary of CGImageDestination compatible depth information, or nil if the auxDataType is unsupported.
When using ImageIO framework’s CGImageDestination API to write depth data to a HEIF or JPEG file, you may use this method to generate a dictionary of primitive map information consumed by CGImageDestinationAddAuxiliaryDataInfo.
Sourcepub unsafe fn depthDataType(&self) -> u32
pub unsafe fn depthDataType(&self) -> u32
Specifies the pixel format type of this depth data object’s internal map.
One of kCVPixelFormatType_DisparityFloat16, kCVPixelFormatType_DisparityFloat32, kCVPixelFormatType_DepthFloat16, or kCVPixelFormatType_DepthFloat32.
Sourcepub unsafe fn depthDataMap(&self) -> Retained<CVPixelBuffer>
Available on crate feature objc2-core-video only.
pub unsafe fn depthDataMap(&self) -> Retained<CVPixelBuffer>
objc2-core-video only.Provides access to the depth data object’s internal map.
The depth data map’s pixel format can be queried using the depthDataType property.
Sourcepub unsafe fn depthDataQuality(&self) -> AVDepthDataQuality
pub unsafe fn depthDataQuality(&self) -> AVDepthDataQuality
Specifies the overall quality of the depth data map’s values.
See AVDepthDataQuality documentation for more information.
Sourcepub unsafe fn isDepthDataFiltered(&self) -> bool
pub unsafe fn isDepthDataFiltered(&self) -> bool
Specifies whether the depth data pixel buffer map contains filtered (hole-filled) data.
By setting either AVCaptureDepthDataOutput’s filteringEnabled property or AVCapturePhotoSettings’ depthDataFiltered property to YES, the resulting depth data are filtered to remove invalid pixel values that may be present due to a variety of factors including low light and lens occlusion. If you’ve requested depth data filtering, all depth data holes are filled. Note that filtering the depth data makes it more usable for applying effects, but alters the data such that it may no longer be suitable for computer vision tasks. Unfiltered depth maps present missing data as NaN.
Sourcepub unsafe fn depthDataAccuracy(&self) -> AVDepthDataAccuracy
pub unsafe fn depthDataAccuracy(&self) -> AVDepthDataAccuracy
Specifies the accuracy of the units in the depth data map’s values.
See AVDepthDataAccuracy documentation for more information.
Sourcepub unsafe fn cameraCalibrationData(
&self,
) -> Option<Retained<AVCameraCalibrationData>>
Available on crate feature AVCameraCalibrationData only.
pub unsafe fn cameraCalibrationData( &self, ) -> Option<Retained<AVCameraCalibrationData>>
AVCameraCalibrationData only.The calibration data of the camera with which AVDepthData map’s values are aligned.
See AVCameraCalibrationData for more information. This property may return nil if no camera calibration data is available for the depth data.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AVDepthData> for AVDepthData
impl AsRef<AVDepthData> for AVDepthData
Source§impl AsRef<AnyObject> for AVDepthData
impl AsRef<AnyObject> for AVDepthData
Source§impl AsRef<NSObject> for AVDepthData
impl AsRef<NSObject> for AVDepthData
Source§impl Borrow<AnyObject> for AVDepthData
impl Borrow<AnyObject> for AVDepthData
Source§impl Borrow<NSObject> for AVDepthData
impl Borrow<NSObject> for AVDepthData
Source§impl ClassType for AVDepthData
impl ClassType for AVDepthData
Source§const NAME: &'static str = "AVDepthData"
const NAME: &'static str = "AVDepthData"
Source§type ThreadKind = <<AVDepthData as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<AVDepthData as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for AVDepthData
impl Debug for AVDepthData
Source§impl Deref for AVDepthData
impl Deref for AVDepthData
Source§impl Hash for AVDepthData
impl Hash for AVDepthData
Source§impl Message for AVDepthData
impl Message for AVDepthData
Source§impl NSObjectProtocol for AVDepthData
impl NSObjectProtocol for AVDepthData
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref