虽然不知道能不能在论坛问pyqt的问题,但是我实在是找不到可以问的地方了。
我用pyqt做的图传连接mjpeg_streamer_ap 热点这个例程创建的ip(也就是192.168.1.1:8080),但是程序就会直接卡死。
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtCore import Qt
import socket
import numpy as np
import struct
import pickle
class Client(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(100, 100, 640, 480)
self.setWindowTitle('TCP Client')
self.label = QLabel(self)
self.label.setAlignment(Qt.AlignCenter)
self.label.setGeometry(0, 0, 640, 480)
self.show()
# create a socket object
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# get local machine name
host = '192.168.1.1'
port = 8080
# connection to hostname on the port.
self.client_socket.connect((host, port))
# receive data from the server
data = b''
payload_size = struct.calcsize("L")
while True:
while len(data) < payload_size:
data += self.client_socket.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 += self.client_socket.recv(4096)
frame_data = data[:msg_size]
data = data[msg_size:]
frame = pickle.loads(frame_data, fix_imports=True, encoding="bytes")
frame = np.array(frame, dtype=np.uint8).reshape((480, 640))
h, w = frame.shape
bytesPerLine = w
convertToQtFormat = QImage(frame.data, w, h, bytesPerLine, QImage.Format_Grayscale8)
p = QPixmap.fromImage(convertToQtFormat)
self.label.setPixmap(p)
if __name__ == '__main__':
app = QApplication(sys.argv)
client = Client()
sys.exit(app.exec_())
只要能告诉我做下去的方向和方法就可以,我真的在其他地方找不到可以解决的办法了