我正在尝试从ArDrone 2.0获取图像,并使用Python OpenCV cv2处理图像并创建一个控制器。
这是我的代码:
import cv2
import numpy as np
from pydrone import libardrone
drone = libardrone.ARDrone()
cap = drone.image
while(True):
ret, frame = cap
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
但是,我一直遇到这个问题:
Traceback (most recent call last):
File "ArDrn/7/drony.py", line 14, in <module>
ret, frame = cap
TypeError: 'NoneType' object is not iterable
有人可以告诉我我在做什么错吗?
在我看来,您可能需要稍微更改逻辑以在尝试使用cap之前检查cap是否为None:
while(True):
cap = drone.image
if not cap:
time.sleep(0.1) # or something to save just a touch of CPU spin time, optional
continue
ret, frame = cap
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
可能是因为它处于切换图像的中间或类似的时间,但可能有一段时间cap设置为None。此外,似乎您没有更新上限以指向每个循环的新图像,因此也可能是一个问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句