title: Capture face area by camera
body: <p>I am having problems getting face detection and cropping an image to the face working, below is my code.</p>
  
  <pre><code>import cv2
  
  class Crop:
      #constructor
      def __init__(self, image):
          self.data = image
      def facechop(self):
          # read xml for training data
          facedata = "haarcascade_frontalface_default.xml"
          cascade = cv2.CascadeClassifier(facedata)
          # read image file
          img = cv2.imread(self.data, 0)
  
          minisize = (img.shape[1], img.shape[0])
          miniframe = cv2.resize(img, minisize)
  
          faces = cascade.detectMultiScale(miniframe)
          for f in faces:
              x, y, w, h = [ v for v in f ]
              cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 255))
  
              sub_face = self.data[y:y + h, x:x + w]
  
          # Show picture
          cv2.imshow('img', sub_face)
          return
  </code></pre>
  
  <p>input image file</p>
  
  <pre><code>picture = 'izz.jpg'
  pic = Crop(gambar)
  
  pic.facechop()
  
  # keyboard input to destroy the window
  while(True):
      key = cv2.waitKey(0)
      if key in [27, ord('Q'), ord('q')]:
          break
  </code></pre>
  
  <p>when it's running, it doesn't do raw after <code>for</code> function till <code>sub_face = self.data[y:y + h, x:x + w]</code>. It directly goes to <code>cv2.imshow('img', sub_face)</code>. So, <code>sub_face</code> is not known. Why does it not work well?
  I'm using Aptana to debug it. Thank you.</p>