def detectObject(image):
  grayscale = cv.cvCreateImage(size, 8, 1)
  cv.cvFlip(image, None, 1)
  cv.cvCvtColor(image, grayscale, cv.CV_BGR2GRAY)
  storage = cv.cvCreateMemStorage(0)
  cv.cvClearMemStorage(storage)
  cv.cvEqualizeHist(grayscale, grayscale)
  cascade = cv.cvLoadHaarClassifierCascade(haar_file, cv.cvSize(1,1))
  objects = cv.cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2, 
                                   cv.CV_HAAR_DO_CANNY_PRUNING,
                                   cv.cvSize(100,100))

  # Draw dots where hands are
  if objects:
    for i in objects:
      #cv.cvRectangle(image, cv.cvPoint( int(i.x), int(i.y)),
      #               cv.cvPoint(int(i.x+i.width), int(i.y+i.height)),
      #               cv.CV_RGB(0,255,0), 3, 8, 0)
      center = cv.cvPoint(int(i.x+i.width/2), int(i.y+i.height/2))
      cv.cvCircle(image, center, 10, cv.CV_RGB(0,0,0), 5,8, 0)
      # Left side check
      if center.x > box_forward_left[0].x and center.x < box_backwards_left[1].x and center.y > box_forward_left[0].y and center.y < box_backwards_left[1].y:
        set_speed('left', center)
      # Right side check
      if center.x > box_forward_right[0].x and center.x < box_backwards_right[1].x and center.y > box_forward_right[0].y and center.y < box_backwards_right[1].y:
        set_speed('right', center)
Example #2
0
	def init(self):
		#Load the cascade classifier data
		self.cascade=cv.cvLoadHaarClassifierCascade(self.file_path(self.cascade_file),cv.cvSize(self.haar_face_size[0],self.haar_face_size[1]))

		#Allocate/init storage
		self.storage=cv.cvCreateMemStorage(0)
		cv.cvClearMemStorage(self.storage)
Example #3
0
 def get_cascade(self, cascade_name):
     self._cached_cascades[
         cascade_name] = opencv.cvLoadHaarClassifierCascade(
             os.path.join(self.cascade_dir, cascade_name),
             opencv.cvSize(1, 1))
     #cascade_name, opencv.cvSize(1,1))
     return self._cached_cascades[cascade_name]
Example #4
0
def face_detect(file, closeafter=True):
    """Converts an image to grayscale and prints the locations of any faces found"""

    if hasattr(file, 'read'):
        _, filename = tempfile.mkstemp()
        tmphandle = open(filename, 'w')
        shutil.copyfileobj(file, tmphandle)
        tmphandle.close()
        if closeafter:
            file.close()
        deleteafter = True
    else:
        filename = file
        deleteafter = False

    image = cvLoadImage(filename)
    grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)
    cvCvtColor(image, grayscale, CV_BGR2GRAY)

    storage = cvCreateMemStorage(0)
    cvClearMemStorage(storage)
    cvEqualizeHist(grayscale, grayscale)

    cascade = cvLoadHaarClassifierCascade(
        '/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml',
        cvSize(1,1))

    faces = cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2,
                                CV_HAAR_DO_CANNY_PRUNING, cvSize(50,50))
    if deleteafter:
        os.unlink(filename)

    return (image.width, image.height), faces
def detectObject(image):
    grayscale = cv.cvCreateImage(size, 8, 1)
    cv.cvFlip(image, None, 1)
    cv.cvCvtColor(image, grayscale, cv.CV_BGR2GRAY)
    storage = cv.cvCreateMemStorage(0)
    cv.cvClearMemStorage(storage)
    cv.cvEqualizeHist(grayscale, grayscale)
    cascade = cv.cvLoadHaarClassifierCascade(haar_file, cv.cvSize(1, 1))
    objects = cv.cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2,
                                     cv.CV_HAAR_DO_CANNY_PRUNING,
                                     cv.cvSize(100, 100))

    # Draw dots where hands are
    if objects:
        for i in objects:
            #cv.cvRectangle(image, cv.cvPoint( int(i.x), int(i.y)),
            #               cv.cvPoint(int(i.x+i.width), int(i.y+i.height)),
            #               cv.CV_RGB(0,255,0), 3, 8, 0)
            center = cv.cvPoint(int(i.x + i.width / 2),
                                int(i.y + i.height / 2))
            cv.cvCircle(image, center, 10, cv.CV_RGB(0, 0, 0), 5, 8, 0)
            # Left side check
            if center.x > box_forward_left[
                    0].x and center.x < box_backwards_left[
                        1].x and center.y > box_forward_left[
                            0].y and center.y < box_backwards_left[1].y:
                set_speed('left', center)
            # Right side check
            if center.x > box_forward_right[
                    0].x and center.x < box_backwards_right[
                        1].x and center.y > box_forward_right[
                            0].y and center.y < box_backwards_right[1].y:
                set_speed('right', center)
