-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpression_system_forlinux.py
More file actions
137 lines (109 loc) · 3.37 KB
/
expression_system_forlinux.py
File metadata and controls
137 lines (109 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python3.9
import cv2
import json
import time
import threading
import datetime as dt
import logging as log
from package.list import llistyaya
from package.update import updata_image
from package.pysound import playy
#opencv 基礎設定
cv2.useOptimized()
cascPath = (r"haarcascade_frontalface_default.xml")
faceCascade = cv2.CascadeClassifier(cascPath)
log.basicConfig(filename='webcam.log',level=log.INFO)
#video_capture = cv2.VideoCapture('rtsp:192.168.46.5/')
video_capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
anterior = 0
#opencv setting
text="no data"
jason=[]
world="is me again"
llist="setting"
#AZURE重置
Tstart=time.time()
#色影機拉
class ipcamCapture:
def __init__(self, URL):
self.Frame = []
self.status = False
self.isstop = False
#攝影機連接。
self.video_capture =cv2.VideoCapture(0, cv2.CAP_DSHOW)
#self.video_capture = cv2.VideoCapture(URL)
def start(self):
#把程式放進子執行緒
print('ipcam started!')
threading.Thread(target=self.queryframe, daemon=True, args=()).start()
def stop(self):
#停止無限迴圈的開關。
self.isstop = True
print('ipcam stopped!')
def getframe(self):
#再回傳最新的影像。
return self.Frame
def queryframe(self):
while (not self.isstop):
self.status, self.Frame = self.video_capture.read()
self.video_capture.release()
#設定攝影機
URL = "rtsp:192.168.46.5/"
ipcam = ipcamCapture(1)
#啟動搂!
ipcam.start()
lol = playy("sound/start.mp3")
lol.start()
#填充影像
time.sleep(1)
#建立執行續拉
upd=threading.Thread(target = updata_image)
llya=threading.Thread(target = llistyaya)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~主迴圈~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
while True:
#獲取攝影機畫面
frame = ipcam.getframe()
output = ipcam.getframe()
#ret, frame = video_capture.read()
#ret, output = video_capture.read()
#轉灰階
try:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
)
except:
print("轉換錯誤,切換模式")
faces = faceCascade.detectMultiScale(
frame,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
)
#如果畫面上出現了臉部
for (x, y, w, h) in faces:
#顯示綠色線條
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
#寫入照片
cv2.imwrite(r"image\0.jpg",output)
#顯示文字
cv2.putText(frame, world+" "+str(llist), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2, 4)
cv2.imwrite(r"image\face.jpg",frame)
#計算時間
Tend=time.time()
thetime=round(Tend-Tstart)
time.sleep(0.01)
if thetime % 6 == 0:
time.sleep(0.1)
jason=updata_image()
llist,world=llistyaya(jason)
if anterior != len(faces):
anterior = len(faces)
log.info("faces: "+str(len(faces))+" at "+str(dt.datetime.now()))
if cv2.waitKey(1) & 0xFF == ord('q'):
video_capture.release()
ipcam.stop()
break