我正在尝试稍微调整此处给出的example.py代码-https://github.com/damiafuentes/DJITelloPy,以对无人机视频流接收到的帧进行图像分类。我的图像分类器是使用fast.ai库构建的。我不确定我的方法是否是解决此问题的最佳方法。
我尝试将框架存储在系统上的单独文件夹中,但即使这样似乎也不起作用。总是收到此错误
Err98:端口已在使用中。
def run(self):
if not self.tello.connect():
print("Tello not connected")
return
if not self.tello.set_speed(self.speed):
print("Not set speed to lowest possible")
return
# In case streaming is on. This happens when we quit this program without the escape key.
if not self.tello.streamoff():
print("Could not stop video stream")
return
if not self.tello.streamon():
print("Could not start video stream")
return
frame_read = self.tello.get_frame_read()
should_stop = False
while not should_stop:
for event in pygame.event.get():
if event.type == USEREVENT + 1:
self.update()
elif event.type == QUIT:
should_stop = True
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
should_stop = True
else:
self.keydown(event.key)
elif event.type == KEYUP:
self.keyup(event.key)
if frame_read.stopped:
frame_read.stop()
break
self.screen.fill([0, 0, 0])
frame = cv2.cvtColor(frame_read.frame, cv2.COLOR_BGR2RGB)
frame = np.rot90(frame)
frame = np.flipud(frame)
frame = pygame.surfarray.make_surface(frame)
#code added for image classification
pred_class, pred_idx, outputs = learn.predict(frame)
if outputs[1]>0.7:
img.show()
print ("Detected", pred_class)
self.screen.blit(frame, (0, 0))
pygame.display.update()
time.sleep(1 / FPS)
# Call it always before finishing. I deallocate resources.
self.tello.end()
我期望与图像一起预测特定图像类别的帧,但事实并非如此。错误是
AttributeError:“ pygame.Surface”对象没有属性“ apply_tfms”