FrameConverter

interface FrameConverter extends HybridObject

The FrameConverter can convert Frames and Depth to Images, and back.

Methods

convertDepthToImage(...)

convertDepthToImage(depth: Depth): Image

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(...)

convertDepthToImageAsync(depth: Depth): Promise<Image>

convertFrameToImage(...)

convertFrameToImage(frame: Frame): Image

Converts the given Frame to an Image. This performs a CPU copy.

Throws

If the Frame is invalid (Frame.isValid).


convertFrameToImageAsync(...)

convertFrameToImageAsync(frame: Frame): Promise<Image>

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): Frame

Converts 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 RGB PixelFormat ('rgb-bgra-8-bit' on iOS, 'rgb-rgba-8-bit' on Android), so the conversion is lossless.

Note

Since the pixel data is physically rotated, the resulting Frame's width and height are flipped if orientation is 'left' or 'right'.

Note

The resulting Frame has to be disposed (see dispose()) again to free up its memory.

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

convertImageToFrame(...)

Throws

If the Image has already been disposed, or its pixel data cannot be accessed.