Created
April 15, 2009 02:14
-
-
Save techbelly/95556 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
require "rubygems" | |
require "opencv" | |
include OpenCV | |
class IChat | |
def available! | |
tell_me_to "set status to available" | |
end | |
def away! | |
tell_me_to "set status to away" | |
end | |
def tell_me_to(message) | |
lines = ['tell application "System Events"', | |
'if exists process "iChat" then', | |
'tell application "iChat"', | |
message, | |
'end tell', | |
'end if', | |
'end tell'] | |
cmd = "-e '#{lines.join("' -e '")}'" | |
system "osascript #{cmd}" | |
end | |
end | |
camera = CvCapture.open | |
face_detector = CvHaarClassifierCascade::load("haarcascade_frontalface_alt.xml") | |
ichat = IChat.new | |
check_every = 10 | |
while true | |
image = camera.query | |
faces = face_detector.detect_objects(image) | |
if faces.empty? | |
ichat.away! | |
else | |
ichat.available! | |
end | |
sleep(check_every) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment