FrameConverter
interface FrameConverter extends HybridObjectThe FrameConverter can convert Frames
and Depth to Images, and back.
Methods
convertDepthToImage(...)
Converts the Depth frame to an Image.
The resulting Image will be a grey-scale RGB image,
where black pixels are far away, and white pixels are close by.
convertDepthToImageAsync(...)
convertFrameToImage(...)
Converts the given Frame to an Image.
This performs a CPU copy.
Throws
If the Frame is invalid (Frame.isValid).
convertFrameToImageAsync(...)
Asynchronously converts this Frame to an
Image.
This performs a CPU copy.
Throws
If the Frame is invalid (Frame.isValid).
convertImageToFrame(...)
convertImageToFrame(
image: Image,
orientation: CameraOrientation,
isMirrored: boolean): FrameConverts the given Image to a Frame,
as if the Camera had streamed it in the given orientation
and isMirrored mode.
This is the inverse of convertFrameToImage(...);
the Image's pixel data is physically rotated and mirrored so that
interpreting the resulting Frame with its
orientation and
isMirrored flags yields the original
upright Image again.
This performs a CPU copy.
The resulting Frame is in a CPU-accessible, camera-like
PixelFormat - a 4:2:0 YUV format
('yuv-420-8-bit-full') on iOS, and RGBA
('rgb-rgba-8-bit') on Android.
The RGB -> YUV conversion on iOS is lossy - expect pixel values
to be off by a small amount.
Note
Since YUV 4:2:0 requires even dimensions, odd Image
dimensions are rounded down to the nearest even number.
Throws
If the Image has already been disposed, or its pixel data cannot be accessed.
Example
const image = await loadImage({ filePath: '...' })
const frame = HybridFrameConverter.convertImageToFrame(image, 'up', false)
console.log(`${frame.width}x${frame.height} ${frame.pixelFormat} Frame`)
// process the Frame, e.g. scan it for barcodes or resize it...
frame.dispose()convertImageToFrameAsync(...)
convertImageToFrameAsync(
image: Image,
orientation: CameraOrientation,
isMirrored: boolean): Promise<Frame>Asynchronously converts the given Image to a
Frame, as if the Camera had streamed it in the
given orientation and isMirrored mode.
This performs a CPU copy.
See
Throws
If the Image has already been disposed, or its pixel data cannot be accessed.