opencv顯示伺服器影像(舊) - jenhaoyang/ml_blog GitHub Wiki

Using imageZMQ, this is possible with 11 lines of Python on each Raspberry Pi and with 8 lines of Python on the Mac.

First, run this code on the Mac (or other display computer):

 1   # run this program on the Mac to display image streams from multiple RPis
 2   import cv2
 3   import imagezmq
 4   image_hub = imagezmq.ImageHub()
 5   while True:  # show streamed images until Ctrl-C
 6       rpi_name, image = image_hub.recv_image()
 7       cv2.imshow(rpi_name, image) # 1 window for each RPi
 8       cv2.waitKey(1)
 9       image_hub.send_reply(b'OK')

Then, on each Raspberry Pi, run:

 1   # run this program on each RPi to send a labelled image stream
 2   import socket
 3   import time
 4   from imutils.video import VideoStream
 5   import imagezmq
 6 
 7   sender = imagezmq.ImageSender(connect_to='tcp://jeff-macbook:5555')
 8 
 9   rpi_name = socket.gethostname() # send RPi hostname with each image
10   picam = VideoStream(usePiCamera=True).start()
11   time.sleep(2.0)  # allow camera sensor to warm up
12   while True:  # send images as stream until Ctrl-C
13       image = picam.read()
14       sender.send_image(rpi_name, image)

參考:
https://github.com/jeffbass/imagezmq