rpi-camera/rpi.py

35 lines
864 B
Python
Raw Normal View History

2016-07-28 15:19:27 -04:00
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()
2016-07-28 15:27:33 -04:00
goalImage = goalCam.get_image()
floorImage = floorCam.get_image()
2016-07-28 15:19:27 -04:00
merged = pygame.Surface([640,480])
merged.blit(goalImage,(0,0))
merged.blit(floorImage,(320,0))
2016-07-28 15:27:33 -04:00
data = pygame.image.tostring(merged,"RGB")
2016-07-28 15:19:27 -04:00
try:
connection.sendall(data)
except socket.error:
print("error")
time.sleep(0.05)
connection.close()