harmony 鸿蒙Depth Data (for System Applications Only) (ArkTS)
Depth Data (for System Applications Only) (ArkTS)
Depth data reflects the spatial arrangement of image pixels in relation to the camera lens. It facilitates enhanced focus precision, background blurring effects, and the like. Depth data can be reported in the preview, photo capture, and video scenarios of camera applications.
How to Develop
Read Camera for the API reference.
- Import the camera module, which provides camera-related attributes and methods.
import { camera } from '@kit.CameraKit';
import { BusinessError } from '@kit.BasicServicesKit';
- Use depthProfiles in the CameraOutputCapability class to obtain the depth data capabilities, in the format of an depthProfilesArray array, supported by the current device. Call createDepthDataOutput to create a depth data stream.
function getDepthDataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): camera.DepthDataOutput|undefined {
let depthProfilesArray: Array<camera.DepthProfile> = cameraOutputCapability.depthProfiles;
if (!depthProfilesArray) {
console.error("createOutput depthProfilesArray is null");
}
let depthDataOutput: camera.DepthDataOutput|undefined = undefined;
try {
depthDataOutput = cameraManager.createDepthDataOutput(depthProfilesArray[0]);
} catch (error) {
let err = error as BusinessError;
console.error(`Failed to create the DepthDataOutput instance. error: ${err}`);
}
return depthDataOutput;
}
- Call start in the depthDataOutput class to start outputting the depth data stream. If the call fails, an error code is returned. For details about the error code types, see CameraErrorCode.
async function startDepthDataOutput(depthDataOutput: camera.DepthDataOutput): Promise<void> {
if (!depthDataOutput) {
console.error('depthDataOutput Undefined');
return;
}
try {
await depthDataOutput.start();
} catch (err) {
const error = err as BusinessError;
console.error(`Failed to start depth data output. error: ${err}`);
}
}
Status Listening
During camera application development, you can listen for depth data and depth data output errors.
- Register the fixed callback function depthDataAvailable to obtain the depth data.
function onDepthDataAvailable(depthDataOutput: camera.DepthDataOutput): void {
depthDataOutput.on('depthDataAvailable', (err: BusinessError) => {
if (err !== undefined && err.code !== 0) {
return;
}
console.info('Depth data available');
});
}
- Register the ‘error’ event to listen for depth data output errors. The callback function returns an error code when an API is incorrectly used. For details about the error code types, see CameraErrorCode.
function onDepthDataOutputError(depthDataOutput: camera.DepthDataOutput): void {
depthDataOutput.on('error', (depthDataOutputError: BusinessError) => {
console.error(`Depth data output error code: ${depthDataOutputError.code}`);
});
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Basic Camera Animation (ArkTS)
harmony 鸿蒙Practices for Camera Recovery from the Background (ArkTS)
harmony 鸿蒙Deferred Photo Delivery Practices (ArkTS)
harmony 鸿蒙Deferred Photo Delivery (ArkTS)
harmony 鸿蒙Practices for High-Performance Photo Capture (for System Applications Only) (ArkTS)
harmony 鸿蒙High-Performance Photo Capture (for System Applications Only) (ArkTS)
harmony 鸿蒙Device Input Management (ArkTS)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