Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
As a basic visual capability library, visionBase encapsulates common elements in visual capability scenarios, such as basic resource objects, data structures, and common methods. It helps reduce the coding workload and simplifies the use of functional APIs. You can consider visionBase as a toolbox containing the most common tools. With this base class, you can implement your functions more efficiently while complying with necessary standards. In addition, visionBase provides the infrastructure required by Core Vision Kit AI capabilities, such as data structures, API models, and lifecycle management.
Since: 5.0.0(12)
import { visionBase } from '@kit.CoreVisionKit'; Enumerates scene modes. It indicates the service scene mode corresponding to the request. The engine server sets the task priority based on this mode.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| FOREGROUND | 1 | Foreground mode (default value). |
| BACKGROUND | 2 | Background mode. |
Describes the visual information object to be recognized.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| pixelMap | image.PixelMap | No | No | Image to be recognized. |
type InputData = ImageData | ImageData[]
Defines an array consisting of multiple pieces of image data.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
Describes the bounding box for AI visual capabilities.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| left | number | No | No | X coordinate of the upper left corner of a bounding box. |
| top | number | No | No | Y coordinate of the upper left corner of a bounding box. |
| height | number | No | No | Height of a bounding box, in pixels. |
| width | number | No | No | Width of a bounding box, in pixels. |
Describes a point on a 2D plane.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| x | number | No | No | X coordinate of a point. |
| y | number | No | No | Y coordinate of a point. |
Describes the orientation on a 3D plane.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| yaw | number | No | No | Yaw angle of rotating an object around the vertical axis (Y axis), which determines the direction of the object on the horizontal plane. Value range: [–180, 180] |
| pitch | number | No | No | Pitch angle of rotating an object around the horizontal axis (X axis), which determines the direction of the object on the vertical plane. Value range: [–180, 180] |
| roll | number | No | No | Roll angle of rotating an object around the Z axis, which determines the direction of the object on the plane perpendicular to the X and Y planes. Value range: [–180, 180] |
Describes the data structure of download start events triggered when AI model download starts. It is used to inform you of the resource that starts to be downloaded. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| resId | string | No | No | Resource ID, which is used to identify the model that is being downloaded. |
Describes the data structure of download completion events triggered when model download is complete. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| resId | string | No | No | Resource ID. |
| resVersion | string | No | No | Resource version number. |
Describes the data structure of download cancellation events triggered when the download process is canceled. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| resId | string | No | No | Resource ID. |
Describes the data structure of download status events, which is used to report various statuses during the download process, such as network errors and invalid parameters. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| resId | string | No | No | Resource ID. |
| statusCode | downloadStatusCode | No | No | Status code. |
| message | string | No | No | Status description. The description is not fixed. |
Describes the data structure of download progress events, which is used to report the download progress so that you can display the progress in real time. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| resId | string | No | No | Resource ID. |
| progressInfo | string | No | No | Progress information. |
Enumerates download statuses. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
| Name | Value | Description |
|---|---|---|
| PARAMETER_INVALID | 0 | Incorrect input download parameter. For example, the resource ID format is incorrect. You are advised to check the format and validity of input parameters. |
| NO_NETWORK_STATUS | 1 | The device is offline or the network is unavailable. You are advised to ask the user to check the network connection. |
| NO_MODEL | 2 | The corresponding model file cannot be found on the server. You are advised to check whether the model's resource ID is correct and whether the model file exists on the server. |
| COPY_FILE_FAILED | 3 | A downloaded model file cannot be copied to the specified location. You are advised to check the storage permission and available space. |
| DOWNLOAD_NOT_ALLOWED | 4 | The user has chosen to reject the download in the scenario where user confirmation is required. |
| DOWNLOAD_TIME_OUT | 5 | The network is slow or the server response is delayed. |
| DOWNLOAD_EXCEPTION | 6 | An error occurs during the download process. This value is used to refer to any other unspecified errors. |
| DOWNLOAD_BACK_TO_DESKTOP | 7 | The user switches out of the app during the download process. |
| TASK_BUSY | 8 | The system is busy and is currently executing another task. Since: 6.0.0(20) |
Describes the base class of input parameters.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| inputData | InputData | No | No | Image to be recognized. The value can be an object or an array of objects. |
| scene | SceneMode | No | Yes | Scene mode. The default value is SceneMode.FOREGROUND (foreground mode). This parameter is reserved and not implemented currently. |
| requestId | string | No | Yes | Request ID. You can use it to trace and manage your requests. The default value is an empty string. This parameter is reserved and not implemented currently. |
Describes the response base class, which is used as the returned result of a capability request.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| requestId | string | No | Yes | Unique ID of a request, which is used by developers to trace and manage their own requests. This ID corresponds to the request ID. The default value is an empty string. |
Describes the analyzer base class, which functions as the capability engine.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
destroy(): Promise<void>
Destroys the processes of multiple visual capabilities. This API returns the result asynchronously through a promise.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.0(12)
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example:
on(type: 'downloadStart', callback: Callback<DownloadStartData>): void
Subscribes to the model download start event. This event is triggered when the model download starts. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is 'downloadStart', indicating that the model download starts. |
| callback | Callback<DownloadStartData> | Yes | Callback function, which is triggered when the model download starts to return the identifier of the resource that starts to be downloaded. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
visionBase.on('downloadStart', (data) => {
console.info(`Resource ${data.resId} starts to be downloaded`);
});
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering the download start event.
})
}
}
} on(type: 'downloadComplete', callback: Callback<DownloadCompleteData>): void
Subscribes to the model download completion event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is 'downloadComplete', indicating that the model download is complete. |
| callback | Callback<DownloadCompleteData> | Yes | Callback function, which is triggered when the model download is complete to return the identifier and version number of the downloaded resource. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
visionBase.on('downloadComplete', (data) => {
console.info(`Resource ${data.resId} has been downloaded. Version: ${data.resVersion}`);
});
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering the download completion event.
})
}
}
} on(type: 'downloadCancel', callback: Callback<DownloadCancelData>): void
Subscribes to the model download cancellation event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is 'downloadCancel', indicating that the model download is canceled. |
| callback | Callback<DownloadCancelData> | Yes | Callback function, which is triggered when the model download is canceled to return the identifier of the resource whose download is canceled. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
visionBase.on('downloadCancel', (data) => {
console.info(`Download of resource ${data.resId} has been canceled`);
});
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering the download cancellation event.
})
}
}
} on(type: 'downloadStatus', callback: Callback<DownloadStatusData>): void
Subscribes to the model download status event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is downloadStatus, indicating the model download status event. |
| callback | Callback<DownloadStatusData> | Yes | Callback function, which is triggered when the model download status changes to return the current download status. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
visionBase.on('downloadStatus', (data) => {
console.info(`Download status of resource ${data.resId}: ${data.statusCode}, ${data.message}`);
});
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering the download status event.
})
}
}
} on(type: 'downloadProgress', callback: Callback<DownloadProgressData>): void
Subscribes to the model download progress event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is 'downloadProgress', indicating the model download progress event. |
| callback | Callback<DownloadProgressData> | Yes | Callback function, which is triggered when the model download progress is updated to return the current download progress. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
visionBase.on('downloadProgress', (data) => {
console.info(`Download progress of resource ${data.resId}: ${data.progressInfo}`);
});
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering the download progress event.
})
}
}
} off(type: 'downloadStart', callback?: Callback<DownloadStartData>): void
Unsubscribes from the model download start event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed to downloadStart, indicating unsubscription from the model download start event. |
| callback | Callback<DownloadStartData> | No | Callback function to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callback functions will be unregistered. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
// Define a callback.
const startCallback = (data: visionBase.DownloadStartData) => {
console.info(`Resource ${data.resId} starts to be downloaded`);
};
// Register a listener.
visionBase.on('downloadStart', startCallback);
// Unregister the listener.
visionBase.off('downloadStart', startCallback);
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering unsubscription from the download start event.
})
}
}
} off(type: 'downloadComplete', callback?: Callback<DownloadCompleteData>): void
Deregisters the listener for the model download completion event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed to downloadComplete, indicating unsubscription from the model download completion event. |
| callback | Callback<DownloadCompleteData> | No | Callback function to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callback functions will be unregistered. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
// Define a callback.
const callback = (data: visionBase.DownloadCompleteData) => {
console.info(`Resource ${data.resId} has been downloaded`);
};
// Register a listener.
visionBase.on('downloadComplete', callback);
// Unregister the listener.
visionBase.off('downloadComplete', callback);
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering unsubscription from the download completion event.
})
}
}
} off(type: 'downloadCancel', callback?: Callback<DownloadCancelData>): void
Unsubscribes from the model download cancellation event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed to downloadCancel, indicating unsubscription from the model download cancellation event. |
| callback | Callback<DownloadCancelData> | No | Callback function to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callback functions will be unregistered. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
// Define a callback.
const callback = (data: visionBase.DownloadCancelData) => {
console.info(`Download of resource ${data.resId} has been canceled`);
};
// Register a listener.
visionBase.on('downloadCancel', callback);
// Unregister the listener.
visionBase.off('downloadCancel', callback);
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering unsubscription from the download cancellation event.
})
}
}
} off(type: 'downloadStatus', callback?: Callback<DownloadStatusData>): void
Unsubscribes from the model download status event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed to downloadStatus, indicating unsubscription from the model download status event. |
| callback | Callback<DownloadStatusData> | No | Callback function to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callback functions will be unregistered. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
// Define a callback.
const callback = (data: visionBase.DownloadStatusData) => {
console.info(`Download status of resource ${data.resId}`);
};
// Register a listener.
visionBase.on('downloadStatus', callback);
// Unregister the listener.
visionBase.off('downloadStatus', callback);
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering unsubscription from the download status event.
})
}
}
} off(type: 'downloadProgress', callback?: Callback<DownloadProgressData>): void
Unsubscribes from the model download progress event. This API is reserved and is not supported in the current version.
System capability: SystemCapability.AI.Vision.VisionBase
Model restriction: This API can be used only in the stage model.
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Event type. The value is fixed to downloadProgress, indicating unsubscription from the model download progress event. |
| callback | Callback<DownloadProgressData> | No | Callback function to be unregistered, which must be the same as that passed upon subscription. If this parameter is not passed, all callback functions will be unregistered. |
Error codes:
For details about the error codes, please refer to Core Vision Kit Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | The parameter check failed. |
Example:
import { visionBase } from '@kit.CoreVisionKit';
// Define a callback.
const callback = (data: visionBase.DownloadProgressData) => {
console.info(`Download progress of resource ${data.resId}`);
};
// Register a listener.
visionBase.on('downloadProgress', callback);
// Unregister the listener.
visionBase.off('downloadProgress', callback);
@Entry
@Component
struct Page {
build() {
Column(){
Button('Button').onClick(() => {
// Service logic for triggering unsubscription from the download progress event.
})
}
}
}