Example #6
0
def detect(image, cascade_file='haarcascade_data/haarcascade_frontalface_alt.xml'):
    image_size = cv.cvGetSize(image)

    # create grayscale version
    grayscale = cv.cvCreateImage(image_size, 8, 1)
    cv.cvCvtColor(image, grayscale, cv.CV_BGR2GRAY)

    # create storage
    storage = cv.cvCreateMemStorage(0)
    cv.cvClearMemStorage(storage)

    # equalize histogram
    cv.cvEqualizeHist(grayscale, grayscale)

    # detect objects
    cascade = cv.cvLoadHaarClassifierCascade(cascade_file, cv.cvSize(1,1))
    faces = cv.cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING, cv.cvSize(50, 50))

    positions = []
    if faces:
        for i in faces:
            positions.append({'x': i.x, 'y': i.y, 'width': i.width, 'height':
                i.height,})
            cv.cvRectangle(image, cv.cvPoint( int(i.x), int(i.y)),
                         cv.cvPoint(int(i.x + i.width), int(i.y + i.height)),
                         cv.CV_RGB(0, 255, 0), 3, 8, 0)
    return positions
Example #7
0
	def __init__(self, *args):
		apply(QWidget.__init__,(self, ) + args)
		self.cascade_name						= 'haarcascades/haarcascade_frontalface_alt.xml'
		self.cascade							= cv.cvLoadHaarClassifierCascade(self.cascade_name, cv.cvSize(20,20))
		self.cap								= highgui.cvCreateCameraCapture(0)
		self.q_buffer							= QImage()
		self.q_buffer.create(self.width(),self.height(),8)
		self.timer								= self.startTimer(1)
Example #8
0
 def __init__(self, *args):
     apply(QWidget.__init__, (self, ) + args)
     self.cascade_name = 'haarcascades/haarcascade_frontalface_alt.xml'
     self.cascade = cv.cvLoadHaarClassifierCascade(self.cascade_name,
                                                   cv.cvSize(20, 20))
     self.cap = highgui.cvCreateCameraCapture(0)
     self.q_buffer = QImage()
     self.q_buffer.create(self.width(), self.height(), 8)
     self.timer = self.startTimer(1)
Example #9
0
def _detect(image):
    """ Detects faces on `image`
    Parameters:
        @image: image file path

    Returns:
        [((x1, y1), (x2, y2)), ...] List of coordenates for top-left
                                    and bottom-right corner
    """
    # the OpenCV API says this function is obsolete, but we can't
    # cast the output of cvLoad to a HaarClassifierCascade, so use
    # this anyways the size parameter is ignored
    capture = cvCreateFileCapture(image) 

    if not capture:
        return []

    frame = cvQueryFrame(capture)
    if not frame:
        return []

    img = cvCreateImage(cvSize(frame.width, frame.height),
                        IPL_DEPTH_8U, frame.nChannels)
    cvCopy(frame, img)

    # allocate temporary images
    gray          = cvCreateImage((img.width, img.height),
                                  COPY_DEPTH, COPY_CHANNELS)
    width, height = (cvRound(img.width / IMAGE_SCALE),
                     cvRound(img.height / IMAGE_SCALE))
    small_img     = cvCreateImage((width, height), COPY_DEPTH, COPY_CHANNELS)

    # convert color input image to grayscale
    cvCvtColor(img, gray, CV_BGR2GRAY)

    # scale input image for faster processing
    cvResize(gray, small_img, CV_INTER_LINEAR)
    cvEqualizeHist(small_img, small_img)
    cvClearMemStorage(STORAGE)

    coords = []
    for haar_file in CASCADES:
        cascade = cvLoadHaarClassifierCascade(haar_file, cvSize(1, 1))
        if cascade:
            faces = cvHaarDetectObjects(small_img, cascade, STORAGE, HAAR_SCALE,
                                        MIN_NEIGHBORS, HAAR_FLAGS, MIN_SIZE) or []
            for face_rect in faces:
                # the input to cvHaarDetectObjects was resized, so scale the 
                # bounding box of each face and convert it to two CvPoints
                x, y = face_rect.x, face_rect.y
                pt1 = (int(x * IMAGE_SCALE), int(y * IMAGE_SCALE))
                pt2 = (int((x + face_rect.width) * IMAGE_SCALE),
                       int((y + face_rect.height) * IMAGE_SCALE))
                coords.append((pt1, pt2))
    return coords
