質問編集履歴
2
文法修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -82,6 +82,10 @@
|
|
82
82
|
|
83
83
|
以下追記いたしました。どのようなコードにthreading処理を組み込みたいかについてです。
|
84
84
|
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
85
89
|
以下のようにcv2を用いてPCにおいて画面表示をしながら、任意のフレーム数をリストに格納し、格納したデータについてthreading処理を並列で処理したいと考えています。その際に画面のカメラ画像を止めずにバックグラウンドで処理したいのですが、今のところ試してはいるのですが、画面表示がやや止まる印象がありますので質問させていただきました。
|
86
90
|
|
87
91
|
|
1
どのようなコードに組み込みたいか追記いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -75,3 +75,145 @@
|
|
75
75
|
コード
|
76
76
|
|
77
77
|
```
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
以下追記いたしました。どのようなコードにthreading処理を組み込みたいかについてです。
|
84
|
+
|
85
|
+
以下のようにcv2を用いてPCにおいて画面表示をしながら、任意のフレーム数をリストに格納し、格納したデータについてthreading処理を並列で処理したいと考えています。その際に画面のカメラ画像を止めずにバックグラウンドで処理したいのですが、今のところ試してはいるのですが、画面表示がやや止まる印象がありますので質問させていただきました。
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```python
|
94
|
+
|
95
|
+
import numpy as np
|
96
|
+
|
97
|
+
import cv2
|
98
|
+
|
99
|
+
import matplotlib.pyplot as plt
|
100
|
+
|
101
|
+
import time
|
102
|
+
|
103
|
+
#カメラを設定
|
104
|
+
|
105
|
+
cap = cv2.VideoCapture(0)
|
106
|
+
|
107
|
+
frame_width = int(cap.get(3))
|
108
|
+
|
109
|
+
frame_height = int(cap.get(4))
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
#mp4で保存するため、以下を設定
|
114
|
+
|
115
|
+
out = cv2.VideoWriter('test_.mp4',cv2.VideoWriter_fourcc('M','P','4','V'), 30, (frame_width,frame_height))
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
count=0
|
122
|
+
|
123
|
+
frames_list=[]
|
124
|
+
|
125
|
+
#---------------------------------
|
126
|
+
|
127
|
+
while(True):
|
128
|
+
|
129
|
+
ret, frame = cap.read()
|
130
|
+
|
131
|
+
if ret == True:
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
# Write the frame into the file 'output.avi'
|
136
|
+
|
137
|
+
#out.write(frame)
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
# Display the resulting frame
|
142
|
+
|
143
|
+
cv2.imshow('frame',frame)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
#-----------------------------------------------------------------
|
148
|
+
|
149
|
+
#50フレーム格納すると処理を行うプログラムを実行する。
|
150
|
+
|
151
|
+
frames_list.append(frame)
|
152
|
+
|
153
|
+
count = count + 1
|
154
|
+
|
155
|
+
if count == 50:
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
print("150フレーム分取得,predict開始")
|
160
|
+
|
161
|
+
time_sta=time.time() #時間を計測する
|
162
|
+
|
163
|
+
frames_extracted=np.array(frames_list)
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
#------------------------------------------
|
168
|
+
|
169
|
+
#ここで取得したframe_listに対して並列処理を行いたいです。
|
170
|
+
|
171
|
+
#------------------------------------------
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
#処理が終了したため、frames_listを空にする
|
178
|
+
|
179
|
+
frames_list=[]
|
180
|
+
|
181
|
+
print("listを空にしました",len(frames_list))
|
182
|
+
|
183
|
+
#countを0に戻す
|
184
|
+
|
185
|
+
count=0
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
# Press Q on keyboard to stop recording
|
190
|
+
|
191
|
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
192
|
+
|
193
|
+
break
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
# Break the loop
|
198
|
+
|
199
|
+
else:
|
200
|
+
|
201
|
+
break
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
# When everything done, release the video capture and video write objects
|
206
|
+
|
207
|
+
cap.release()
|
208
|
+
|
209
|
+
out.release()
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
# Closes all the frames
|
214
|
+
|
215
|
+
cv2.destroyAllWindows()
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
```
|