User:Birgit Bachler/techday motion
Motion Assignment
Step1: Making the iSight Camera work in Ubuntu
# cd
# mkdir /mnt/macosx
# mount /dev/sda2 /mnt/macosx
# cp /mnt/macosx/System/Library/Extensions/
IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/
Contents/MacOS/AppleUSBVideoSupport .
# umount /mnt/macosx
# sudo apt-get install isight-firmware-tools
# cd
# ift-extract -a ./AppleUSBVideoSupport
# /etc/init.d/hal restart
See: http://handyfloss.net/2008.07/making-isight-camera-work-in-ubuntu/
Step2: Messing around with the motion.py script
#!/usr/bin/python
import sys
from os import system
import pygame
from pygame.locals import *
from pygame.time import Clock
from time import sleep
import thread
from pygame.locals import *
def reader ():
while True:
line = sys.stdin.readline()
if (not line): break
line = line.strip()
if line.startswith("motion"):
# print "read motion data:", line
(x, y, w, h, numpixels) = [int(x) for x in line.split()[1:]]
evt = pygame.event.Event(USEREVENT, {"x" : x, "y": y, "w":w, "h":h})
pygame.event.post(evt)
(rx, ry, rw, rh) = (0, 0, 0, 0)
(mx, my, mw, mh) = (10, 10, 50, 50)
pygame.init()
# screen = pygame.display.set_mode((640, 480), FULLSCREEN, 32)
screen = pygame.display.set_mode((640, 480), 0, 32)
pygame.display.set_caption("motionbox")
clock = Clock()
thread.start_new_thread(reader, ())
while True:
for event in pygame.event.get():
if event.type==QUIT or \
(event.type == KEYDOWN and event.key == K_ESCAPE):
sys.exit()
elif event.type == USEREVENT:
# print event
mx = event.x
my = event.y
mw = event.w
mh = event.h
# adjust mx, my (as they are a center point)
mx -= mw/2
my -= mh/2
rx += 0.25*(mx-rx)
ry += 0.25*(my-ry)
rw += 0.25*(mw-rw)
rh += 0.25*(mh-rh)
#xx= mx*100
sliderw = float(rw) / 480
sliderh = float(rh) / 640
c = int(sliderw * 255)
d = int(sliderh * 255)
screen.fill((c, 0, d))
pygame.draw.rect(screen, (d, d, d), (rx, ry, rw, rh), 1)
pygame.display.update()
clock.tick(30)