Skip to main content

VisionCamera

Classes​

Interfaces​

Type Aliases​

AutoFocusSystem​

Ƭ AutoFocusSystem: "contrast-detection" | "phase-detection" | "none"

Indicates a format's autofocus system.

  • "none": Indicates that autofocus is not available
  • "contrast-detection": Indicates that autofocus is achieved by contrast detection. Contrast detection performs a focus scan to find the optimal position
  • "phase-detection": Indicates that autofocus is achieved by phase detection. Phase detection has the ability to achieve focus in many cases without a focus scan. Phase detection autofocus is typically less visually intrusive than contrast detection autofocus

Defined in​

CameraDevice.ts:89


CameraDevices​

Ƭ CameraDevices: { [key in CameraPosition]: CameraDevice | undefined }

Defined in​

hooks/useCameraDevices.ts:7


CameraPermissionRequestResult​

Ƭ CameraPermissionRequestResult: "authorized" | "denied"

Defined in​

Camera.tsx:17


CameraPermissionStatus​

Ƭ CameraPermissionStatus: "authorized" | "not-determined" | "denied" | "restricted"

Defined in​

Camera.tsx:16


CameraPhotoCodec​

Ƭ CameraPhotoCodec: "jpeg" | "pro-res-4444" | "pro-res-422" | "pro-res-422-hq" | "pro-res-422-lt" | "pro-res-422-proxy"

Defined in​

VideoFile.ts:7


CameraPosition​

Ƭ CameraPosition: "front" | "back" | "unspecified" | "external"

Represents the camera device position.

  • "back": Indicates that the device is physically located on the back of the system hardware
  • "front": Indicates that the device is physically located on the front of the system hardware

iOS only​

  • "unspecified": Indicates that the device's position relative to the system hardware is unspecified

Android only​

  • "external": The camera device is an external camera, and has no fixed facing relative to the device's screen. (Android only)

Defined in​

CameraPosition.ts:13


CameraVideoCodec​

Ƭ CameraVideoCodec: "h264" | "hevc" | "hevc-alpha"

Defined in​

VideoFile.ts:6


CaptureError​

Ƭ CaptureError: "capture/invalid-photo-format" | "capture/encoder-error" | "capture/muxer-error" | "capture/recording-in-progress" | "capture/no-recording-in-progress" | "capture/file-io-error" | "capture/create-temp-file-error" | "capture/invalid-video-options" | "capture/create-recorder-error" | "capture/recorder-error" | "capture/no-valid-data" | "capture/inactive-source" | "capture/insufficient-storage" | "capture/file-size-limit-reached" | "capture/invalid-photo-codec" | "capture/not-bound-error" | "capture/capture-type-not-supported" | "capture/video-not-enabled" | "capture/photo-not-enabled" | "capture/aborted" | "capture/unknown"

Defined in​

CameraError.ts:31


ColorSpace​

Ƭ ColorSpace: "hlg-bt2020" | "p3-d65" | "srgb" | "yuv" | "jpeg" | "jpeg-depth" | "raw" | "heic" | "private" | "depth-16" | "unknown"

Indicates a format's color space.

The following colorspaces are available on iOS:​

  • "srgb": The sGRB color space.
  • "p3-d65": The P3 D65 wide color space which uses Illuminant D65 as the white point
  • "hlg-bt2020": The BT2020 wide color space which uses Illuminant D65 as the white point and Hybrid Log-Gamma as the transfer function

See "AVCaptureColorSpace" for more information.

The following colorspaces are available on Android:​

  • "yuv": The Multi-plane Android YCbCr color space. (YUV 420_888, 422_888 or 444_888)
  • "jpeg": The compressed JPEG color space.
  • "jpeg-depth": The compressed JPEG color space including depth data.
  • "raw": The Camera's RAW sensor color space. (Single-channel Bayer-mosaic image, usually 16 bit)
  • "heic": The compressed HEIC color space.
  • "private": The Android private opaque image format. (The choices of the actual format and pixel data layout are entirely up to the device-specific and framework internal implementations, and may vary depending on use cases even for the same device. These buffers are not directly accessible to the application)
  • "depth-16": The Android dense depth image format (16 bit)
  • "unknown": Placeholder for an unknown image/pixel format. Edit this file to add a name for the unknown format.

See "Android Color Formats" for more information.

Defined in​

CameraDevice.ts:67


