diff --git a/.planning/STATE.md b/.planning/STATE.md index 4805c86..1610cbe 100644 --- a/.planning/STATE.md +++ b/.planning/STATE.md @@ -22,6 +22,7 @@ | # | Description | Date | Commit | Directory | |---|-------------|------|--------|-----------| | 260330-ld1 | 在example的人脸识别预览页面增加注册按钮和人脸ID显示 | 2026-03-30 | 184c3a9 | [260330-ld1-example-id-id](./quick/260330-ld1-example-id-id/) | +| 260330-ll6 | 修复注册后不显示已注册状态的问题 | 2026-03-30 | - | [260330-ll6-fix-registration](./quick/260330-ll6-fix-registration/) | --- *State initialized: 2026-03-30* \ No newline at end of file diff --git a/.planning/quick/260330-ll6-fix-registration/260330-ll6-SUMMARY.md b/.planning/quick/260330-ll6-fix-registration/260330-ll6-SUMMARY.md new file mode 100644 index 0000000..79b074a --- /dev/null +++ b/.planning/quick/260330-ll6-fix-registration/260330-ll6-SUMMARY.md @@ -0,0 +1,36 @@ +# Quick Task 260330-ll6: Summary + +## Task +注册完成后并不会显示用户已注册,检查一下注册流程和检测流程。 + +## Problem Analysis +**问题根源**: +1. 检测时,`_getFaceKey()` 生成人脸特征标识 +2. 注册按钮只更新了 `_currentFaceIds` 列表,但**没有将特征标识和ID存入 `_faceIdMap`** +3. 下次检测时,`_faceIdMap` 为空,所有人脸都显示"未注册" + +## Fix +### `example/lib/main.dart` +1. **添加状态变量**: `_currentFaceKeys` - 保存当前帧的人脸特征标识列表 +2. **修改检测流程**: 同时保存特征标识和ID +3. **修改注册流程**: 注册时将特征标识和生成的ID存入 `_faceIdMap` + +## Code Changes + +```dart +// 新增: 保存当前帧的人脸特征标识 +List _currentFaceKeys = []; + +// 检测时: 同时保存特征标识 +_currentFaceKeys = faceList.map((face) => _getFaceKey(face)).toList(); +_currentFaceIds = _currentFaceKeys.map((key) => _faceIdMap[key] ?? '未注册').toList(); + +// 注册时: 将特征标识和ID存入映射表 +_faceIdMap[faceKey] = newId; +``` + +## Verification +- `flutter analyze lib/main.dart` - No issues found + +--- +*Completed: 2026-03-30* \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index a1d422d..acbd535 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -333,6 +333,8 @@ class _CameraPreviewScreenState extends State { final Map _faceIdMap = {}; /// 当前帧检测到的人脸ID列表 List _currentFaceIds = []; + /// 当前帧检测到的人脸特征标识列表(用于注册时关联) + List _currentFaceKeys = []; /// 随机数生成器 final Random _random = Random(); @@ -459,10 +461,12 @@ class _CameraPreviewScreenState extends State { _lastDetectionTime = timeStr; _rgbLivenessResult = rgbLiveness; _rgbLivenessStatus = rgbIsAlive ? '真人' : (rgbLiveness == 0 ? '非真人' : '未知'); - // 更新当前人脸ID列表 - _currentFaceIds = faceList.map((face) { - final faceKey = _getFaceKey(face as Map); - return _faceIdMap[faceKey] ?? '未注册'; + // 更新当前人脸特征标识和ID列表 + _currentFaceKeys = faceList.map((face) { + return _getFaceKey(face as Map); + }).toList(); + _currentFaceIds = _currentFaceKeys.map((key) { + return _faceIdMap[key] ?? '未注册'; }).toList(); }); } @@ -476,6 +480,7 @@ class _CameraPreviewScreenState extends State { _rgbLivenessResult = -1; _rgbLivenessStatus = '未检测'; _currentFaceIds = []; + _currentFaceKeys = []; }); } } @@ -713,11 +718,15 @@ class _CameraPreviewScreenState extends State { width: double.infinity, child: ElevatedButton.icon( onPressed: () { - // 为未注册的人脸生成随机ID + // 为未注册的人脸生成随机ID,并存入映射表 setState(() { for (int i = 0; i < _faceCount; i++) { if (_currentFaceIds[i] == '未注册') { - _currentFaceIds[i] = _generateRandomFaceId(); + final newId = _generateRandomFaceId(); + final faceKey = _currentFaceKeys[i]; + // 将特征标识和ID存入映射表 + _faceIdMap[faceKey] = newId; + _currentFaceIds[i] = newId; } } });