AVCaptureMetadataOutputDetectEvent:objects 属性
objects 属性是这一帧里认到的全部。
值
数组,至少一个元素。数组是冻结的,里面的对象也都只读。
- 只读。给它赋值抛
TypeError。 - 认到的是码时,元素是
AVMetadataMachineReadableCodeObject,有stringValue(码里的文字)和corners(四个角)。读stringValue之前先用instanceof判断。 - 认到的是人脸这类时,元素是
AVMetadataObject,只有type和bounds。 bounds和corners是 0 到 1 的比例,见画面里的坐标。- 用
new创建时没给,是 冻结的空数组。
示例
js
const output = new AVCaptureMetadataOutput();
output.addEventListener('detect', (e) => {
for (const found of e.objects) {
if (found instanceof AVMetadataMachineReadableCodeObject) {
console.log(found.type, found.stringValue);
}
}
});效果:取景画面里有码时,每一帧输出码的种类和里面的文字。
对应的 iOS API
captureOutput:didOutputMetadataObjects:fromConnection: 的参数 metadataObjects。