我有一个客户机-服务器程序,其中raspberry pi有客户机,pc机包含服务器。我想把由pi捕捉到的图像发送到服务器并在那里进行处理。代码如下所示。 客户端:
import io
import socket
import struct
from PIL import Image
s = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
s.connect(('ip', 12345))
connection = s.makefile('wb')
try:
camera = picamera.PiCamera()
camera.resolution = (640, 480)
camera.start_preview()
time.sleep(2)
stream = io.BytesIO()
camera.capture(stream , format='jpeg')
connection.write(struct.pack('<L', stream.tell()))
connection.flush()
stream.seek(0)
connection.write(stream.read())
stream.seek(0)
stream.truncate()
finally:
camera.stop_preview()
connection.close()
client_socket.close()
服务器:
^{pr2}$执行此程序时,会出现一个错误,说明:
Traceback (most recent call last):
File "server.py", line 24, in <module>
image = Image.open(image_stream)
File "C:\Users\USER\AppData\Local\conda\conda\envs\cvv\lib\site-packages\PIL\I
mage.py", line 2687, in open
% (filename if filename else fp))
OSError:
cannot identify image file <_io.BytesIO object at 0x000000D6
请帮我拿这个。在
目前没有回答
相关问题 更多 >
编程相关推荐