In order to enhance the user experience, various types of applications are committed to providing more intelligent and more efficient services through integrating artificial intelligence technology. Applications can not only interact with users through text and voice, but also analyze the content of the picture and provide users with accurate solutions.
Before analyzing the picture, the application first needs to accurately identify the elements contained in the picture. Based on this, Harmonyos SDKBasic vision services(Core Vision Kit)Multi -target recognition function, can simultaneously detect various objects in a given picture, including landscapes, animals, plants, buildings, trees, faces, tables, text, etc., and frame the objects. If necessary, you can also The recognition results are displayed on the interface.
Multi -target recognition function is a wide range of basic capabilities. In the application scenario of search engines, applications can be used to achieve image search and classification with the help of this ability; in AR games, multi -target recognition functions can identify players in front of the camera In order to interact with the content of virtual games; in addition, the multi -target recognition function can also be applied to the security monitoring system, and safety analysis and emergency response are performed by identifying pedestrians, vehicles, and other goals.
Development steps
1. When using multiple target recognition, add multi -target recognition classes to engineering.
import { BusinessError } from '@';
import { objectDetection, visionBase } from '@';
2. The layout of the simple configuration page, add a click event to the Button component, pull up the gallery, and select the picture.
Button('Select picture')
.type()
.fontColor()
.alignSelf()
.width('80%')
.margin(10)
.onClick(() => {
// Pull up the gallery and obtain image resources
();
})
3. Obtain picture resources through the gallery and convert the pictures into PixelMap.
private async selectImage() {
let uri = await ()
if (uri === undefined) {
(0x0000, 'objectDetectSample', "Failed to defined uri.");
}
(uri)
}
private openPhoto(): Promise<string> {
return new Promise<string>((resolve, reject) => {
let photoPicker: = new ();
({
MIMEType: .IMAGE_TYPE, maxSelectNumber: 1
}).then(res => {
resolve([0])
}).catch((err: BusinessError) => {
(0x0000, 'objectDetectSample', `Failed to get photo image uri. code:${},message:${}`);
reject('')
})
})
}
private loadImage(name: string) {
setTimeout(async () => {
let fileSource = await (name, .READ_ONLY);
= ();
= await ();
}, 100)
4. Instantly the Request object, and pass the Pixelmap to be detected, call the multi -target recognition function of multi -target recognition.
// Call the multi -target detection interface
Let Request: = {
InputData: {pixelmap:}
};
let data: = await (await ()). Process (request);
5. (Optional) If you need to display the results on the interface, you can use the following code.
let objectJson = (data);
(0x0000, 'objectDetectSample', `Succeeded in face detect:${objectJson}`);
= objectJson;
Learn more>>
accessBasic Vision Service Alliance official website
ObtainMulti -target recognition development guidance document