public
Description: A collection of object-oriented Python wrappers for OpenCV
Homepage:
Clone URL: git://github.com/cv/opencv-wrappers.git
opencv-wrappers / finger-tracking.py
100644 40 lines (30 sloc) 0.937 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from wrappers import *
 
class FingerTracking:
  
  def __init__(self):
    self.camera = Camera(CV_CAP_ANY)
    self.window = Window()
    self.initial = False
    self.threshold = 50
    self.running = 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()
 
 
  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
 
if __name__ == '__main__':
  FingerTracking().run()