Skip to content

Commit 63c6376

Browse files
committed
demo
1 parent d356665 commit 63c6376

File tree

160 files changed

+266
-1037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+266
-1037
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ tmp
128128
.project
129129
.pydevproject
130130
.README.md.html
131-
README.md.html
131+
README.md.html
132+
shape_predictor_68_face_landmarks.dat

.settings/org.eclipse.core.resources.prefs

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
eclipse.preferences.version=1
2+
encoding//Demo/EmbedWindow.py=utf-8
3+
encoding//Demo/FacePoints.py=utf-8
4+
encoding//Demo/FollowWindow.py=utf-8
5+
encoding//Demo/FramelessWindow.py=utf-8
6+
encoding//Demo/Lib/Application.py=utf-8
7+
encoding//Demo/NativeEvent.py=utf-8
8+
encoding//Demo/Notification.py=utf-8
9+
encoding//Demo/ProbeWindow.py=utf-8
10+
encoding//Demo/RestartWindow.py=utf-8
11+
encoding//Demo/SharedMemory.py=utf-8
12+
encoding//Demo/SingleApplication.py=utf-8
13+
encoding//Demo/VerificationCode.py=utf-8
14+
encoding//Demo/WeltHideWindow.py=utf-8
15+
encoding//Demo/WindowNotify.py=utf-8
16+
encoding//QFont/AwesomeFont.py=utf-8
17+
encoding//QFont/Lib/FontAwesome.py=utf-8
218
encoding//QListView/CustomWidgetSortItem.py=utf-8
319
encoding//QListView/SortItemByRole.py=utf-8
420
encoding//QMessageBox/CustomColorIcon.py=utf-8
@@ -22,3 +38,5 @@ encoding//QWebView/DreamTree.py=utf-8
2238
encoding//QWidget/Lib/CustomPaintWidget.py=utf-8
2339
encoding//QWidget/Lib/CustomWidget.py=utf-8
2440
encoding//QWidget/WidgetStyle.py=utf-8
41+
encoding//Test/\u5168\u5C40\u70ED\u952E/HotKey.py=utf-8
42+
encoding//Test/\u81EA\u52A8\u66F4\u65B0/test.py=utf-8
File renamed without changes.
File renamed without changes.
File renamed without changes.

Demo/Data/AutoRestart.exe

