UNPKG

id-scanner-lib

Version:

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

171 lines (170 loc) 4.36 kB
/** * @file 身份证防伪检测模块 * @description 提供身份证防伪特征识别功能,区分真假身份证 * @module AntiFakeDetector * @version 1.3.2 */ import { Disposable } from "../../utils/resource-manager"; /** * 防伪检测结果 */ export interface AntiFakeDetectionResult { isAuthentic: boolean; confidence: number; detectedFeatures: string[]; message: string; processingTime?: number; } /** * 防伪检测器配置选项 */ export interface AntiFakeDetectorOptions { sensitivity?: number; enableCache?: boolean; cacheSize?: number; logger?: (message: string) => void; } /** * 身份证防伪特征检测器 * * 基于图像分析技术检测身份证中的多种防伪特征,包括: * 1. 荧光油墨特征 * 2. 微缩文字 * 3. 光变图案 * 4. 雕刻凹印 * 5. 隐形图案 * * @example * ```typescript * // 创建防伪检测器 * const antiFakeDetector = new AntiFakeDetector({ * sensitivity: 0.8, * enableCache: true * }); * * // 分析身份证图像 * const imageData = await ImageProcessor.createImageDataFromFile(idCardFile); * const result = await antiFakeDetector.detect(imageData); * * if (result.isAuthentic) { * console.log('身份证真实,检测到防伪特征:', result.detectedFeatures); * } else { * console.log('警告!', result.message); * } * ``` */ export declare class AntiFakeDetector implements Disposable { private options; private resultCache; /** * 创建身份证防伪检测器实例 * * @param options 防伪检测器配置 */ constructor(options?: AntiFakeDetectorOptions); /** * 检测身份证图像的防伪特征 * * @param imageData 身份证图像数据 * @returns 防伪检测结果 */ detect(imageData: ImageData): Promise<AntiFakeDetectionResult>; /** * 增强身份证图像中的防伪特征 * * @param imageData 原始图像数据 * @returns 增强后的图像数据 * @private */ private enhanceAntiFakeFeatures; /** * 检测荧光油墨特征 * * @param imageData 图像数据 * @returns [特征名称, 是否检测到, 置信度] * @private */ private detectUVInkFeatures; /** * 从图像数据中提取指定颜色通道 * @param imageData 原始图像数据 * @param channel 通道名称(red, green, blue) */ private extractColorChannel; /** * 分析颜色通道分布特征 * @param channelData 颜色通道数据 */ private analyzeChannelDistribution; /** * 平滑直方图以减少噪声 */ private smoothHistogram; /** * 检测图像中的荧光颜色模式 */ private detectUVColorPattern; /** * 分析头像区域是否存在荧光特征 * 这个方法用于检测伪造的身份证,因为头像区域不应该有荧光特征 */ private analyzePortraitArea; /** * 检测微缩文字 * * @param imageData 图像数据 * @returns [特征名称, 是否检测到, 置信度] * @private */ private detectMicroText; /** * 分析边缘图像的频率特征 * 微缩文字呈现高频的边缘过渡 */ private analyzeFrequencyFeatures; /** * 检测微缩文字区域 * 微缩文字通常呈现呈现规则的组合排列 */ private detectMicroTextRegions; /** * 深度优先搜索连通的边缘区域 */ private floodFillEdge; /** * 获取点集的外接矩形 */ private getBoundingBox; /** * 检测光变图案 * * @param imageData 图像数据 * @returns [特征名称, 是否检测到, 置信度] * @private */ private detectOpticalVariable; /** * 检测凹印雕刻特征 * * @param imageData 图像数据 * @returns [特征名称, 是否检测到, 置信度] * @private */ private detectIntaglioPrinting; /** * 检测隐形图案(幽灵图像) * * @param imageData 图像数据 * @returns [特征名称, 是否检测到, 置信度] * @private */ private detectGhostImage; /** * 清除结果缓存 */ clearCache(): void; /** * 释放资源 */ dispose(): void; }