Exemplo n.º 1
0
    def detectFace(self):
        print "stuff"
        import sys, getopt
        print help_message

        args, video_src = getopt.getopt(sys.argv[1:], '', ['cascade=', 'nested-cascade='])
        try: video_src = video_src[0]
        except: video_src = 0
        args = dict(args)
        # cascade_fn = args.get('--cascade', "haarcascade_frontalface_alt.xml")
        cascade = cv2.CascadeClassifier("haarcascade_frontalface_alt.xml")
        
        cam = create_capture(video_src, fallback='synth:bg=lena.jpg:noise=0.05')
        found = False
        
        while True:
            ret, img = cam.read()
            rects = self.detect(img, cascade)
            vis = img.copy()
            if(rects != [] and found == False):
                print "here"
                if goodOrBad(img,cascade):
                    found = True

            cv2.imshow('facedetect', vis)

            if 0xFF & cv2.waitKey(5) == 27:
                break
        cv2.destroyAllWindows()
Exemplo n.º 2
0
def image_capture(queue):
   '''
   Attempts to detect a face in the video feed, and adds a frame to the queue.
   '''
   import sys, getopt

   args, video_src = getopt.getopt(sys.argv[1:], '', ['cascade=', 'nested-cascade='])
   try: video_src = video_src[0]
   except: video_src = 0
   args = dict(args)
   cascade_fn = args.get('--cascade', "../metadata/haarcascade_frontalface_alt.xml")
   cascade = cv2.CascadeClassifier(cascade_fn)
        
   vidFile = create_capture(video_src, fallback='synth:bg=lena.jpg:noise=0.05')
   
   curr = 1

   while True:

      try:
         flag, frame = vidFile.read() # what does flag mean? 
         # Flag just tells you if it was able to successfully capture the image or not
         frame = frame[frame.shape[1]/2-150:frame.shape[1]/2+200, frame.shape[0]/2-50:frame.shape[0]/2+250]

         rects = detect(frame, cascade)
         
         if(rects != []):
            if goodOrBad(frame,cascade, curr):
               curr = curr +1
               found = True
               lf.config(bg = "Green")
               lf_text.config(text="Face Detected", bg="Green")
            else:
               lf.config(bg = "Red")
               lf_text.confid(text="Searching for a face...", bg="Red")
         
         
         if flag==0:
            break
         queue.put(frame) 	# why is this loading frames onto the queue? because the thread might not
         					# be able to display frames quickly enough?
         #This is a producer/consumer type of problem. The queue is thread safe, one process
         # puts things on the queue and another process removes things from ther queue.
         
      except:
         continue