我在Windows 10 X64上使用python v3.7和PyQt5
我想在客户端中截屏(捕获桌面)并通过套接字发送到服务器。
在服务器接收映像中并显示此文件(作为远程桌面)。
我使用两种方法显示图像:1- cv2.imshow()和2-Pyqt QLabel.setPixmap()
使用cv2.imshow()不会出现问题,并且一切正常。
但是,当我使用Pyqt QLabel.setPixmap()方法时,会显示图像,但是大约1分钟后,程序会停止(有点像挂起)并停止而没有任何错误。
我使用线程以如下方式运行getVideo函数:
vv = threading.Thread(target=getVideo,args=(self,))
vv.start()
我的问题是为什么当我使用QLabel显示从套接字接收的序列图像时,大约1分钟后我的程序停止了吗?
def getVideo(celf):
host = '0.0.0.0'
mouse_port = 5559
video_s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
video_s.bind((host, mouse_port))
video_s.listen(1)
print("Server is Waiting to Accept a client ...")
conn, video_addr = video_s.accept()
print("Video --- {0}:{1} is connected to server\n".format(video_addr[0],
video_addr[1]))
data = b""
payload_size = struct.calcsize(">L")
while (True):
if(not vid_flag):
conn.send(bytes(False))
continue
conn.send(bytes(True))
while len(data) < payload_size:
data += conn.recv(4096)
packed_msg_size = data[:payload_size]
data = data[payload_size:]
msg_size = struct.unpack(">L", packed_msg_size)[0]
while len(data) < msg_size:
data += conn.recv(4096)
frame_data = data[:msg_size]
data = data[msg_size:]
frame_data = zlib.decompress(frame_data)
frame = pickle.loads(frame_data, fix_imports=True, encoding="bytes")
frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
qformat = QImage.Format_Indexed8
if (len(frame.shape) == 3):
if (frame.shape[2] == 4):
qformat = QImage.Format_RGBA8888
else:
qformat = QImage.Format_RGB888
out_image = QImage(frame, frame.shape[1], frame.shape[0],frame.strides[0], qformat)
out_image = out_image.rgbSwapped()
celf.imgshow_place.setPixmap(QPixmap.fromImage(out_image))
celf.imgshow_place.setScaledContents(True)
// ---------method 1 work correctly------------
//cv2.imshow('ImageWindow', frame)// method 1
//cv2.waitKey(1) // method 1
谢谢