DeviceError​

Ƭ DeviceError: "device/configuration-error" | "device/no-device" | "device/invalid-device" | "device/parallel-video-processing-not-supported" | "device/torch-unavailable" | "device/microphone-unavailable" | "device/low-light-boost-not-supported" | "device/focus-not-supported" | "device/camera-not-available-on-simulator"

Defined in​

CameraError.ts:8


FormatError​

Ƭ FormatError: "format/invalid-fps" | "format/invalid-hdr" | "format/invalid-low-light-boost" | "format/invalid-format" | "format/invalid-color-space"

Defined in​

CameraError.ts:18


FrameProcessor​

Ƭ FrameProcessor: { frameProcessor: (frame: Frame) => void ; type: "frame-processor" } | { frameProcessor: (frame: DrawableFrame) => void ; type: "skia-frame-processor" }

Defined in​

CameraProps.ts:7


LogicalCameraDeviceType​

Ƭ LogicalCameraDeviceType: "dual-camera" | "dual-wide-camera" | "triple-camera"

Indentifiers for a logical camera (Combinations of multiple physical cameras to create a single logical camera).

  • "dual-camera": A combination of wide-angle and telephoto cameras that creates a capture device.
  • "dual-wide-camera": A device that consists of two cameras of fixed focal length, one ultrawide angle and one wide angle.
  • "triple-camera": A device that consists of three cameras of fixed focal length, one ultrawide angle, one wide angle, and one telephoto.

Defined in​

CameraDevice.ts:20


ParameterError​

Ƭ ParameterError: "parameter/invalid-parameter" | "parameter/unsupported-os" | "parameter/unsupported-output" | "parameter/unsupported-input" | "parameter/invalid-combination"

Defined in​

CameraError.ts:2


PermissionError​

Ƭ PermissionError: "permission/microphone-permission-denied" | "permission/camera-permission-denied"

Defined in​

CameraError.ts:1


PhysicalCameraDeviceType​

Ƭ PhysicalCameraDeviceType: "ultra-wide-angle-camera" | "wide-angle-camera" | "telephoto-camera"

Indentifiers for a physical camera (one that actually exists on the back/front of the device)

  • "ultra-wide-angle-camera": A built-in camera with a shorter focal length than that of a wide-angle camera. (focal length between below 24mm)
  • "wide-angle-camera": A built-in wide-angle camera. (focal length between 24mm and 35mm)
  • "telephoto-camera": A built-in camera device with a longer focal length than a wide-angle camera. (focal length between above 85mm)

Defined in​

CameraDevice.ts:11


SessionError​

Ƭ SessionError: "session/camera-not-ready" | "session/camera-cannot-be-opened" | "session/camera-has-been-disconnected" | "session/audio-session-setup-failed" | "session/audio-in-use-by-other-app" | "session/audio-session-failed-to-activate"

Defined in​

CameraError.ts:24


SystemError​

Ƭ SystemError: "system/camera-module-not-found" | "system/no-camera-manager" | "system/frame-processors-unavailable" | "system/skia-unavailable" | "system/view-not-found"

Defined in​

CameraError.ts:53


UnknownError​

Ƭ UnknownError: "unknown/unknown"

Defined in​

CameraError.ts:59


VideoFileType​

Ƭ VideoFileType: "mov" | "avci" | "m4v" | "mp4"

Defined in​

VideoFile.ts:4


VideoStabilizationMode​

Ƭ VideoStabilizationMode: "off" | "standard" | "cinematic" | "cinematic-extended" | "auto"

Indicates a format's supported video stabilization mode

  • "off": Indicates that video should not be stabilized
  • "standard": Indicates that video should be stabilized using the standard video stabilization algorithm introduced with iOS 5.0. Standard video stabilization has a reduced field of view. Enabling video stabilization may introduce additional latency into the video capture pipeline
  • "cinematic": Indicates that video should be stabilized using the cinematic stabilization algorithm for more dramatic results. Cinematic video stabilization has a reduced field of view compared to standard video stabilization. Enabling cinematic video stabilization introduces much more latency into the video capture pipeline than standard video stabilization and consumes significantly more system memory. Use narrow or identical min and max frame durations in conjunction with this mode
  • "cinematic-extended": Indicates that the video should be stabilized using the extended cinematic stabilization algorithm. Enabling extended cinematic stabilization introduces longer latency into the video capture pipeline compared to the AVCaptureVideoStabilizationModeCinematic and consumes more memory, but yields improved stability. It is recommended to use identical or similar min and max frame durations in conjunction with this mode (iOS 13.0+)
  • "auto": Indicates that the most appropriate video stabilization mode for the device and format should be chosen automatically

