我正在尝试从网络摄像头流到另一台计算机并将流保存在numpy数组中的pickle文件中。我稍后将处理iskits库中的帧。 ****我从发件人发送字符串并将其转换为numpy数组并保存到pickle文件。****
但是当我尝试从.pkl文件加载流时,它显示错误。 当我尝试打印数组的大小时,它显示0或1或2。
with open('/home/siplab/samples.pkl','rb') as f:
data = pickle.load(f)
print shape(data)
输出显示
siplab@siplab-OptiPlex-9020:~$ python gh.py
(2,)
客户端的代码是
import socket
import pygame
import sys
import numpy as np
import pickle
host = "127.0.1.1"
port=5000
screen = pygame.display.set_mode((640,480),0)
pygame.display.set_caption('Webcam Viewer')
while True:
clientsocket=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect((host, port))
received = []
while True:
recvd_data = clientsocket.recv(1024000)
if not recvd_data:
break
else:
received.append(recvd_data)
dataset = ''.join(received)
image = pygame.image.fromstring(dataset,(640,480),"RGB")
screen.blit(image,(0,0))
pygame.display.update()
k = np.asarray('received',dtype=float,sep=', ')
with open('samples.pkl','wb') as f:
pickle.dump(k,f)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
服务器的代码是
import socket
import pygame
import pygame.camera
import sys
import time
port = 5000
pygame.init()
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(("127.0.1.1",port))
serversocket.listen(5)
pygame.camera.init()
screen = pygame.display.set_mode((640,480))
webcam = pygame.camera.Camera("/dev/video0",(640,480))
webcam.start()
while True:
connection, address = serversocket.accept()
image = webcam.get_image()
screen.blit(image,(0,0))
data = pygame.image.tostring(image,"RGB")
connection.sendall(data)
pygame.display.update()
time.sleep(0.1)
connection.close()