5.47 MB
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Demo/嵌入外部窗口.py Demo/EmbedWindow.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Created on 2018年3月1日
6+
@author: Irony
7+
@site: https://pyqt5.com , https://github.com/892768447
8+
@email: 892768447@qq.com
9+
@file: EmbedWindow
10+
@description: 嵌入外部窗口
11+
"""
12+
13+
__Author__ = 'By: Irony\nQQ: 892768447\nEmail: 892768447@qq.com'
14+
__Copyright__ = 'Copyright (c) 2018 Irony'
15+
__Version__ = 1.0
16+
117
from PyQt5.QtGui import QWindow
218
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QListWidget,\
319
QLabel

Demo/人脸描点检测/OpencvWidget.py Demo/FacePoints.py

+66-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
@author: Irony."[讽刺]
77
@site: https://pyqt5.com , https://github.com/892768447
88
@email: 892768447@qq.com
9-
@file: OpencvWidget
10-
@description:
9+
@file: FacePoints
10+
@description: 人脸特征点
1111
'''
12+
from bz2 import BZ2Decompressor
13+
import cgitb
14+
import os
1215
import sys
1316

14-
from PyQt5.QtCore import QTimer
17+
from PyQt5.QtCore import QTimer, QUrl, QFile, QIODevice
1518
from PyQt5.QtGui import QImage, QPixmap
19+
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
1620
from PyQt5.QtWidgets import QLabel, QMessageBox, QApplication
1721
import cv2 # @UnresolvedImport
1822
import dlib
@@ -24,23 +28,66 @@
2428
__Version__ = "Version 1.0"
2529

2630
DOWNSCALE = 4
31+
URL = 'http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2'
2732

2833

2934
class OpencvWidget(QLabel):
3035

3136
def __init__(self, *args, **kwargs):
3237
super(OpencvWidget, self).__init__(*args, **kwargs)
38+
self.httpRequestAborted = False
3339
self.fps = 24
3440
self.resize(800, 600)
35-
self.setText("请稍候,正在初始化数据和摄像头。。。")
3641

37-
def start(self):
42+
if not os.path.exists("Data/shape_predictor_68_face_landmarks.dat"):
43+
self.setText("正在下载数据文件。。。")
44+
self.outFile = QFile(
45+
"Data/shape_predictor_68_face_landmarks.dat.bz2")
46+
if not self.outFile.open(QIODevice.WriteOnly):
47+
QMessageBox.critical(self, '错误', '无法写入文件')
48+
return
49+
self.qnam = QNetworkAccessManager(self)
50+
self._reply = self.qnam.get(QNetworkRequest(QUrl(URL)))
51+
self._reply.finished.connect(self.httpFinished)
52+
self._reply.readyRead.connect(self.httpReadyRead)
53+
self._reply.downloadProgress.connect(self.updateDataReadProgress)
54+
else:
55+
self.startCapture()
56+
57+
def httpFinished(self):
58+
self.outFile.close()
59+
if self.httpRequestAborted or self._reply.error():
60+
self.outFile.remove()
61+
self._reply.deleteLater()
62+
del self._reply
63+
# 下载完成解压文件并加载摄像头
64+
self.setText("正在解压数据。。。")
65+
try:
66+
bz = BZ2Decompressor()
67+
data = bz.decompress(
68+
open('Data/shape_predictor_68_face_landmarks.dat.bz2', 'rb').read())
69+
open('Data/shape_predictor_68_face_landmarks.dat', 'wb').write(data)
70+
except Exception as e:
71+
self.setText('解压失败:' + str(e))
72+
return
73+
self.setText('正在开启摄像头。。。')
74+
self.startCapture()
75+
76+
def httpReadyRead(self):
77+
self.outFile.write(self._reply.readAll())
78+
self.outFile.flush()
79+
80+
def updateDataReadProgress(self, bytesRead, totalBytes):
81+
self.setText('已下载:{} %'.format(round(bytesRead / 64040097 * 100, 2)))
82+
83+
def startCapture(self):
84+
self.setText("请稍候,正在初始化数据和摄像头。。。")
3885
try:
3986
# 检测相关
4087
self.detector = dlib.get_frontal_face_detector()
4188
self.predictor = dlib.shape_predictor(
42-
"data/shape_predictor_68_face_landmarks.dat")
43-
cascade_fn = "data/lbpcascades/lbpcascade_frontalface.xml"
89+
"Data/shape_predictor_68_face_landmarks.dat")
90+
cascade_fn = "Data/lbpcascades/lbpcascade_frontalface.xml"
4491
self.cascade = cv2.CascadeClassifier(cascade_fn)
4592
if not self.cascade:
4693
return QMessageBox.critical(self, "错误", cascade_fn + " 无法找到")
@@ -54,6 +101,17 @@ def start(self):
54101
QMessageBox.critical(self, "错误", str(e))
55102

56103
def closeEvent(self, event):
104+
if hasattr(self, "_reply") and self._reply:
105+
self.httpRequestAborted = True
106+
self._reply.abort()
107+
try:
108+
os.unlink("Data/shape_predictor_68_face_landmarks.dat.bz2")
109+
except:
110+
pass
111+
try:
112+
os.unlink("Data/shape_predictor_68_face_landmarks.dat")
113+
except:
114+
pass
57115
if hasattr(self, "timer"):
58116
self.timer.stop()
59117
self.timer.deleteLater()
@@ -105,9 +163,8 @@ def onCapture(self):
105163

106164

107165
if __name__ == "__main__":
166+
sys.excepthook = cgitb.enable(1, None, 5, '')
108167
app = QApplication(sys.argv)
109168
w = OpencvWidget()
110169
w.show()
111-
# 5秒后启动
112-
QTimer.singleShot(5000, w.start)
113170
sys.exit(app.exec_())

Demo/外部窗口跟随.py Demo/FollowWindow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@site: https://github.com/892768447
88
@email: 892768447@qq.com
99
@file: FollowWindow
10-
@description:
10+
@description: 跟随外部窗口
1111
"""
1212
import os
1313

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from PyQt5.QtGui import QIcon
44
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextEdit
55

6-
from FramelessWindow import FramelessWindow # @UnresolvedImport
6+
from Lib.FramelessWindow import FramelessWindow # @UnresolvedImport
77

88

