Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 204c8e8

Browse files
author
winterssy
committed
新增:直方图均衡化
1 parent a1eb800 commit 204c8e8

File tree

6 files changed

+56
-63
lines changed

6 files changed

+56
-63
lines changed

core.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def __init__(self):
7171
lambda: self.faceProcessingThread.enableFaceRecognizer(self))
7272
self.panalarmCheckBox.stateChanged.connect(lambda: self.faceProcessingThread.enablePanalarm(self))
7373

74+
# 直方图均衡化
75+
self.equalizeHistCheckBox.stateChanged.connect(
76+
lambda: self.faceProcessingThread.enableEqualizeHist(self))
77+
7478
# 调试模式
7579
self.debugCheckBox.stateChanged.connect(lambda: self.faceProcessingThread.enableDebug(self))
7680
self.confidenceThresholdSlider.valueChanged.connect(
@@ -414,6 +418,8 @@ def __init__(self):
414418
self.confidenceThreshold = 50
415419
self.autoAlarmThreshold = 65
416420

421+
self.isEqualizeHistEnabled = False
422+
417423
# 是否开启人脸跟踪
418424
def enableFaceTracker(self, coreUI):
419425
if coreUI.faceTrackerCheckBox.isChecked():
@@ -467,6 +473,15 @@ def setAutoAlarmThreshold(self, coreUI):
467473
self.autoAlarmThreshold = coreUI.autoAlarmThresholdSlider.value()
468474
coreUI.statusBar().showMessage('自动报警阈值:{}'.format(self.autoAlarmThreshold))
469475

476+
# 是否执行直方图均衡化
477+
def enableEqualizeHist(self, coreUI):
478+
if coreUI.equalizeHistCheckBox.isChecked():
479+
self.isEqualizeHistEnabled = True
480+
coreUI.statusBar().showMessage('直方图均衡化:开启')
481+
else:
482+
self.isEqualizeHistEnabled = False
483+
coreUI.statusBar().showMessage('直方图均衡化:关闭')
484+
470485
def run(self):
471486
faceCascade = cv2.CascadeClassifier('./haarcascades/haarcascade_frontalface_default.xml')
472487

@@ -484,6 +499,8 @@ def run(self):
484499
if CoreUI.cap.isOpened():
485500
ret, frame = CoreUI.cap.read()
486501
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
502+
if self.isEqualizeHistEnabled:
503+
gray = cv2.equalizeHist(gray)
487504
faces = faceCascade.detectMultiScale(gray, 1.3, 5, minSize=(90, 90))
488505

489506
# 预加载数据文件

dataManage.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def __init__(self):
4949
self.queryUserButton.clicked.connect(self.queryUser)
5050
self.deleteUserButton.clicked.connect(self.deleteUser)
5151

52+
# 直方图均衡化
53+
self.isEqualizeHistEnabled = False
54+
self.equalizeHistCheckBox.stateChanged.connect(
55+
lambda: self.enableEqualizeHist(self.equalizeHistCheckBox))
56+
5257
# 训练人脸数据
5358
self.trainButton.clicked.connect(self.train)
5459

@@ -57,6 +62,13 @@ def __init__(self):
5762
self.logOutputThread = threading.Thread(target=self.receiveLog, daemon=True)
5863
self.logOutputThread.start()
5964

65+
# 是否执行直方图均衡化
66+
def enableEqualizeHist(self, equalizeHistCheckBox):
67+
if equalizeHistCheckBox.isChecked():
68+
self.isEqualizeHistEnabled = True
69+
else:
70+
self.isEqualizeHistEnabled = False
71+
6072
# 初始化/刷新数据库
6173
def initDb(self):
6274
# 刷新前重置tableWidget
@@ -182,6 +194,8 @@ def deleteUser(self):
182194
# 检测人脸
183195
def detectFace(self, img):
184196
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
197+
if self.isEqualizeHistEnabled:
198+
gray = cv2.equalizeHist(gray)
185199
face_cascade = cv2.CascadeClassifier('./haarcascades/haarcascade_frontalface_default.xml')
186200
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5, minSize=(90, 90))
187201