Example #10
0
def _detect(image):
    """ Detects faces on `image`
    Parameters:
        @image: image file path

    Returns:
        [((x1, y1), (x2, y2)), ...] List of coordenates for top-left
                                    and bottom-right corner
    """
    # the OpenCV API says this function is obsolete, but we can't
    # cast the output of cvLoad to a HaarClassifierCascade, so use
    # this anyways the size parameter is ignored
    capture = cvCreateFileCapture(image)

    if not capture:
        return []

    frame = cvQueryFrame(capture)
    if not frame:
        return []

    img = cvCreateImage(cvSize(frame.width, frame.height), IPL_DEPTH_8U,
                        frame.nChannels)
    cvCopy(frame, img)

    # allocate temporary images
    gray = cvCreateImage((img.width, img.height), COPY_DEPTH, COPY_CHANNELS)
    width, height = (cvRound(img.width / IMAGE_SCALE),
                     cvRound(img.height / IMAGE_SCALE))
    small_img = cvCreateImage((width, height), COPY_DEPTH, COPY_CHANNELS)

    # convert color input image to grayscale
    cvCvtColor(img, gray, CV_BGR2GRAY)

    # scale input image for faster processing
    cvResize(gray, small_img, CV_INTER_LINEAR)
    cvEqualizeHist(small_img, small_img)
    cvClearMemStorage(STORAGE)

    coords = []
    for haar_file in CASCADES:
        cascade = cvLoadHaarClassifierCascade(haar_file, cvSize(1, 1))
        if cascade:
            faces = cvHaarDetectObjects(small_img, cascade, STORAGE,
                                        HAAR_SCALE, MIN_NEIGHBORS, HAAR_FLAGS,
                                        MIN_SIZE) or []
            for face_rect in faces:
                # the input to cvHaarDetectObjects was resized, so scale the
                # bounding box of each face and convert it to two CvPoints
                x, y = face_rect.x, face_rect.y
                pt1 = (int(x * IMAGE_SCALE), int(y * IMAGE_SCALE))
                pt2 = (int((x + face_rect.width) * IMAGE_SCALE),
                       int((y + face_rect.height) * IMAGE_SCALE))
                coords.append((pt1, pt2))
    return coords
Example #11
0
def detect_faces_on(path):
    faces = []
    image = cvLoadImage(path)
    # convert to grayscale for faster results
    grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)
    cvCvtColor(image, grayscale, CV_BGR2GRAY)
    # smooth picture for better results
    cvSmooth(grayscale, grayscale, CV_GAUSSIAN, 3, 3)

    storage = cvCreateMemStorage(0)
    cvClearMemStorage(storage)
    cvEqualizeHist(grayscale, grayscale)

    cascade_files = [
        # ('/usr/share/opencv/haarcascades/haarcascade_eye_tree_eyeglasses.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_lowerbody.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_mcs_mouth.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_profileface.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_eye.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_mcs_eyepair_big.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_mcs_nose.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_righteye_2splits.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_fullbody.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_mcs_eyepair_small.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_mcs_righteye.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_upperbody.xml', (50, 50)),
        ('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt_tree.xml',
         (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_lefteye_2splits.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_mcs_lefteye.xml', (50, 50)),
        # ('/usr/share/opencv/haarcascades/haarcascade_mcs_upperbody.xml', (50, 50)),
        # ('parojos_22_5.1.xml', (22, 5)),
        # ('Mouth.xml', (22, 15)),
    ]

    for cascade_file, cascade_sizes in cascade_files:
        cascade = cvLoadHaarClassifierCascade(os.path.join(cascade_file),
                                              cvSize(1, 1))
        faces += cvHaarDetectObjects(grayscale, cascade, storage, HAAR_SCALE,
                                     HAAR_NEIGHBORS, CV_HAAR_DO_CANNY_PRUNING,
                                     cvSize(*cascade_sizes))

    return [{'x': f.x, 'y': f.y, 'w': f.width, 'h': f.height} for f in faces]
Example #12
0
def detect_faces(image):
    """Converts an image to grayscale and prints the locations of any
         faces found"""
    grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)
    cvCvtColor(image, grayscale, CV_BGR2GRAY)

    storage = cvCreateMemStorage(0)
    cvClearMemStorage(storage)
    cvEqualizeHist(grayscale, grayscale)

    # The default parameters (scale_factor=1.1, min_neighbors=3,
    # flags=0) are tuned for accurate yet slow face detection. For
    # faster face detection on real video images the better settings are
    # (scale_factor=1.2, min_neighbors=2, flags=CV_HAAR_DO_CANNY_PRUNING).
    # --- http://www710.univ-lyon1.fr/~bouakaz/OpenCV-0.9.5/docs/ref/OpenCVRef_Experimental.htm#decl_cvHaarDetectObjects
    # The size box is of the *minimum* detectable object size. Smaller box = more processing time. - http://cell.fixstars.com/opencv/index.php/Facedetect
    minsize = (int(MINFACEWIDTH_PERCENT * image.width + 0.5),
               int(MINFACEHEIGHT_PERCENT * image.height))
    print >> sys.stderr, "Min size of face: %s" % ` minsize `

    faces = []
    for cascadefile in [
            '/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml'
    ]:
        #    for cascadefile in ['/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml', '/usr/share/opencv/haarcascades/haarcascade_profileface.xml']:
        cascade = cvLoadHaarClassifierCascade(cascadefile, cvSize(1, 1))
        #        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(50,50))
        #        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.1, 3, 0, cvSize(MINFACEWIDTH,MINFACEHEIGHT))
        #        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.1, 3, 0, cvSize(MINFACEWIDTH,MINFACEHEIGHT))
        #        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize(*minsize))
        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.1,
                                     4, CV_HAAR_DO_CANNY_PRUNING,
                                     cvSize(*minsize))


