質問編集履歴
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -72,6 +72,7 @@
|
|
72
72
|
少し調べたことろファイルが開かれてないのに編集しようとしているからこのエラーが起こる?みたいなことが書かれていたのですが本当の原因がこれなのかわかりません。
|
73
73
|
|
74
74
|
実行したことは画像が保存されるごとに画像の名前を変えて保存したいです。
|
75
|
+
そのためにdatetime.now()の箇所を変えないといけないのですがどう変えていいのかわからず質問させていただきました。
|
75
76
|
```
|
76
77
|
import requests
|
77
78
|
import json
|
1
編集
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
ValueError: I/O operation on closed file というエラーが出てしまう。
|
body
CHANGED
@@ -1,17 +1,71 @@
|
|
1
1
|
[リンク内容](https://qiita.com/daiarg/items/0fa6759e450c18c502b3#comments)
|
2
2
|
このサイトを参考にして自分のパソコン環境でも動くようにしたいと思い少しずつ改変していっいるのですが、
|
3
3
|
```
|
4
|
+
9\x11@\x1d\xd6f\x1bO\\x0c\x1c\xf5\x185\xcek\x9e6\xbe\xbe\x9f\xca\x02G\xc6\xe2\x1d$}\xee\xd9%\x8b\x00\xdc\x8e2O\xd7\x8a\xa0\x9a6\xbfw\x033\'\xca\xd9\x92GT?+`\x809\xfa\x8c\x91\xfe5\xa3\xa5\xf8v\xd2\x00\xbet{\xb6\x1d\xcd+7\uS\x8fa\xeb\xff\x00\xd
|
5
|
+
|
6
|
+
このような文字がいっぱい続いてました。
|
7
|
+
|
4
8
|
---------------------------------------------------------------------------
|
5
|
-
|
9
|
+
ValueError Traceback (most recent call last)
|
6
|
-
<ipython-input-
|
10
|
+
<ipython-input-1-4b147de06743> in <module>
|
11
|
+
53 }
|
7
|
-
|
12
|
+
54 response = requests.post(face_api_url, headers=headers,
|
8
|
-
41 cv2.imwrite(filename, img)#画像の書き出し
|
9
|
-
--->
|
13
|
+
---> 55 params=params, data=image_data)#FaceAPIで解析
|
14
|
+
56
|
10
|
-
|
15
|
+
57 response.raise_for_status()
|
11
|
-
44 print(content)
|
12
16
|
|
17
|
+
E:\Anaconda\envs\env\lib\site-packages\requests\api.py in post(url, data, json, **kwargs)
|
18
|
+
117 """
|
19
|
+
118
|
13
|
-
|
20
|
+
--> 119 return request('post', url, data=data, json=json, **kwargs)
|
21
|
+
120
|
22
|
+
121
|
14
23
|
|
24
|
+
E:\Anaconda\envs\env\lib\site-packages\requests\api.py in request(method, url, **kwargs)
|
25
|
+
59 # cases, and look like a memory leak in others.
|
26
|
+
60 with sessions.Session() as session:
|
27
|
+
---> 61 return session.request(method=method, url=url, **kwargs)
|
28
|
+
62
|
29
|
+
63
|
30
|
+
|
31
|
+
E:\Anaconda\envs\env\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
|
32
|
+
514 hooks=hooks,
|
33
|
+
515 )
|
34
|
+
--> 516 prep = self.prepare_request(req)
|
35
|
+
517
|
36
|
+
518 proxies = proxies or {}
|
37
|
+
|
38
|
+
E:\Anaconda\envs\env\lib\site-packages\requests\sessions.py in prepare_request(self, request)
|
39
|
+
457 auth=merge_setting(auth, self.auth),
|
40
|
+
458 cookies=merged_cookies,
|
41
|
+
--> 459 hooks=merge_hooks(request.hooks, self.hooks),
|
42
|
+
460 )
|
43
|
+
461 return p
|
44
|
+
|
45
|
+
E:\Anaconda\envs\env\lib\site-packages\requests\models.py in prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
|
46
|
+
315 self.prepare_headers(headers)
|
47
|
+
316 self.prepare_cookies(cookies)
|
48
|
+
--> 317 self.prepare_body(data, files, json)
|
49
|
+
318 self.prepare_auth(auth, url)
|
50
|
+
319
|
51
|
+
|
52
|
+
E:\Anaconda\envs\env\lib\site-packages\requests\models.py in prepare_body(self, data, files, json)
|
53
|
+
476 if is_stream:
|
54
|
+
477 try:
|
55
|
+
--> 478 length = super_len(data)
|
56
|
+
479 except (TypeError, AttributeError, UnsupportedOperation):
|
57
|
+
480 length = None
|
58
|
+
|
59
|
+
E:\Anaconda\envs\env\lib\site-packages\requests\utils.py in super_len(o)
|
60
|
+
118 elif hasattr(o, 'fileno'):
|
61
|
+
119 try:
|
62
|
+
--> 120 fileno = o.fileno()
|
63
|
+
121 except io.UnsupportedOperation:
|
64
|
+
122 pass
|
65
|
+
|
66
|
+
ValueError: I/O operation on closed file
|
67
|
+
|
68
|
+
|
15
69
|
```
|
16
70
|
というエラーが出てしまいます。
|
17
71
|
保存する画像名の指定の仕方が悪いのか保存されないです。
|
@@ -41,9 +95,9 @@
|
|
41
95
|
cascade = cv2.CascadeClassifier(cascade_path)
|
42
96
|
|
43
97
|
##Faceの設定
|
44
|
-
subscription_key = '
|
98
|
+
subscription_key = '####################'#ここに取得したキー1を入力
|
45
99
|
assert subscription_key
|
46
|
-
face_api_url = 'https://
|
100
|
+
face_api_url = 'https://#######.cognitiveservices.azure.com/face/v1.0/detect'#ここに取得したエンドポイントのURLを入力
|
47
101
|
|
48
102
|
##実行
|
49
103
|
while True:
|
@@ -57,7 +111,7 @@
|
|
57
111
|
cv2.imshow('image',img_gray)
|
58
112
|
if len(faces) > 0: #顔を検出した場合
|
59
113
|
for face in faces:
|
60
|
-
now =
|
114
|
+
now = 1#撮影時間
|
61
115
|
filename = "face{}.jpg".format(now)#保存するfilename
|
62
116
|
cv2.imwrite(filename, img)#画像の書き出し
|
63
117
|
with open(filename, mode="rb") as image_data:#処理をする画像を選択
|