Interface: Media
torchlive/media.Media
Methods
imageFromBlob
▸ imageFromBlob(blob
, width
, height
): Image
deprecated
This function will be removed in the next release. Use imageFromTensor
instead.
const tensor = torch.fromBlob(blob, [imageHeight, imageWidth, channels]);
const image = media.imageFromTensor(tensor);
Converts a Blob into an Image. The blob should be in RGB format.
The width and height input should match the blob size.
i.e. blob.getDirectSize()
equals width * height * 3
.
Parameters
Name | Type | Description |
---|---|---|
blob | Blob | Blob to turn into an Image. |
width | number | The width of the image. |
height | number | - |
Returns
An Image object created from the Blob.
imageFromFile
▸ imageFromFile(filepath
): Image
experimental
This function is experimental and can change.
Loads an Image from a file. The function will throw an error if the image couldn't be loaded.
Parameters
Name | Type | Description |
---|---|---|
filepath | string | A local file path to an image. |
Returns
An Image loaded from filepath.
imageFromFrame
▸ imageFromFrame(frame
): Image
Converts a VisionCamera Frame
into an Image. This function has to be called inside a Frame Processor, as the Frame only exists inside a Frame Processor.
Parameters
Name | Type | Description |
---|---|---|
frame | unknown | [[Frame]] to turn into an Image. |
Returns
An Image object created from the [[Frame]].
imageFromTensor
▸ imageFromTensor(tensor
): Image
Converts a Tensor into an Image. The tensor should be in CHW (channels, height, width) format, with uint8 type.
There are some assumptions made about the input tensor:
- If the tensor has 4 channels, it is assumed to be RGBA.
- If the tensor has 3 channels, it is assumed to be RGB.
- If the tensor has 1 channel, it is assumed to be grayscale.
Parameters
Name | Type | Description |
---|---|---|
tensor | Tensor | Tensor to turn into an Image. |
Returns
An Image object created from the Tensor.
imageToFile
▸ imageToFile(image
, filepath
): string
experimental
This function is experimental and can change.
Saves an Image to a file. The second argument is the local filepath at
which the image will be saved. The filepath can be created by using a
third-party React Native package like react-native-fs
(i.e., RNFS).
const image = await ImageUtil.fromURL('https://example.com/image.jpg');
const filepath = media.imageToFile(
image,
RNFS.DownloadDirectoryPath + '/saved_image.png',
);
image.release();
The function will throw an error if the Image couldn't be saved.
Parameters
Name | Type | Description |
---|---|---|
image | Image | Image that should be saved to a file. |
filepath | string | The filepath at which the image will be saved. |
Returns
string
The filepath of the saved image.
toBlob
▸ toBlob(obj
): Blob
Converts a Tensor or NativeJSRef into a Blob. The blob can be used to create a Tensor object or convert into a NativeJSRef like an image or audio.
Parameters
Name | Type | Description |
---|---|---|
obj | NativeJSRef | Tensor | Object to turn into a Blob. |