images/CoreUI.png

1.31 KB
Loading

images/DataManageUI.png

-675 Bytes
Loading

ui/Core.ui

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<property name="geometry">
3434
<rect>
3535
<x>10</x>
36-
<y>20</y>
36+
<y>60</y>
3737
<width>301</width>
3838
<height>161</height>
3939
</rect>
@@ -157,9 +157,9 @@
157157
<property name="geometry">
158158
<rect>
159159
<x>10</x>
160-
<y>190</y>
160+
<y>230</y>
161161
<width>301</width>
162-
<height>161</height>
162+
<height>121</height>
163163
</rect>
164164
</property>
165165
<property name="title">
@@ -169,9 +169,9 @@
169169
<property name="geometry">
170170
<rect>
171171
<x>10</x>
172-
<y>80</y>
172+
<y>60</y>
173173
<width>271</width>
174-
<height>71</height>
174+
<height>51</height>
175175
</rect>
176176
</property>
177177
<property name="text">
@@ -187,7 +187,7 @@
187187
<x>10</x>
188188
<y>20</y>
189189
<width>271</width>
190-
<height>51</height>
190+
<height>41</height>
191191
</rect>
192192
</property>
193193
<property name="text">
@@ -198,6 +198,19 @@
198198
</property>
199199
</widget>
200200
</widget>
201+
<widget class="QCheckBox" name="equalizeHistCheckBox">
202+
<property name="geometry">
203+
<rect>
204+
<x>20</x>
205+
<y>25</y>
206+
<width>101</width>
207+
<height>21</height>
208+
</rect>
209+
</property>
210+
<property name="text">
211+
<string>直方图均衡化</string>
212+
</property>
213+
</widget>
201214
</widget>
202215
<widget class="QGroupBox" name="systemSettingsGroupBox">
203216
<property name="geometry">

ui/DataManage.ui

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -107,68 +107,17 @@
107107
<property name="title">
108108
<string>图像预处理</string>
109109
</property>
110-
<widget class="QPushButton" name="pushButton">
111-
<property name="enabled">
112-
<bool>false</bool>
113-
</property>
114-
<property name="geometry">
115-
<rect>
116-
<x>20</x>
117-
<y>30</y>
118-
<width>111</width>
119-
<height>31</height>
120-
</rect>
121-
</property>
122-
<property name="text">
123-
<string>这是一个</string>
124-
</property>
125-
</widget>
126-
<widget class="QPushButton" name="pushButton_2">
127-
<property name="enabled">
128-
<bool>false</bool>
129-
</property>
130-
<property name="geometry">
131-
<rect>
132-
<x>20</x>
133-
<y>70</y>
134-
<width>111</width>
135-
<height>31</height>
136-
</rect>
137-
</property>
138-
<property name="text">
139-
<string>待评估</string>
140-
</property>
141-
</widget>
142-
<widget class="QPushButton" name="pushButton_3">
143-
<property name="enabled">
144-
<bool>false</bool>
145-
</property>
110+
<widget class="QCheckBox" name="equalizeHistCheckBox">
146111
<property name="geometry">
147112
<rect>
148-
<x>150</x>
149-
<y>30</y>
150-
<width>111</width>
151-
<height>31</height>
152-
</rect>
153-
</property>
154-
<property name="text">
155-
<string>新功能</string>
156-
</property>
157-
</widget>
158-
<widget class="QPushButton" name="pushButton_4">
159-
<property name="enabled">
160-
<bool>false</bool>
161-
</property>
162-
<property name="geometry">
163-
<rect>
164-
<x>150</x>
165-
<y>70</y>
166-
<width>111</width>
167-
<height>31</height>
113+
<x>10</x>
114+
<y>40</y>
115+
<width>91</width>
116+
<height>41</height>
168117
</rect>
169118
</property>
170119
<property name="text">
171-
<string>可能不会实现</string>
120+
<string>直方图均衡化</string>
172121
</property>
173122
</widget>
174123
</widget>

0 commit comments

Comments
 (0)