UNPKG

id-scanner-lib

Version:

Browser-based ID card, QR code, and face recognition scanner with liveness detection

82 lines (81 loc) 2.26 kB
/** * @file 相机工具类 * @description 提供访问和控制设备摄像头的功能 * @module Camera */ /** * 相机配置选项接口 * * @interface CameraOptions * @property {number} [width] - 视频宽度,默认为640 * @property {number} [height] - 视频高度,默认为480 * @property {string} [facingMode] - 摄像头朝向,'user'为前置摄像头,'environment'为后置摄像头,默认为'environment' */ export interface CameraOptions { width?: number; height?: number; facingMode?: 'user' | 'environment'; } /** * 相机工具类 * * 提供访问设备摄像头、获取视频流以及捕获图像帧的功能 * * @example * ```typescript * // 创建相机实例 * const camera = new Camera({ * width: 1280, * height: 720, * facingMode: 'environment' // 使用后置摄像头 * }); * * // 初始化相机 * const videoElement = document.getElementById('video') as HTMLVideoElement; * await camera.start(videoElement); * * // 捕获当前视频帧 * const imageData = camera.captureFrame(); * * // 使用结束后释放资源 * camera.stop(); * ``` */ export declare class Camera { private options; private stream; private videoElement; /** * 创建相机实例 * @param {CameraOptions} [options] - 相机配置选项 */ constructor(options?: CameraOptions); /** * 启动摄像头并将视频流绑定到视频元素 * @param videoElement HTML视频元素 * @returns Promise<void> */ start(videoElement: HTMLVideoElement): Promise<void>; /** * 停止摄像头并释放资源 */ stop(): void; /** * 初始化相机,获取视频流并绑定到视频元素 * * @param {HTMLVideoElement} videoElement - 用于显示视频流的视频元素 * @returns {Promise<void>} 初始化完成的Promise * @throws 如果无法访问摄像头,将抛出错误 */ initialize(videoElement: HTMLVideoElement): Promise<void>; /** * 捕获当前视频帧 * * @returns {ImageData|null} 视频帧的ImageData对象,如果未初始化则返回null */ captureFrame(): ImageData | null; /** * 释放摄像头资源 */ release(): void; }