Skip to content

ayaananone/cafeteria

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

智慧食堂人流统计系统 (Cafeteria Flow Statistics)

基于 Spring Boot + FFmpeg + 百度AI 的视频人脸检测与统计系统,自动分析食堂监控视频,实时统计人流量。

功能特性

  • 🎥 自动视频处理:监控文件夹,自动检测新视频并处理
  • 🧠 AI 人脸检测:集成百度AI人脸识别API,精准统计人数
  • ⏱️ 定时截图:每5秒提取一帧,计算时间戳
  • 📊 数据持久化:PostgreSQL 存储统计结果,支持历史查询
  • 🚀 异步处理:线程池处理多个视频,避免阻塞
  • 🌐 REST API:提供查询接口,支持按食堂、时间段筛选

技术栈

技术 用途
Spring Boot 3.x 后端框架
MyBatis 数据持久层
PostgreSQL 数据库
FFmpeg 视频帧提取
百度AI Face API 人脸检测识别
Gradle 构建工具

快速开始

1. 环境准备

  • JDK 17+
  • PostgreSQL 12+
  • FFmpeg(添加到系统PATH)
# 验证 FFmpeg
ffmpeg -version
2. 数据库配置
sql
复制
CREATE DATABASE cafeteria;

CREATE TABLE flow_records (
    id BIGSERIAL PRIMARY KEY,
    canteen_name VARCHAR(255) NOT NULL,
    record_time TIMESTAMP NOT NULL,
    person_count INTEGER DEFAULT 0,
    image_path TEXT,
    confidence_avg DECIMAL(5,4),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
3. 配置文件
修改 application.yml:
yaml
复制
# 百度AI配置(https://ai.baidu.com)
baidu:
  ai:
    app-id: 你的AppID
    api-key: 你的ApiKey
    secret-key: 你的SecretKey

# 视频处理配置
video:
  processor:
    watch-folder: D:/videos/input      # 监控文件夹
    output-folder: D:/videos/frames    # 帧输出文件夹
    ffmpeg-path: ffmpeg                # FFmpeg路径
    frame-interval: 5                  # 截图间隔(秒)

# 数据库配置
spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/cafeteria
    username: postgres
    password: 你的密码
4. 运行项目
bash
复制
./gradlew bootRun
或运行 CafeteriaApplication.main()
5. 放入视频测试
将视频文件放入 watch-folder:
plain
复制
D:/videos/input/食堂A_20240214.mp4
系统自动处理,控制台输出:
plain
复制
🎬 开始处理: 食堂A_20240214.mp4, 食堂: 食堂A
📸 帧提取完成
食堂 食堂A - 0秒: 检测到 5 人, 平均置信度: 0.9160
...
✅ 视频处理完成
API 接口
表格
复制
接口	方法	说明
/api/pic/records/{canteenName}	GET	查询食堂所有记录
/api/pic/records/range	GET	按时间段查询
/api/pic/records/latest/{canteenName}	GET	获取最新记录
/api/pic/process	POST	手动触发视频处理
示例
bash
复制
# 查询食堂A的记录
GET http://localhost:8080/api/pic/records/食堂A

# 按时间段查询
GET http://localhost:8080/api/pic/records/range?canteenName=食堂A&startTime=2024-02-14 10:00:00&endTime=2024-02-14 12:00:00

# 手动处理视频
POST http://localhost:8080/api/pic/process?videoPath=D:/videos/input/test.mp4&canteenName=食堂B
项目结构
plain
复制
src/main/java/com/ceshi/cafeteria/
├── config/          # 配置类(百度AI、FFmpeg、异步线程池)
├── controller/      # REST API 接口
├── dao/             # MyBatis Mapper
├── model/           # 实体类(PicModel)
├── service/         # 业务逻辑
│   └── impl/
├── task/            # 定时任务(文件夹监控)
└── CafeteriaApplication.java

src/main/resources/
├── mapper/          # MyBatis XML
├── static/          # 静态资源
└── application.yml  # 配置文件
注意事项
百度AI QPS限制:免费版每秒2次请求,代码已添加1000ms间隔
FFmpeg路径:Windows建议配置完整路径 D:/ffmpeg/bin/ffmpeg.exe
视频格式:支持 mp4/avi/mkv/mov/flv/wmv
文件名规则:食堂名_xxx.mp4 可自动识别食堂名

方案概略流程图:![img_3.png](img_3.png)
百度API:![img_2.png](img_2.png)
处理后数据:![img_1.png](img_1.png)(来源为https://www.pexels.com/video/bustling-city-street-scene-with-pedestrians-28990412/)
运行成功:![img.png](img.png)

许可证
MIT License
联系方式
作者:ayaananone
邮箱:luanmazongxingba@163.com
GitHub:https://github.com/ayaananone/cafeteria

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors