質問編集履歴
1
コード削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,86 +44,6 @@
|
|
44
44
|
|
45
45
|
```python
|
46
46
|
|
47
|
-
import cv2
|
48
|
-
|
49
|
-
import threading
|
50
|
-
|
51
|
-
#マルチプロセスの場合は↓を使用
|
52
|
-
|
53
|
-
#import multiprocessing
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#HOG特長全身検出器の設定
|
58
|
-
|
59
|
-
global hog
|
60
|
-
|
61
|
-
hog = cv2.HOGDescriptor()
|
62
|
-
|
63
|
-
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
#矩形描画
|
68
|
-
|
69
|
-
def draw_rectangle(img, rects):
|
70
|
-
|
71
|
-
for x, y, w, h in rects:
|
72
|
-
|
73
|
-
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), thickness = 2)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
#カメラキャプチャ開始
|
78
|
-
|
79
|
-
cap = cv2.VideoCapture(0)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
if __name__ = '__main__':
|
84
|
-
|
85
|
-
while(cap.isOpened()):
|
86
|
-
|
87
|
-
ret, frame = cap.read()
|
88
|
-
|
89
|
-
#検出処理
|
90
|
-
|
91
|
-
found, features = hog.detectMultiScale(frame, winStride = (8, 8), padding = (32, 32), scale = 1.05)
|
92
|
-
|
93
|
-
#矩形描画スレッド起動
|
94
|
-
|
95
|
-
t = threading.Thread(target = draw_rectangle, args = (frame, found))
|
96
|
-
|
97
|
-
#マルチプロセスの場合は↓を使用
|
98
|
-
|
99
|
-
#t = multiprocessing.Process(target = draw_rectangle, args = (frame, found))
|
100
|
-
|
101
|
-
t.start()
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
#画像表示
|
106
|
-
|
107
|
-
cv2.imshow('fullbody', frame)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
#何かキーが押されたら終了
|
112
|
-
|
113
|
-
key_input = cv2.waitKey(10)
|
114
|
-
|
115
|
-
if key_input > 0:
|
116
|
-
|
117
|
-
break
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
#終了処理
|
122
|
-
|
123
|
-
cap.release()
|
124
|
-
|
125
|
-
cv2.destroyAllWindows()
|
126
|
-
|
127
47
|
|
128
48
|
|
129
49
|
```
|