回答編集履歴
5
不必要な文の削除
test
CHANGED
@@ -7,30 +7,6 @@
|
|
7
7
|
```
|
8
8
|
|
9
9
|
でtimeモジュールをimportして,
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
```python
|
14
|
-
|
15
|
-
while True:
|
16
|
-
|
17
|
-
tick = cv2.getTickCount()
|
18
|
-
|
19
|
-
close_eye = 0.0
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
ret, rgb = cap.read()
|
24
|
-
|
25
|
-
gray = cv2.cvtColor(rgb, cv2.COLOR_RGB2GRAY)
|
26
|
-
|
27
|
-
faces = face_cascade.detectMultiScale(
|
28
|
-
|
29
|
-
gray, scaleFactor=1.11, minNeighbors=3, minSize=(100, 100))
|
30
|
-
|
31
|
-
```
|
32
|
-
|
33
|
-
~~この部分に,close_eye=0.0を加えます.~~
|
34
10
|
|
35
11
|
|
36
12
|
|
4
codeの再修正
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
close_eye = 0.0
|
20
20
|
|
21
|
-
|
21
|
+
|
22
22
|
|
23
23
|
ret, rgb = cap.read()
|
24
24
|
|
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
cap = cv2.VideoCapture(0)
|
44
44
|
|
45
|
-
|
45
|
+
t1 = 0.0
|
46
46
|
|
47
47
|
close_eye = 0.0
|
48
48
|
|
3
codeの修正
test
CHANGED
@@ -17,6 +17,8 @@
|
|
17
17
|
tick = cv2.getTickCount()
|
18
18
|
|
19
19
|
close_eye = 0.0
|
20
|
+
|
21
|
+
t1 = 0.0
|
20
22
|
|
21
23
|
ret, rgb = cap.read()
|
22
24
|
|
@@ -64,15 +66,13 @@
|
|
64
66
|
|
65
67
|
if (left_eye_ear + right_eye_ear) < 0.45:
|
66
68
|
|
67
|
-
if
|
69
|
+
if t1 == 0.0:
|
68
70
|
|
69
71
|
t1 = time.time()
|
70
72
|
|
71
73
|
else:
|
72
74
|
|
73
|
-
t2 = time.time()
|
74
|
-
|
75
|
-
close_eye += t
|
75
|
+
close_eye += time.time()-t1
|
76
76
|
|
77
77
|
t1 = time.time()
|
78
78
|
|
@@ -104,4 +104,6 @@
|
|
104
104
|
|
105
105
|
close_eye = 0.0
|
106
106
|
|
107
|
+
t1 = 0.0
|
108
|
+
|
107
109
|
```
|
2
close_eyeの位置の修正
test
CHANGED
@@ -28,7 +28,29 @@
|
|
28
28
|
|
29
29
|
```
|
30
30
|
|
31
|
-
この部分に,
|
31
|
+
~~この部分に,close_eye=0.0を加えます.~~
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
while分の中に入れてしまうと毎回初期化されてしまうため,
|
36
|
+
|
37
|
+
こちらの位置に修正してください.
|
38
|
+
|
39
|
+
```Python
|
40
|
+
|
41
|
+
cap = cv2.VideoCapture(0)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
close_eye = 0.0
|
46
|
+
|
47
|
+
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml')
|
48
|
+
|
49
|
+
face_parts_detector = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
32
54
|
|
33
55
|
|
34
56
|
|
1
timeをclose_eyeに変更しました.
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
tick = cv2.getTickCount()
|
18
18
|
|
19
|
-
|
19
|
+
close_eye = 0.0
|
20
20
|
|
21
21
|
ret, rgb = cap.read()
|
22
22
|
|
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
if (left_eye_ear + right_eye_ear) < 0.45:
|
44
44
|
|
45
|
-
if
|
45
|
+
if close_eye == 0.0:
|
46
46
|
|
47
47
|
t1 = time.time()
|
48
48
|
|
@@ -50,11 +50,11 @@
|
|
50
50
|
|
51
51
|
t2 = time.time()
|
52
52
|
|
53
|
-
|
53
|
+
close_eye += t2-t1
|
54
54
|
|
55
55
|
t1 = time.time()
|
56
56
|
|
57
|
-
if
|
57
|
+
if close_eye > 4.0:
|
58
58
|
|
59
59
|
cv2.putText(rgb,"close",
|
60
60
|
|
@@ -80,6 +80,6 @@
|
|
80
80
|
|
81
81
|
else:
|
82
82
|
|
83
|
-
|
83
|
+
close_eye = 0.0
|
84
84
|
|
85
85
|
```
|