harmony 鸿蒙Camera Metadata
Camera Metadata
Metadata is the description and context of image information returned by the camera application. It provides detailed data for the image information, for example, coordinates of a viewfinder frame for identifying a portrait in a photo or a video.
Metadata uses a tag (key) to find the corresponding data during the transfer of parameters and configurations, reducing memory copy operations.
How to Develop
Read Camera for the API reference.
Import the modules.
import camera from '@ohos.multimedia.camera'; import { BusinessError } from '@ohos.base';
Obtain the metadata types supported by the current device from supportedMetadataObjectTypes in CameraOutputCapability, and then use createMetadataOutput() to create a metadata output stream.
function getMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): camera.MetadataOutput|undefined {
let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes;
let metadataOutput: camera.MetadataOutput|undefined = undefined;
try {
metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
} catch (error) {
let err = error as BusinessError;
console.info('Failed to createMetadataOutput, error code: '+ err.code);
}
return metadataOutput;
}
- Call start() to start outputting metadata. If the call fails, an error code is returned. For details, see Camera Error Codes.
function startMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.start().then(() => {
console.info('Callback returned with metadataOutput started.');
}).catch((err: BusinessError) => {
console.info('Failed to metadataOutput start, error code: '+ err.code);
});
}
- Call stop() to stop outputting metadata. If the call fails, an error code is returned. For details, see Camera Error Codes.
function stopMetadataOutput(metadataOutput: camera.MetadataOutput): void {
metadataOutput.stop().then(() => {
console.info('Callback returned with metadataOutput stopped.');
}).catch((err: BusinessError) => {
console.info('Failed to metadataOutput stop '+ err.code);
});
}
Status Listening
During camera application development, you can listen for the status of metadata objects and output stream.
- Register the ‘metadataObjectsAvailable’ event to listen for metadata objects that are available. When a valid metadata object is detected, the callback function returns the metadata. This event can be registered when a MetadataOutput object is created.
function onMetadataObjectsAvailable(metadataOutput: camera.MetadataOutput): void {
metadataOutput.on('metadataObjectsAvailable', (err: BusinessError, metadataObjectArr: Array<camera.MetadataObject>) => {
console.info(`metadata output metadataObjectsAvailable`);
});
}
NOTE
Currently, only FACE_DETECTION is available for the metadata type. The metadata object is the rectangle of the recognized face, including the x-axis coordinate and y-axis coordinate of the upper left corner of the rectangle as well as the width and height of the rectangle.
- Register the ‘error’ event to listen for metadata stream errors. The callback function returns an error code when an API is incorrectly used. For details about the error code types, see Camera Error Codes.
function onMetadataError(metadataOutput: camera.MetadataOutput): void {
metadataOutput.on('error', (metadataOutputError: BusinessError) => {
console.info(`Metadata output error code: ${metadataOutputError.code}`);
});
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Developing Audio Call
harmony 鸿蒙Audio Call Development
harmony 鸿蒙Audio Effect Management
harmony 鸿蒙Audio Input Device Management
harmony 鸿蒙Audio Output Device Management
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