99
# Created on 2018年4月30日
@@ -68,7 +68,7 @@ def __init__(self, *args, **kwargs):
6868
app.setStyleSheet(StyleSheet)
6969
w = FramelessWindow()
7070
w.setWindowTitle('测试标题栏')
71-
w.setWindowIcon(QIcon('Qt.ico'))
71+
w.setWindowIcon(QIcon('Data/Qt.ico'))
7272
w.setWidget(MainWindow(w)) # 把自己的窗口添加进来
7373
w.show()
7474
sys.exit(app.exec_())
File renamed without changes.
File renamed without changes.
File renamed without changes.

Demo/无边框自定义标题栏窗口/win无边框调整大小.py Demo/NativeEvent.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
"""Created on 2018年8月2日
4+
author: Irony
5+
site: https://pyqt5.com , https://github.com/892768447
6+
email: 892768447@qq.com
7+
file: win无边框调整大小
8+
description:
9+
"""
10+
311
from ctypes.wintypes import POINT
412
import ctypes.wintypes
513

614
from PyQt5.QtCore import Qt
7-
from PyQt5.QtWidgets import QWidget
15+
from PyQt5.QtWidgets import QWidget, QPushButton
816
from PyQt5.QtWinExtras import QtWin
917
import win32api
1018
import win32con
1119
import win32gui
1220

1321

14-
# Created on 2018年8月2日
15-
# author: Irony
16-
# site: https://pyqt5.com , https://github.com/892768447
17-
# email: 892768447@qq.com
18-
# file: win无边框调整大小
19-
# description:
2022
__Author__ = """By: Irony
2123
QQ: 892768447
2224
Email: 892768447@qq.com"""
@@ -64,6 +66,12 @@ def nativeEvent(self, eventType, message):
6466
retval, result = super(Window, self).nativeEvent(eventType, message)
6567
if eventType == "windows_generic_MSG":
6668
msg = ctypes.wintypes.MSG.from_address(message.__int__())
69+
# 获取鼠标移动经过时的坐标
70+
x = win32api.LOWORD(msg.lParam) - self.frameGeometry().x()
71+
y = win32api.HIWORD(msg.lParam) - self.frameGeometry().y()
72+
# 判断鼠标位置是否有其它控件
73+
if self.childAt(x, y) != None:
74+
return retval, result
6775
if msg.message == win32con.WM_NCCALCSIZE:
6876
# 拦截不显示顶部的系统自带的边框
6977
return True, 0
@@ -77,9 +85,6 @@ def nativeEvent(self, eventType, message):
7785
# 修改放置点的x,y坐标为0,0
7886
info.ptMaxPosition.x, info.ptMaxPosition.y = 0, 0
7987
if msg.message == win32con.WM_NCHITTEST:
80-
# 获取鼠标移动经过时的坐标
81-
x = win32api.LOWORD(msg.lParam) - self.frameGeometry().x()
82-
y = win32api.HIWORD(msg.lParam) - self.frameGeometry().y()
8388
w, h = self.width(), self.height()
8489
lx = x < self.BorderWidth
8590
rx = x > w - self.BorderWidth
@@ -119,5 +124,7 @@ def nativeEvent(self, eventType, message):
119124
from PyQt5.QtWidgets import QApplication
120125
app = QApplication(sys.argv)
121126
w = Window()
127+
btn = QPushButton('exit', w, clicked=app.quit)
128+
btn.setGeometry(10, 10, 100, 40)
122129
w.show()
123130
sys.exit(app.exec_())
File renamed without changes.

Demo/简单探测窗口和放大截图.py Demo/ProbeWindow.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3+
"""
4+
Created on 2018年6月8日
5+
author: Irony
6+
site: https://pyqt5.com , https://github.com/892768447
7+
email: 892768447@qq.com
8+
file: ProbeWindow
9+
description: 简单探测窗口和放大截图
10+
"""
11+
312
from PyQt5.QtCore import Qt, QRect
413
from PyQt5.QtGui import QPainter, QPen, QCursor, QColor
514
from PyQt5.QtWidgets import QLabel, QWidget, QApplication
615
import win32gui
716

817

9-
# Created on 2018年6月8日
10-
# author: Irony
11-
# site: https://pyqt5.com , https://github.com/892768447
12-
# email: 892768447@qq.com
13-
# file: 简单探测窗口和放大截图
14-
# description:
1518
__Author__ = """By: Irony
1619
QQ: 892768447
1720
Email: 892768447@qq.com"""

Demo/QRC资源文件使用/README.md

-34
This file was deleted.
-6.48 KB
Binary file not shown.

Demo/QRC资源文件使用/qrctest1.py

-44
This file was deleted.

0 commit comments

Comments
 (0)