跳至主要內容
视频流传输

使用 imagezmq 传输视频流

视频流发送端

from imutils.video import VideoStream
import imagezmq
import socket
import cv2

# 创建VideoCapture对象,参数0表示使用默认的摄像头
cap = cv2.VideoCapture(0)

#ubuntu 的ip
sender = imagezmq.ImageSender(connect_to='tcp://10.144.54.202:5555') 
cam_id = socket.gethostname()
print("cam_id: ",cam_id)

while True:
    # 读取视频流的帧
    ret, frame = cap.read()
    sender.send_image(cam_id, frame)
    print(frame.shape)

    resized_frame = cv2.resize(frame, (640, 480))

    cv2.imshow('Resized Frame', resized_frame)

    # 按下'q'键退出循环
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# 释放VideoCapture对象
cap.release()

# 关闭所有打开的窗口
cv2.destroyAllWindows()


大约 1 分钟使用指南ImageZMQvideo_streamingpython