rpi-camera/rpi.py

35 lines
951 B
Python

import socket
import pygame
import pygame.camera
import sys
import time
port = 5802
pygame.init()
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(("",port))
serversocket.listen(1)
pygame.camera.init()
goalCam = pygame.camera.Camera("/dev/video0",(320,240))
floorCam = pygame.camera.Camera("/dev/video1",(320,240))
goalCam.start()
floorCam.start()
while True:
connection, address = serversocket.accept()
goalImage = goalCam.get_image() # capture image
floorImage = floorCam.get_image() # capture image
merged = pygame.Surface([640,480])
merged.blit(goalImage,(0,0))
merged.blit(floorImage,(320,0))
data = pygame.image.tostring(merged,"RGB") # convert captured image to string, use RGB color scheme
try:
connection.sendall(data)
except socket.error:
print("error")
time.sleep(0.05)
connection.close()