Defined in​

CameraDevice.ts:100

Variables​

VisionCameraProxy​

• Const VisionCameraProxy: TVisionCameraProxy

Defined in​

FrameProcessorPlugins.ts:34

Functions​

createFrameProcessor​

â–¸ createFrameProcessor(frameProcessor, type): FrameProcessor

Parameters​

NameType
frameProcessor(frame: Frame) => void | (frame: DrawableFrame) => void
type"frame-processor" | "skia-frame-processor"

Returns​

FrameProcessor

Defined in​

hooks/useFrameProcessor.ts:7


frameRateIncluded​

â–¸ frameRateIncluded(range, fps): boolean

Returns true if the given Frame Rate Range (range) contains the given frame rate (fps)

Example

// get all formats that support 60 FPS
const formatsWithHighFps = useMemo(() => device.formats.filter((f) => f.frameRateRanges.some((r) => frameRateIncluded(r, 60))), [device.formats])

Method

Parameters​

NameTypeDescription
rangeFrameRateRangeThe range to check if the given fps are included in
fpsnumberThe FPS to check if the given range supports.

Returns​

boolean

Defined in​

utils/FormatFilter.ts:85


isErrorWithCause​

â–¸ isErrorWithCause(error): error is ErrorWithCause

Checks if the given error is of type ErrorWithCause

Parameters​

NameTypeDescription
errorunknownAny unknown object to validate

Returns​

error is ErrorWithCause

true if the given error is of type ErrorWithCause

Defined in​

CameraError.ts:177


parsePhysicalDeviceTypes​

â–¸ parsePhysicalDeviceTypes(physicalDeviceTypes): PhysicalCameraDeviceType | LogicalCameraDeviceType

Parses an array of physical device types into a single PhysicalCameraDeviceType or LogicalCameraDeviceType, depending what matches.

Method

Parameters​

NameType
physicalDeviceTypesPhysicalCameraDeviceType[]

Returns​

PhysicalCameraDeviceType | LogicalCameraDeviceType

Defined in​

CameraDevice.ts:26


runAsync​

â–¸ runAsync(frame, func): void

Runs the given function asynchronously, while keeping a strong reference to the Frame.

For example, if you want to run a heavy face detection algorithm while still drawing to the screen at 60 FPS, you can use runAsync(...) to offload the face detection algorithm to a separate thread.

Example

const frameProcessor = useFrameProcessor((frame) => {
'worklet'
console.log('New Frame')
runAsync(frame, () => {
'worklet'
const faces = detectFaces(frame)
const face = [faces0]
console.log(`Detected a new face: ${face}`)
})
})

Parameters​

NameTypeDescription
frameFrameThe current Frame of the Frame Processor.
func() => voidThe function to execute.

Returns​

void

Defined in​

FrameProcessorPlugins.ts:138


runAtTargetFps​

â–¸ runAtTargetFps<T>(fps, func): T | undefined

Runs the given function at the given target FPS rate.

For example, if you want to run a heavy face detection algorithm only once per second, you can use runAtTargetFps(1, ...) to throttle it to 1 FPS.

Example

const frameProcessor = useFrameProcessor((frame) => {
'worklet'
console.log('New Frame')
runAtTargetFps(5, () => {
'worklet'
const faces = detectFaces(frame)
console.log(`Detected a new face: ${faces[0]}`)
})
})

Type parameters​

Name
T

Parameters​

NameTypeDescription
fpsnumberThe target FPS rate at which the given function should be executed
func() => TThe function to execute.

Returns​

T | undefined

The result of the function if it was executed, or undefined otherwise.

Defined in​

FrameProcessorPlugins.ts:82


sortDevices​

â–¸ sortDevices(left, right): number

Compares two devices by the following criteria:

  • wide-angle-cameras are ranked higher than others
  • Devices with more physical cameras are ranked higher than ones with less. (e.g. "Triple Camera" > "Wide-Angle Camera")

Note that this makes the sort() function descending, so the first element ([0]) is the "best" device.

Example

const devices = camera.devices.sort(sortDevices)
const bestDevice = devices[0]

