jibinbabyai/Foresight-AI---Prompt-Engineering
GitHub: jibinbabyai/Foresight-AI---Prompt-Engineering
一个完全离线运行的失踪人员检测系统,通过对CCTV监控视频进行深度学习人脸识别,自动匹配参考照片并生成检测报告。
Stars: 1 | Forks: 0
# 🔍 Foresight AI — 失踪人员检测系统





## 🧠 概述
**Foresight AI** 是一个完全**离线**、生产级的**计算机视觉 (Computer Vision)** 应用程序,旨在通过对 CCTV 监控视频进行智能人脸识别,协助失踪人员的调查工作。该项目作为一套**端到端 AI pipeline** 从零构建,集成了基于深度学习的人脸编码、启发式口罩检测、实时视频处理以及精致的桌面 GUI —— 所有功能均在本地运行,无需任何云端依赖。
此项目展示了 AI 工程解决方案的完整生命周期:
- 🎯 **问题定义** — 自动化监控录像的人工审查流程
- 🔬 **模型集成** — 使用预训练深度学习模型进行人脸嵌入 (dlib + face_recognition)
- 🖥️ **端到端开发** — 涵盖数据摄取、推理、报告生成以及完全交互式的 UI
- ⚙️ **性能工程** — 针对普通硬件优化的跳帧处理、多线程处理和视频 I/O
## ✨ 主要功能
| 功能 | 描述 |
|---|---|
| 🧬 **深度学习人脸识别** | 通过 `face_recognition` + `dlib` 使用基于 ResNet 的模型编码参考人脸 |
| 🎭 **启发式口罩检测** | 利用对人脸区域的灰度标准差分析来检测面部遮挡物 |
| ⚡ **优化的视频处理** | 跳帧(每第 N 帧)和基于 FFmpeg 的片段提取,适用于低内存运行环境 |
| 🎛️ **实时控制** | 使用 `threading.Event` 信号在运行中暂停、恢复和停止检测 |
| 📊 **自动报告生成** | 生成包含时间戳和置信度分数的 `.txt` 和 `.csv` (pandas) 检测报告 |
| 🗂️ **基于任务的隔离** | 每项调查都是一个独立的任务文件夹,具有结构化的子目录 |
| 🖥️ **现代桌面 GUI** | 使用 CustomTkinter 构建的深色主题、堆栈导航 UI —— 支持实时视频预览和进度追踪 |
| 🔒 **完全离线** | 零互联网或云端依赖 —— 完全在本地硬件上运行 |
## 🏗️ 系统架构
```
Foresight-AI/
│
├── main.py # Entry point — CustomTkinter GUI (FaceRecognitionApp)
├── detection.py # Core AI engine — EnhancedDetectionEngine (face recognition + mask detection)
├── video_processing.py # FFmpeg wrapper for frame extraction and video clip creation
├── database.py # In-memory detection store + .txt/.csv report generator
├── config.py # Centralized config manager with dot-notation access and YAML override
│
├── requirements.txt # Pinned dependencies for reproducibility
├── config.yaml # (Optional) External config override
│
└── tasks/ # Auto-generated per task
└── {TaskName}/
├── detected_faces/ ← Cropped face images from detections
├── reports/ ← Generated .txt and .csv reports
├── temp/ ← Short video clips recorded at detection events
├── reference_image/ ← Copies of user-provided reference photos
└── cctv_footage/ ← Copy of the analysed video file
```
## 🔬 AI Pipeline — 工作原理
```
Reference Images (1–4 photos)
↓
[face_recognition] → Extract 128-dimensional face embeddings (ResNet-based)
↓
CCTV Video → OpenCV VideoCapture → Frame-by-Frame Iteration
↓ (every Nth frame, configurable)
[face_recognition] → Detect face locations → Compute encodings
↓
Euclidean distance comparison vs. reference encodings
↓ ↓
MATCH FOUND No match → skip
↓
Crop face region → Mask Detection (grayscale std-dev heuristic)
↓
Draw bounding box (Green = masked, Red = unmasked)
↓
Save face crop + Start recording .avi clip
↓
Update GUI preview + progress bar (via thread callbacks)
↓
Auto-generate .txt and .csv reports on completion
```
## 🖥️ GUI 演示
桌面应用程序采用**基于堆栈的导航系统** —— 每个屏幕都可以前进和后退导航,并且所有 UI 交互都封装在 `@safe_run` 装饰器中,以便在不崩溃的情况下优雅地处理错误。
**屏幕:**
1. **主屏幕** — 创建任务、选择视频、添加参考图像(最多 4 张)、开始/暂停/停止检测
2. **结果屏幕** — 按文件夹浏览检测到的人脸、报告、截取片段和参考图像
3. **任务屏幕** — 查看、打开或删除所有过去的调查任务
## ⚙️ 配置
所有参数均可通过 `config.yaml` 或 `Config` 类默认值进行配置:
```
frame_skip: 5 # Process every 5th frame
detection_threshold: 0.5 # Maximum face distance for a match (lower = stricter)
mask_std_threshold: 20 # Grayscale std-dev below this value = mask detected
clip_duration_seconds: 5 # Duration of video clip saved on detection
max_reference_images: 4 # Max number of reference photos per task
ui_settings:
theme: dark
accent_color: "#00ff88"
font: Arial
```
## 🔧 技术栈
| 层级 | 技术 |
|---|---|
| **计算机视觉** | OpenCV 4.6, face_recognition 1.3.0 |
| **深度学习模型** | dlib (ResNet face encoder), face_recognition_models |
| **视频处理** | FFmpeg via `ffmpeg-python` |
| **GUI 框架** | CustomTkinter 5.2.0 (dark mode) |
| **数据与报告** | pandas, numpy |
| **图像处理** | Pillow (PIL) |
| **配置** | PyYAML, Python dataclasses |
| **并发** | Python `threading` 模块 |
## 🚀 入门指南
### 前置条件
- Python 3.9 或更高版本
- Windows 11(也可在 Windows 10 上运行)
- 在 Windows 上编译 dlib:通过 Visual Studio Build Tools 安装 **Desktop development with C++** (MSVC v142/v143)
### 安装
```
# Clone 仓库
git clone https://github.com/yourusername/Foresight-AI.git
cd Foresight-AI
# Install 依赖
pip install -r requirements.txt
# Run 应用程序
python main.py
```
### 最低硬件要求
| 组件 | 最低配置 | 推荐配置 |
|---|---|---|
| CPU | AMD Ryzen 3 (4核) | Intel Core i5 / AMD Ryzen 5 |
| RAM | 8 GB | 16 GB |
| 存储 | 512 GB | 建议 SSD |
| GPU | 非必需 | AMD/NVIDIA(用于加速) |
## 📈 使用方法
1. **创建任务** — 输入任务名称并点击 _Create New Task_。这将搭建文件夹结构。
2. **选择视频** — 选择一个 `.mp4`、`.avi` 或 `.mov` 格式的 CCTV 视频文件。
3. **添加参考图像** — 添加 1-4 张要搜索的人员的清晰照片。
4. **开始检测** — 点击 _Start Detection_。观看实时预览和进度条实时更新。
5. **查看结果** — 处理完成后,点击 _Results_ 浏览检测到的人脸截取图、报告和视频片段。
## 🗺️ 未来路线图
- [ ] 实时 RTSP/网络摄像头流支持,用于实时检测
- [ ] 通过 CUDA 进行 GPU 加速(dlib GPU 版本)
- [ ] 集成训练好的 CNN 以实现鲁棒的口罩分类
- [ ] 多人同时追踪
- [ ] 用于检测报告的交互式 HTML 仪表板
- [ ] 用于无头部署的 REST API 封装
## 📄 许可证
本项目基于 [MIT License](LICENSE) 授权。
## 🙏 致谢
- [ageitgey/face_recognition](https://github.com/ageitgey/face_recognition) — 基础人脸识别库
- [davisking/dlib](https://github.com/davisking/dlib) — 底层深度学习人脸嵌入模型
- [TomSchimansky/CustomTkinter](https://github.com/TomSchimansky/CustomTkinter) — 现代 Python UI 框架
- 开源计算机视觉和 AI 社区
标签:CCTV监控分析, CustomTkinter, dlib, FFmpeg, GUI开发, OpenCV, Python, ResNet, 人脸编码, 人脸识别, 公共安全, 刑侦技术, 图像处理, 失踪人口检测, 恶意代码分类, 恶意活动检测, 无后门, 智慧安防, 桌面应用, 深度学习, 目标检测, 离线人工智能, 端到端管道, 视频分析, 视频结构化, 计算机视觉, 逆向工具, 面具检测