<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,18 +1,40 @@
 from wrappers import *
 
-camera = Camera(CV_CAP_ANY)
-window = Window()
-initial = False
+class FingerTracking:
+  
+  def __init__(self):
+    self.camera = Camera(CV_CAP_ANY)
+    self.window = Window()
+    self.initial = False
+    self.threshold = 50
+    self.running = True
 
-while True:
+  def run(self):
+    while self.running:
+      current = self.camera.frame().grayscale()
+      if not self.initial:
+        self.initial = current
+      self.window.show(current.sub(self.initial).threshold(self.threshold, mode=CV_THRESH_BINARY_INV))
+      self._handleKeyboardEvents()
 
-  current = camera.frame().grayscale().invert()
 
-  if not initial:
-    initial = current
+  def _handleKeyboardEvents(self):  
+    key = getKeyPressed()
+  
+    if key == '\x1b': # escape
+      self.window.destroy()
+      self.running = False
+  
+    elif key == ' ':
+      self.initial = False
+    
+    elif key == '+':
+      self.threshold += 10
+      print 'Threshold:', self.threshold
+  
+    elif key == '-':
+      self.threshold -= 10
+      print 'Threshold:', self.threshold
 
-  window.show(current.sub(initial).threshold(20, mode=CV_THRESH_BINARY_INV))
-
-  if escape_pressed():
-    window.destroy()
-    break
+if __name__ == '__main__':
+  FingerTracking().run()
\ No newline at end of file</diff>
      <filename>finger-tracking.py</filename>
    </modified>
    <modified>
      <diff>@@ -2,76 +2,76 @@ from opencv import *
 from opencv.highgui import *
 
 class Window:
-    def __init__(self, name=&quot;Main Window&quot;):
-        self.name = name
-        cvNamedWindow(name)
-    
-    def show(self, image):
-        cvShowImage(self.name, image.image)
-    
-    def destroy(self):
-        cvDestroyWindow(self.name)
+  def __init__(self, name=&quot;Main Window&quot;):
+    self.name = name
+    cvNamedWindow(name)
+  
+  def show(self, image):
+    cvShowImage(self.name, image.image)
+  
+  def destroy(self):
+    cvDestroyWindow(self.name)
 
 class Camera:
     
-    def __init__(self, id):
-        self.capture = cvCreateCameraCapture(id)
-        
-    def frame(self):
-        return Image(cvQueryFrame(self.capture))
+  def __init__(self, id):
+    self.capture = cvCreateCameraCapture(id)
+      
+  def frame(self):
+    return Image(cvQueryFrame(self.capture))
 
 class Image:
-    
-    def __init__(self, image):
-        self.image = image
-        self.size = cvSize(image.width, image.height)
-        
-    def __del__(self):
-        if self and self.image:
-            cvReleaseImage(self.image)
-        
-    def grayscale(self, channels=1):
-        result = cvCreateImage(self.size, self.image.depth, channels)
-        cvCvtColor(self.image, result, CV_RGB2GRAY)
-        return Image(result)
+  
+  def __init__(self, image):
+    self.image = image
+    self.size = cvSize(image.width, image.height)
+      
+  def __del__(self):
+    if self and self.image:
+      cvReleaseImage(self.image)
+      
+  def grayscale(self, channels=1):
+    result = cvCreateImage(self.size, self.image.depth, channels)
+    cvCvtColor(self.image, result, CV_RGB2GRAY)
+    return Image(result)
 
-    def threshold(self, threshold, max_value=255, mode=CV_THRESH_BINARY, channels=1):
-        result = cvCreateImage(self.size, self.image.depth, channels)
-        cvThreshold(self.image, result, threshold, 255, mode)
-        return Image(result)
-        
-    def add(self, anotherImage, channels=1):
-        result = cvCreateImage(self.size, self.image.depth, channels)
-        cvAdd(self.image, anotherImage, result)
-        return Image(result)
+  def threshold(self, threshold, max_value=255, mode=CV_THRESH_BINARY, channels=1):
+    result = cvCreateImage(self.size, self.image.depth, channels)
+    cvThreshold(self.image, result, threshold, 255, mode)
+    return Image(result)
+      
+  def add(self, anotherImage, channels=1):
+    result = cvCreateImage(self.size, self.image.depth, channels)
+    cvAdd(self.image, anotherImage, result)
+    return Image(result)
 
-    def sub(self, anotherImage, channels=1):
-        result = cvCreateImage(self.size, self.image.depth, channels)
-        cvSub(self.image, anotherImage.image, result)
-        return Image(result)
+  def sub(self, anotherImage, channels=1):
+    result = cvCreateImage(self.size, self.image.depth, channels)
+    cvSub(self.image, anotherImage.image, result)
+    return Image(result)
 
-    def xor(self, anotherImage, channels=1):
-        result = cvCreateImage(self.size, self.image.depth, channels)
-        cvXor(self.image, anotherImage, result)
-        return Image(result)
-        
-    def _and(self, anotherImage, channels=1):    
-        result = cvCreateImage(self.size, self.image.depth, channels)
-        cvAnd(self.image, anotherImage, result)
-        return Image(result)        
-    
-    def _not(self, channels=1):
-        result = cvCreateImage(self.size, self.image.depth, channels)
-        cvNot(self.image, result)
-        return Image(result)        
+  def xor(self, anotherImage, channels=1):
+    result = cvCreateImage(self.size, self.image.depth, channels)
+    cvXor(self.image, anotherImage, result)
+    return Image(result)
     
-    def invert(self, channels=1):
-        return self._not(channels)
-        
-    def nand(self, anotherImage, channels=1):
-        return self._not(self.image)._and(anotherImage)
+  def _and(self, anotherImage, channels=1):    
+    result = cvCreateImage(self.size, self.image.depth, channels)
+    cvAnd(self.image, anotherImage, result)
+    return Image(result)        
 
-def escape_pressed():
-    return cvWaitKey(10) == '\x1b'
+  def _not(self, channels=1):
+    result = cvCreateImage(self.size, self.image.depth, channels)
+    cvNot(self.image, result)
+    return Image(result)        
 
+  def invert(self, channels=1):
+    return self._not(channels)
+    
+  def nand(self, anotherImage, channels=1):
+    return self._not(self.image)._and(anotherImage)
+
+def getKeyPressed(wait=10):
+  return cvWaitKey(wait)
+    
 cvStartWindowThread()    </diff>
      <filename>wrappers.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>93d69c8ae49b582eb57ea982c68658f3e90126af</id>
    </parent>
  </parents>
  <author>
    <name>Carlos Villela</name>
    <email>cv@lixo.org</email>
  </author>
  <url>http://github.com/cv/opencv-wrappers/commit/627bd70a6b50bf1f4a84ffae8a54426d629f2e9b</url>
  <id>627bd70a6b50bf1f4a84ffae8a54426d629f2e9b</id>
  <committed-date>2008-05-15T16:22:31-07:00</committed-date>
  <authored-date>2008-05-15T16:22:31-07:00</authored-date>
  <message>fixed indentation (soft tabs=2 ftw), objectified finger tracking demo - looks more verbose, but it's easier to expand with new key events and the image manipulation stuff is a little more contained</message>
  <tree>61871949ec7758125439b176826b9954f5aea626</tree>
  <committer>
    <name>Carlos Villela</name>
    <email>cv@lixo.org</email>
  </committer>
</commit>
