@@ -7,7 +7,7 @@ import cv2 | |||
# Connect a client socket to my_server:8000 (change my_server to the | |||
# hostname of your server) | |||
client_socket = socket.socket() | |||
client_socket.connect(('my_server', 8000)) | |||
client_socket.connect(('192.168.1.107', 8000)) | |||
# Make a file-like object out of the connection | |||
connection = client_socket.makefile('wb') | |||
@@ -17,11 +17,15 @@ try: | |||
while True: | |||
ret, frame = cap.read() | |||
if frame == None: | |||
if frame is None: | |||
break | |||
image = cv2.imencode('.jpg', frame) | |||
print(type(frame)) | |||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |||
print(type(gray)) | |||
_, image = cv2.imencode('.jpg', gray) | |||
print(type(image)) | |||
stream = image.tobytes() | |||
print(type(stream)) | |||
# Write the length of the capture to the stream and flush to | |||
# ensure it actually gets sent |
@@ -0,0 +1,14 @@ | |||
# run this program on each RPi to send a labelled image stream | |||
import socket | |||
import time | |||
from imutils.video import VideoStream | |||
import imagezmq | |||
sender = imagezmq.ImageSender(connect_to='tcp://jeff-macbook:5555') | |||
rpi_name = socket.gethostname() # send RPi hostname with each image | |||
picam = VideoStream(usePiCamera=True).start() | |||
time.sleep(2.0) # allow camera sensor to warm up | |||
while True: # send images as stream until Ctrl-C | |||
image = picam.read() | |||
sender.send_image(rpi_name, image) |
@@ -0,0 +1,10 @@ | |||
import cv2 | |||
import imagezmq | |||
image_hub = imagezmq.ImageHub() | |||
while True: # show streamed images until Ctrl-C | |||
rpi_name, image = image_hub.recv_image() | |||
cv2.imshow(rpi_name, image) # 1 window for each RPi | |||
cv2.waitKey(1) | |||
image_hub.send_reply(b'OK') |