Method

Parameters​

NameType
leftCameraDevice
rightCameraDevice

Returns​

number

Defined in​

utils/FormatFilter.ts:18


sortFormats​

â–¸ sortFormats(left, right): number

Sort formats by resolution and aspect ratio difference (to the Screen size).

Note that this makes the sort() function descending, so the first element ([0]) is the "best" device.

Parameters​

NameType
leftCameraDeviceFormat
rightCameraDeviceFormat

Returns​

number

Defined in​

utils/FormatFilter.ts:50


tryParseNativeCameraError​

â–¸ tryParseNativeCameraError<T>(nativeError): CameraCaptureError | CameraRuntimeError | T

Tries to parse an error coming from native to a typed JS camera error.

Method

Type parameters​

Name
T

Parameters​

NameTypeDescription
nativeErrorTThe native error instance. This is a JSON in the legacy native module architecture.

Returns​

CameraCaptureError | CameraRuntimeError | T

A CameraRuntimeError or CameraCaptureError, or the nativeError itself if it's not parsable

Defined in​

CameraError.ts:203


useCameraDevices​

â–¸ useCameraDevices(): CameraDevices

Gets the best available CameraDevice. Devices with more cameras are preferred.

Throws

CameraRuntimeError if no device was found.

Example

const device = useCameraDevice()
// ...
return <Camera device={device} />

Returns​

CameraDevices

The best matching CameraDevice.

Defined in​

hooks/useCameraDevices.ts:29

â–¸ useCameraDevices(deviceType): CameraDevices

Gets a CameraDevice for the requested device type.

Throws

CameraRuntimeError if no device was found.

Example

const device = useCameraDevice('wide-angle-camera')
// ...
return <Camera device={device} />

Parameters​

NameTypeDescription
deviceTypePhysicalCameraDeviceType | LogicalCameraDeviceTypeSpecifies a device type which will be used as a device filter.

Returns​

CameraDevices

A CameraDevice for the requested device type.

Defined in​

hooks/useCameraDevices.ts:44


useCameraFormat​

â–¸ useCameraFormat(device?): CameraDeviceFormat | undefined

Returns the best format for the given camera device.

This function tries to choose a format with the highest possible photo-capture resolution and best matching aspect ratio.

Parameters​

NameTypeDescription
device?CameraDeviceThe Camera Device

Returns​

CameraDeviceFormat | undefined

The best matching format for the given camera device, or undefined if the camera device is undefined.

Defined in​

hooks/useCameraFormat.ts:14


useFrameProcessor​

â–¸ useFrameProcessor(frameProcessor, dependencies): FrameProcessor

Returns a memoized Frame Processor function wich you can pass to the <Camera>. (See "Frame Processors")

Make sure to add the 'worklet' directive to the top of the Frame Processor function, otherwise it will not get compiled into a worklet.

Example

const frameProcessor = useFrameProcessor((frame) => {
'worklet'
const qrCodes = scanQRCodes(frame)
console.log(`QR Codes: ${qrCodes}`)
}, [])

Parameters​

NameTypeDescription
frameProcessor(frame: Frame) => voidThe Frame Processor
dependenciesDependencyListThe React dependencies which will be copied into the VisionCamera JS-Runtime.

Returns​

FrameProcessor

The memoized Frame Processor.

Defined in​

hooks/useFrameProcessor.ts:44


useSkiaFrameProcessor​

â–¸ useSkiaFrameProcessor(frameProcessor, dependencies): FrameProcessor

Returns a memoized Skia Frame Processor function wich you can pass to the <Camera>. The Skia Frame Processor allows you to draw anything onto the Frame using react-native-skia. (See "Frame Processors")

Make sure to add the 'worklet' directive to the top of the Frame Processor function, otherwise it will not get compiled into a worklet.

Example

const frameProcessor = useSkiaFrameProcessor((frame) => {
'worklet'
const qrCodes = scanQRCodes(frame)
frame.drawRect(...)
console.log(`QR Codes: ${qrCodes}`)
}, [])

Parameters​

NameTypeDescription
frameProcessor(frame: DrawableFrame) => voidThe Frame Processor
dependenciesDependencyListThe React dependencies which will be copied into the VisionCamera JS-Runtime.

Returns​

FrameProcessor

The memoized Frame Processor.

Defined in​

hooks/useFrameProcessor.ts:69