#        faces += cvHaarDetectObjects(grayscale, cascade, storage, scale_factor=1.1, min_neighbors=3, flags=0, cvSize(50,50))

#    print dir(faces)
    bboxes = []
    if faces:
        for f in faces:
            print >> sys.stderr, "\tFace at [(%d,%d) -> (%d,%d)]" % (
                f.x, f.y, f.x + f.width, f.y + f.height)
        bboxes = [Face(f.x, f.y, f.x + f.width, f.y + f.height) for f in faces]
    return bboxes
Example #13
0
def detectObjects(image):
    """Converts an image to grayscale and prints the locations of any
    faces found"""
    size = cv.cvSize(image.width, image.height)
    grayscale =  cv.cvCreateImage(size, 8, 1)
    cv.cvCvtColor(image, grayscale,  cv.CV_BGR2GRAY)
    


    storage =  cv.cvCreateMemStorage(0)         
    cv.cvClearMemStorage(storage)              
    cv.cvEqualizeHist(grayscale, grayscale)    
    cascade = cv.cvLoadHaarClassifierCascade(PATH, cv.cvSize(1,1))     
    faces = cv.cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING, cv.cvSize(30,30))

    if faces:
        for f in faces:
            print("[(%d,%d) -> (%d,%d)]" % (f.x, f.y, f.x+f.width, f.y+f.height))
Example #14
0
def detect_faces_on(path):
    faces = []
    image = cvLoadImage(path)
    # convert to grayscale for faster results
    grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)
    cvCvtColor(image, grayscale, CV_BGR2GRAY)
    # smooth picture for better results
    cvSmooth(grayscale, grayscale, CV_GAUSSIAN, 3, 3)

    storage = cvCreateMemStorage(0)
    cvClearMemStorage(storage)
    cvEqualizeHist(grayscale, grayscale)

    cascade_files = [
                     # ('/usr/share/opencv/haarcascades/haarcascade_eye_tree_eyeglasses.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_lowerbody.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_mcs_mouth.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_profileface.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_eye.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_mcs_eyepair_big.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_mcs_nose.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_righteye_2splits.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_fullbody.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_mcs_eyepair_small.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_mcs_righteye.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_upperbody.xml', (50, 50)),
                     ('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt_tree.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_lefteye_2splits.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_mcs_lefteye.xml', (50, 50)),
                     # ('/usr/share/opencv/haarcascades/haarcascade_mcs_upperbody.xml', (50, 50)),
                     # ('parojos_22_5.1.xml', (22, 5)),
                     # ('Mouth.xml', (22, 15)),
                    ]

    for cascade_file, cascade_sizes in cascade_files:
        cascade = cvLoadHaarClassifierCascade(os.path.join(cascade_file), cvSize(1, 1))
        faces += cvHaarDetectObjects(grayscale, cascade, storage, HAAR_SCALE, HAAR_NEIGHBORS, CV_HAAR_DO_CANNY_PRUNING, cvSize(*cascade_sizes))

    return [{'x': f.x, 'y': f.y, 'w': f.width, 'h': f.height} for f in faces]
