Last active
October 5, 2016 02:22
-
-
Save lpereira/7178f27fe06ecfe042a0eff656786eed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
import random | |
import pygame | |
import pygame.camera | |
import pygame.transform | |
from pygame.locals import * | |
UDP_IP = "192.168.50.50" | |
UDP_PORT = 2711 | |
pygame.init() | |
pygame.camera.init() | |
camlist = pygame.camera.list_cameras() | |
if camlist: | |
cam = pygame.camera.Camera(camlist[0],(640,480), "RGB") | |
cam.start() | |
else: | |
raise "Sem camera" | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
def yield_bytes(surf): | |
for x in range(10): | |
for y in range(10): | |
color = image.get_at((x, y)) | |
yield chr(color.r) | |
yield chr(color.g) | |
yield chr(color.b) | |
while True: | |
image = pygame.transform.smoothscale(cam.get_image(), (10, 10)) | |
message = bytes('\x00\x00\x00\x00\x64' + ''.join(yield_bytes(image)), 'iso-8859-1') | |
sock.sendto(message, (UDP_IP, UDP_PORT)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment