2017-06-09 33 views
0

私は数日前にプログラミングを始めましたが、私はこの問題を抱えています:AttributeError: 'NoneType' object has no attribute 'tostring'。私は何が間違っているのか分からない。AttributeError: 'NoneType'オブジェクトに 'tostring'属性がありません

#Reads through each frame, calculates the timestamp, places it on the frame and 
#exports the frame to the output video. 
while current_frame < total_frames: 
    success, image = video.read() 
    elapsed_time = video.get(cv2.CAP_PROP_POS_MSEC) 
    current_frame = video.get(cv2.CAP_PROP_POS_FRAMES) 
    timestamp = initial + dt.timedelta(microseconds = elapsed_time*1000) 
    cv2.putText(image, 'Date: ' + str(timestamp)[0:10], (50,int(height-150)), cv2.FONT_HERSHEY_COMPLEX_SMALL, 2, (255, 255, 255), 3) 
    cv2.putText(image, 'Time: ' + str(timestamp)[11:-4], (50,int(height-100)), cv2.FONT_HERSHEY_COMPLEX_SMALL, 2, (255, 255, 255), 3) 
    pipe.stdin.write(image.tostring()) 

答えて

0

これは、いくつかのフレームが正しく返却されていない可能性がありますし、そうimage変数が空であるためNoneTypeである、つまり、それは何のタイプを持っていません。

image.shapeを使用して画像の形状を確認してください。

また、Pythonの変数のタイプをtype(variable)でチェックすることもできます。

if image.shape[0]==0 or image.shape[1]==0: continue #or do something else to handle this

+0

これはコメントのように見えますが、質問に対する回答ではありません。 – LethalProgrammer

関連する問題