このリンク先ページに記載されいているコードを実行してプログラムを動かしたいのですが、エラーが出てしまいます。
#%% import cv2 import requests #ローカル画像を分析してFaceAPIで解析する #https://docs.microsoft.com/ja-jp/azure/cognitive-services/computer-vision/quickstarts/python-disk #バイナリファイルを送ればよいみたい headers = { # Request headers 'Content-Type': 'application/octet-stream', 'Ocp-Apim-Subscription-Key': '##################', #write your key } write_file_name = r'E:\opencvcascade\pos\model_2.png' api_url = '############################/face/v1.0/detect' # VideoCaptureのインスタンスを作成する。 # 引数でカメラを選べれる。 cap = cv2.VideoCapture(0) params = { # Request parameters 'returnFaceId': 'false', 'returnFaceLandmarks': 'false', 'returnFaceAttributes': 'emotion', } try: while True: ret, frame = cap.read() cv2.imwrite(write_file_name, frame) with open(write_file_name, 'rb') as f: img = f.read() response = requests.post(api_url,params=params,headers=headers,data=img) cv2.imshow('Raw Frame', frame) data = response.json() for id in range(len(data)): rect = data[id]['faceRectangle'] emotion = data[id]['faceAttributes']['emotion'] top = int(rect['top']) left = int(rect['left']) btm = top + int(rect['height']) right = left + int(rect['width']) #draw.rectangle((left, top, right, btm), outline=(255, 255, 255)) cv2.rectangle(frame, (left,top),(right,btm),(255,255,255),3) #cv2.putText(frame,emotion,(10,500), font, 4,(255,255,255),2,cv2.LINE_AA) emotion_result = '' dy = top + 0 for e in emotion: emotion_result = e + ':' + str(emotion[e]) dy = dy + 15 cv2.putText(frame,emotion_result,(right + 10,dy), 0, 0.5,(255,255,255),1,cv2.LINE_AA) cv2.imshow('Raw Frame', frame) print("") k = cv2.waitKey(1) if k == 27: print() break except Exception as e: print("[Errno {0}] {1}".format(e.errno, e.strerror))
error Traceback (most recent call last) <ipython-input-5-e0a11eb91c6f> in <module> 37 ---> 38 cv2.imshow('Raw Frame', frame) 39 error: C:\ci\opencv_1512688052760\work\modules\highgui\src\window.cpp:331: error: (-215) size.width>0 && size.height>0 in function cv::imshow During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) <ipython-input-5-e0a11eb91c6f> in <module> 66 break 67 except Exception as e: ---> 68 print("[Errno {0}] {1}".format(e.errno, e.strerror)) AttributeError: 'error' object has no attribute 'errno'
エラー部分の最後の行をコメントアウトしprint(error")にしてもerrorと表示されるだけで変化はありませんでした。何が原因かがわかりません。解決法などありましたらよろしくお願いいたします。
![guest](/img/icon/icnUserSample.jpg)
あなたの回答
tips
プレビュー