gpt4 book ai didi

python-2.7 - 属性错误 : 'NoneType' object has no attribute 'tostring'

转载 作者:行者123 更新时间:2023-12-04 23:26:28 28 4
gpt4 key购买 nike

所以前几天刚开始编程,遇到了这个问题:AttributeError: 'NoneType' object has no attribute '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())

最佳答案

可能某些帧没有正确返回,因此 image变量为空,因此为 NoneType ,即它没有类型。

使用 image.shape 检查图像的形状.

您还可以使用 type(variable) 检查 Python 中任何变量的类型。 .
if image.shape[0]==0 or image.shape[1]==0:
continue #or do something else to handle this

关于python-2.7 - 属性错误 : 'NoneType' object has no attribute 'tostring' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44465713/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com