Example #15
0
def detect(image):
	image_size = cv.cvGetSize(image)
 
	# create grayscale version
	grayscale = cv.cvCreateImage(image_size, 8, 1)
	cv.cvCvtColor(image, grayscale, opencv.CV_BGR2GRAY)
 
	# create storage
	storage = cv.cvCreateMemStorage(0)
	cv.cvClearMemStorage(storage)
 
	# equalize histogram
	cv.cvEqualizeHist(grayscale, grayscale)
 
	# detect objects
	cascade = cv.cvLoadHaarClassifierCascade('haarcascade_frontalface_alt.xml', cv.cvSize(1,1))
	faces = cv.cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2, opencv.CV_HAAR_DO_CANNY_PRUNING, cv.cvSize(100, 100))
 
	if faces:
		for i in faces:
			r = image[int(i.y):int(i.y+i.height),int(i.x):int(i.x+i.width)]
			cv.cvSmooth(r,r,cv.CV_BLUR,51,51)
Example #16
0
def detect_faces(image):
    """Converts an image to grayscale and prints the locations of any
         faces found"""
    grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)
    cvCvtColor(image, grayscale, CV_BGR2GRAY)

    storage = cvCreateMemStorage(0)
    cvClearMemStorage(storage)
    cvEqualizeHist(grayscale, grayscale)

    # The default parameters (scale_factor=1.1, min_neighbors=3,
    # flags=0) are tuned for accurate yet slow face detection. For
    # faster face detection on real video images the better settings are
    # (scale_factor=1.2, min_neighbors=2, flags=CV_HAAR_DO_CANNY_PRUNING).
    # --- http://www710.univ-lyon1.fr/~bouakaz/OpenCV-0.9.5/docs/ref/OpenCVRef_Experimental.htm#decl_cvHaarDetectObjects
    # The size box is of the *minimum* detectable object size. Smaller box = more processing time. - http://cell.fixstars.com/opencv/index.php/Facedetect
    minsize = (int(MINFACEWIDTH_PERCENT*image.width+0.5),int(MINFACEHEIGHT_PERCENT*image.height))
    print >> sys.stderr, "Min size of face: %s" % `minsize`

    faces = []
    for cascadefile in ['/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml']:
#    for cascadefile in ['/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml', '/usr/share/opencv/haarcascades/haarcascade_profileface.xml']:
        cascade = cvLoadHaarClassifierCascade(cascadefile, cvSize(1,1))
#        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(50,50))
#        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.1, 3, 0, cvSize(MINFACEWIDTH,MINFACEHEIGHT))
#        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.1, 3, 0, cvSize(MINFACEWIDTH,MINFACEHEIGHT))
#        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize(*minsize))
        faces += cvHaarDetectObjects(grayscale, cascade, storage, 1.1, 4, CV_HAAR_DO_CANNY_PRUNING, cvSize(*minsize))
#        faces += cvHaarDetectObjects(grayscale, cascade, storage, scale_factor=1.1, min_neighbors=3, flags=0, cvSize(50,50))

#    print dir(faces)
    bboxes = []
    if faces:
        for f in faces:
            print >> sys.stderr, "\tFace at [(%d,%d) -> (%d,%d)]" % (f.x, f.y, f.x+f.width, f.y+f.height)
        bboxes = [Face(f.x, f.y, f.x+f.width, f.y+f.height) for f in faces]
    return bboxes
Example #17
0
 def get_cascade(self, cascade_name):
   self._cached_cascades[cascade_name] = opencv.cvLoadHaarClassifierCascade(
           os.path.join(self.cascade_dir, cascade_name), opencv.cvSize(1,1))
           #cascade_name, opencv.cvSize(1,1))
   return self._cached_cascades[cascade_name]
Example #18
0
import pygame
import Image
from pygame.locals import *
import sys

from opencv import cv as opencv
# Magic class with a method for grabbing images
from opencv import highgui

from opencv import Ipl2PIL

camera = highgui.cvCreateCameraCapture(-1)
cascade = opencv.cvLoadHaarClassifierCascade('haarcascade_hand_fist.xml', opencv.cvSize(1,1))
eye_cascade = opencv.cvLoadHaarClassifierCascade('/usr/local/share/opencv/haarcascades/haarcascade_mcs_mouth.xml', opencv.cvSize(1,1))

def get_image():
    im = highgui.cvQueryFrame(camera)
    detect(im)
    #convert Ipl image to PIL image
    return Ipl2PIL(im)

def draw_bounding_boxes(cascade_list, img, r,g,b, width):
    if cascade_list:
        for rect in cascade_list:
            opencv.cvRectangle(img, opencv.cvPoint( int(rect.x), int(rect.y)),
                         opencv.cvPoint(int(rect.x + rect.width), int(rect.y + rect.height)),
                         opencv.CV_RGB(r,g,b), width)

def detect(image):
    image_size = opencv.cvGetSize(image)