Skip to content

Commit edff2a9

Browse files
authored
Merge pull request #14 from rrr-001/shot/feature
增加人脸识别打码功能
2 parents ec0e656 + dbee58a commit edff2a9

23 files changed

+47250
-4707
lines changed

Makefile

Lines changed: 768 additions & 782 deletions
Large diffs are not rendered by default.

Makefile.Debug

Lines changed: 4458 additions & 1880 deletions
Large diffs are not rendered by default.

Makefile.Release

Lines changed: 4458 additions & 1880 deletions
Large diffs are not rendered by default.

OPENCV_INSTALL.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# OpenCV 安装指南
2+
3+
本指南将帮助您在 Windows 上安装和配置 OpenCV,以启用人脸识别功能。
4+
5+
## 方法一:使用预编译版本(推荐,最简单)
6+
7+
### 1. 下载 OpenCV
8+
9+
1. 访问 [OpenCV 官网](https://opencv.org/releases/)
10+
2. 下载最新版本的 Windows 预编译包(例如:`opencv-4.x.x-windows.exe`
11+
3. 运行安装程序,选择一个安装路径(例如:`D:\opencv`
12+
13+
### 2. 配置项目文件
14+
15+
编辑 `ScreenSniper.pro` 文件:
16+
17+
1. **找到第 73 行**,注释掉或删除 `DEFINES += NO_OPENCV`
18+
```pro
19+
# DEFINES += NO_OPENCV # 注释掉这一行
20+
```
21+
22+
2. **找到 Windows 配置部分(约第 57-70 行)**,取消注释并修改 OpenCV 路径:
23+
```pro
24+
win32 {
25+
# OpenCV 配置
26+
# 将下面的路径改为您实际的 OpenCV 安装路径
27+
OPENCV_DIR = D:/opencv/build
28+
29+
INCLUDEPATH += $$OPENCV_DIR/include
30+
INCLUDEPATH += $$OPENCV_DIR/include/opencv2
31+
DEPENDPATH += $$OPENCV_DIR/include
32+
33+
# 根据您的编译器选择:
34+
# MSVC 编译器
35+
LIBS += -L$$OPENCV_DIR/x64/vc16/lib
36+
CONFIG(debug, debug|release) {
37+
LIBS += -lopencv_world4xxd # 将 4xx 替换为实际版本号(如 480)
38+
DEFINES += OPENCV_DEBUG
39+
} else {
40+
LIBS += -lopencv_world4xx # 将 4xx 替换为实际版本号(如 480)
41+
}
42+
43+
# 或者 MinGW 编译器
44+
# LIBS += -L$$OPENCV_DIR/x64/mingw/lib
45+
# CONFIG(debug, debug|release) {
46+
# LIBS += -lopencv_world4xxd
47+
# } else {
48+
# LIBS += -lopencv_world4xx
49+
# }
50+
}
51+
```
52+
53+
3. **重要**:将 `OPENCV_DIR` 和版本号(`4xx`)替换为您实际的路径和版本号。
54+
55+
### 3. 配置环境变量(可选但推荐)
56+
57+
将 OpenCV 的 DLL 目录添加到系统 PATH:
58+
- 路径示例:`D:\opencv\build\x64\vc16\bin`(MSVC)或 `D:\opencv\build\x64\mingw\bin`(MinGW)
59+
60+
或者将 DLL 文件复制到可执行文件目录。
61+
62+
### 4. 重新编译项目
63+
64+
```bash
65+
# 清理之前的构建
66+
qmake
67+
make clean
68+
69+
# 重新生成 Makefile
70+
qmake
71+
72+
# 编译
73+
make
74+
```
75+
76+
## 方法二:使用 vcpkg(推荐用于 Qt Creator)
77+
78+
### 1. 安装 vcpkg
79+
80+
```bash
81+
# 克隆 vcpkg
82+
git clone https://github.com/Microsoft/vcpkg.git
83+
cd vcpkg
84+
85+
# Windows 上运行
86+
.\bootstrap-vcpkg.bat
87+
88+
# 集成到系统(可选)
89+
.\vcpkg integrate install
90+
```
91+
92+
### 2. 安装 OpenCV
93+
94+
```bash
95+
# 安装 OpenCV(Qt 支持)
96+
.\vcpkg install opencv[contrib,qt]:x64-windows
97+
98+
# 或者仅安装基础版本
99+
.\vcpkg install opencv:x64-windows
100+
```
101+
102+
### 3. 配置项目文件
103+
104+
`ScreenSniper.pro` 中添加:
105+
106+
```pro
107+
win32 {
108+
# 移除 NO_OPENCV 定义
109+
# DEFINES += NO_OPENCV
110+
111+
# vcpkg 配置(根据您的 vcpkg 安装路径修改)
112+
VCPKG_DIR = C:/vcpkg/installed/x64-windows
113+
114+
INCLUDEPATH += $$VCPKG_DIR/include
115+
LIBS += -L$$VCPKG_DIR/lib
116+
117+
CONFIG(debug, debug|release) {
118+
LIBS += -lopencv_worldd
119+
} else {
120+
LIBS += -lopencv_world
121+
}
122+
}
123+
```
124+
125+
## 方法三:从源码编译(高级用户)
126+
127+
### 1. 安装依赖
128+
129+
- **CMake**: 从 [CMake 官网](https://cmake.org/download/) 下载安装
130+
- **Visual Studio**: 安装 "Desktop development with C++" 工作负载
131+
- **Qt**: 确保已安装 Qt
132+
133+
### 2. 下载 OpenCV 源码
134+
135+
```bash
136+
git clone https://github.com/opencv/opencv.git
137+
cd opencv
138+
git checkout 4.x # 选择稳定版本
139+
```
140+
141+
### 3. 使用 CMake 配置
142+
143+
1. 打开 CMake GUI
144+
2. 设置源码路径:`<opencv_source_dir>`
145+
3. 设置构建路径:`<opencv_build_dir>`
146+
4. 点击 "Configure",选择 Visual Studio 生成器
147+
5. 配置选项:
148+
- `CMAKE_PREFIX_PATH` = 您的 Qt 安装路径
149+
- `WITH_QT` = ON(如果需要 Qt 支持)
150+
6. 点击 "Generate"
151+
152+
### 4. 编译
153+
154+
在 Visual Studio 中打开生成的解决方案,编译 Debug 和 Release 版本。
155+
156+
### 5. 安装
157+
158+
```bash
159+
cmake --install . --prefix D:/opencv/install
160+
```
161+
162+
## 验证安装
163+
164+
编译完成后,运行程序并点击"自动打码"按钮。如果配置正确,应该能够正常使用人脸识别功能。
165+
166+
## 常见问题
167+
168+
### Q: 编译时提示找不到 OpenCV 头文件
169+
170+
A: 检查 `INCLUDEPATH` 是否正确设置,路径中不要使用反斜杠,使用正斜杠 `/` 或双反斜杠 `\\`
171+
172+
### Q: 运行时提示找不到 DLL
173+
174+
A:
175+
1. 将 OpenCV 的 `bin` 目录添加到系统 PATH
176+
2. 或将 DLL 文件复制到可执行文件目录
177+
3. 确保使用正确版本的 DLL(Debug/Release)
178+
179+
### Q: MinGW 和 MSVC 库不兼容
180+
181+
A: 如果使用 MinGW 编译器,必须使用 MinGW 编译的 OpenCV 库。预编译版本通常只提供 MSVC 版本,需要自己编译 MinGW 版本。
182+
183+
### Q: 如何检查 OpenCV 版本
184+
185+
A: 查看 `opencv\build\include\opencv2\opencv_version.hpp` 文件,或查看库文件名中的版本号。
186+
187+
## 模型文件
188+
189+
确保 `models` 目录下有以下文件:
190+
- `opencv_face_detector_uint8.pb`
191+
- `opencv_face_detector.pbtxt.txt``opencv_face_detector.pbtxt`
192+
193+
这些文件可以从 [OpenCV 官方仓库](https://github.com/opencv/opencv_extra/tree/master/testdata/dnn) 下载。
194+
195+
## 参考链接
196+
197+
- [OpenCV 官方文档](https://docs.opencv.org/)
198+
- [OpenCV Windows 安装教程](https://docs.opencv.org/4.x/d3/d52/tutorial_windows_install.html)
199+
- [vcpkg 文档](https://vcpkg.io/)
200+

ScreenSniper.pro

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
QT += core gui widgets
2-
QT += core gui network
1+
QT += core gui widgets network
32

3+
# 明确移除 NO_OPENCV 定义(如果存在)
4+
DEFINES -= NO_OPENCV
45

56
win32 {
67
LIBS += -lPsapi -lDwmapi
@@ -26,7 +27,9 @@ macx {
2627
-lopencv_imgproc \
2728
-lopencv_highgui \
2829
-lopencv_imgcodecs \
29-
-lopencv_videoio
30+
-lopencv_videoio \
31+
-lopencv_dnn \
32+
-lopencv_objdetect
3033
}
3134
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
3235

@@ -56,21 +59,19 @@ unix:!macx {
5659
}
5760
win32 {
5861
# Windows 配置
59-
# OpenCV暂时禁用(MinGW与MSVC库不兼容)
60-
# INCLUDEPATH += "D:/C++/opencv/build/include"
61-
# DEPENDPATH += "D:/C++/opencv/build/include"
62-
# INCLUDEPATH += "D:/C++/opencv/build/include/opencv2"
63-
# DEPENDPATH += "D:/C++/opencv/build/include/opencv2"
64-
# LIBS += -L"D:/C++/opencv/build/x64/vc16/lib"
65-
# CONFIG(debug, debug|release) {
66-
# LIBS += -lopencv_world480d
67-
# DEFINES += OPENCV_DEBUG
68-
# } else {
69-
# LIBS += -lopencv_world480
70-
# }
71-
72-
# 禁用水印功能
73-
DEFINES += NO_OPENCV
62+
# OpenCV 配置
63+
# 明确移除 NO_OPENCV 定义(如果之前有定义)
64+
DEFINES -= NO_OPENCV
65+
66+
# OpenCV头文件路径
67+
INCLUDEPATH += D:/rr/opencv/opencv/opencv_bulid/install/include
68+
69+
# OpenCV库文件路径 + 链接库
70+
LIBS += -LD:/rr/opencv/opencv/opencv_bulid/lib
71+
LIBS += -lopencv_calib3d4120 -lopencv_core4120 -lopencv_dnn4120 -lopencv_features2d4120 \
72+
-lopencv_flann4120 -lopencv_highgui4120 -lopencv_imgcodecs4120 -lopencv_imgproc4120 \
73+
-lopencv_ml4120 -lopencv_objdetect4120 -lopencv_photo4120 -lopencv_stitching4120 \
74+
-lopencv_ts4120 -lopencv_video4120 -lopencv_videoio4120
7475

7576
# Tesseract configuration for Windows
7677
# 请根据实际安装路径修改
@@ -100,7 +101,8 @@ SOURCES += \
100101
ocrmanager.cpp \
101102
ocrresultdialog.cpp \
102103
watermark_robust.cpp \
103-
i18nmanager.cpp
104+
i18nmanager.cpp \
105+
facedetector.cpp
104106

105107
HEADERS += \
106108
aiconfigmanager.h \
@@ -111,7 +113,8 @@ HEADERS += \
111113
ocrmanager.h \
112114
ocrresultdialog.h \
113115
watermark_robust.h \
114-
i18nmanager.h
116+
i18nmanager.h \
117+
facedetector.h
115118

116119
FORMS += \
117120
mainwindow.ui

aiconfigmanager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,19 @@ void AIConfigManager::saveIniFile(const QString &filePath, const QMap<QString, Q
146146
const QMap<QString, QString> &sectionConfig = sectionIter.value();
147147

148148
// 写入节
149-
out << "[" << section << "]" << endl;
149+
out << "[" << section << "]" << Qt::endl;
150150

151151
// 写入节内的键值对
152152
for (auto keyIter = sectionConfig.constBegin(); keyIter != sectionConfig.constEnd(); ++keyIter)
153153
{
154154
const QString &key = keyIter.key();
155155
const QString &value = keyIter.value();
156156

157-
out << key << "=" << value << endl;
157+
out << key << "=" << value << Qt::endl;
158158
}
159159

160160
// 节之间空一行
161-
out << endl;
161+
out << Qt::endl;
162162
}
163163

164164
file.close();

0 commit comments

Comments
 (0)