我正在尝试通过 UDP 从我的 Raspberry Pi 上的相机流式传输图像。我正在 Android 设备上接收/显示它们。
根据我的计算,我的应用程序以 10 fps 的最大速率发送,但我需要 25 fps。
有谁知道如何加快我的解决方案,或者有更好的解决方案?
我的代码如下
sock=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect((UDP_IP, UDP_PORT))
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 30
rawCapture = PiRGBArray(camera, size=(640, 480))
time.sleep(0.1)
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
image = frame.array
img = Image.fromarray(image,'RGB')
output = StringIO.StringIO()
img.save(output, format='JPEG')
contents = output.getvalue()
output.close()
sock.send(contents)
key = cv2.waitKey(1) & 0xFF
rawCapture.truncate(0)
sock.close