Browse Source

move streaming to new folder + other method

master
Lennart Heimbs 5 years ago
parent
commit
ebff3999bd

camera/video_client_pi.py → camera/video_stream/video_client_pi.py View File


camera/video_client_pi_cv2.py → camera/video_stream/video_client_pi_cv2.py View File

# Connect a client socket to my_server:8000 (change my_server to the # Connect a client socket to my_server:8000 (change my_server to the
# hostname of your server) # hostname of your server)
client_socket = socket.socket() 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 # Make a file-like object out of the connection
connection = client_socket.makefile('wb') connection = client_socket.makefile('wb')
while True: while True:
ret, frame = cap.read() ret, frame = cap.read()


if frame == None:
if frame is None:
break 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() stream = image.tobytes()
print(type(stream))


# Write the length of the capture to the stream and flush to # Write the length of the capture to the stream and flush to
# ensure it actually gets sent # ensure it actually gets sent

camera/video_server.py → camera/video_stream/video_server.py View File


+ 14
- 0
camera/video_stream/zmq_video_client.py View File

# 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)

+ 10
- 0
camera/video_stream/zmq_video_server.py View File

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')

Loading…
Cancel
Save