質問編集履歴
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -113,3 +113,85 @@
|
|
113
113
|
cv2.imwrite('/content/drive/My Drive/eye/塗りつぶし.png',img)
|
114
114
|
|
115
115
|
```
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
見よう見まねで記述したコード
|
120
|
+
|
121
|
+
```
|
122
|
+
|
123
|
+
from google.colab import drive
|
124
|
+
|
125
|
+
drive.mount('/content/drive')
|
126
|
+
|
127
|
+
from __future__ import print_function
|
128
|
+
|
129
|
+
import cv2
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
image_count =100
|
134
|
+
|
135
|
+
# 顔検出インスタンス生成
|
136
|
+
|
137
|
+
cascadePath = '/content/drive/My Drive/opencv-master/data/haarcascades/haarcascade_eye_tree_eyeglasses.xml'
|
138
|
+
|
139
|
+
faceCascade = cv2.CascadeClassifier(cascadePath)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
# 画像ファイル読み込み
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
for i in range(image_count):
|
148
|
+
|
149
|
+
img = cv2.imread('/content/drive/My Drive/eye/A/'+'('+str(i+1)+')'+'.jpg',cv2.IMREAD_COLOR)
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
# 最小Windowサイズを定義
|
154
|
+
|
155
|
+
minW = 0.1*640
|
156
|
+
|
157
|
+
minH = 0.1*480
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
# グレースケールに変換
|
162
|
+
|
163
|
+
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
|
164
|
+
|
165
|
+
# 顔検出
|
166
|
+
|
167
|
+
faces = faceCascade.detectMultiScale(
|
168
|
+
|
169
|
+
gray,
|
170
|
+
|
171
|
+
scaleFactor = 1.2,
|
172
|
+
|
173
|
+
minNeighbors = 3,
|
174
|
+
|
175
|
+
minSize = (int(minW), int(minH)),
|
176
|
+
|
177
|
+
)
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
# 検出領域を塗りつぶすためのループ
|
182
|
+
|
183
|
+
for x, y, w, h in faces:
|
184
|
+
|
185
|
+
img [y: y + h, x: x + w] = [0, 0, 0] #色指定
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
# 画像保存
|
190
|
+
|
191
|
+
cv2.imwrite('/content/drive/My Drive/eye/'+'('+str(i+1)+')' + '.jpg',img)
|
192
|
+
|
193
|
+
# Do a bit of cleanup
|
194
|
+
|
195
|
+
print("\n Exit Program")
|
196
|
+
|
197
|
+
```
|