def testDetectFacesAndCreateFiles(self): ''' Go through two images, the first with 1 face, the second with 4 faces Assert that the detected faces are correct, and draw them. Also creates output images of the padded faces ''' fnames = ['./resources/cascade/janice2.jpg', './resources/cascade/albert4.jpg', './resources/cascade/albert5.jpg', './resources/cascade/david1.jpg'] for n_image in range(len(fnames)): fname = fnames[n_image] expected_result = expected_results[n_image] _, base_fname = os.path.split(fname) face_finder = CascadeFaceFinder(haar_file = '../resources/haarcascade_frontalface_default.xml', lbp_file = '../resources/lbpcascade_frontalface.xml') faces_file = face_finder.create_faces_file(fname, is_overwrite = True, target_file = './outputs/cascade/2/' + base_fname + '.faces.txt') # get the sub images sub_images = face_finder.get_sub_images_from_file(original_image_file = fname, faces_file = faces_file) for n_face, sub_image in enumerate(sub_images): cv2.imshow('face_%d' %n_face, sub_image) cv2.waitKey() # create sub images files sub_images_file = face_finder.create_sub_images_from_file(original_image_file = fname, faces_file = faces_file, target_folder = None) with open(faces_file,'r') as fid: for i in range(len(expected_result)): line = fid.readline()
def testDetectFacesAndCreateFiles(self): ''' Go through two images, the first with 1 face, the second with 4 faces Assert that the detected faces are correct, and draw them. Also creates output images of the padded faces ''' fnames = [ './resources/cascade/Fayssal_Mekdad_0002.jpg', './resources/cascade/family-home.png' ] expected_results = [ ['x,y,dx,dy,score,angle,type\n', '61,62,132,132,344,0.0,haar'], [ 'x,y,dx,dy,score,angle,type\n', '327,101,121,121,154,0.0,lbp\n', '237,106,113,113,139,0.0,lbp\n', '164,49,91,91,49,0.0,lbp\n', '434,86,94,94,95,0.0,lbp\n' ] ] for n_image in range(len(fnames)): fname = fnames[n_image] expected_result = expected_results[n_image] _, base_fname = os.path.split(fname) face_finder = CascadeFaceFinder( haar_file='../resources/haarcascade_frontalface_default.xml', lbp_file='../resources/lbpcascade_frontalface.xml') faces_file = face_finder.create_faces_file( fname, is_overwrite=True, target_file='./outputs/cascade/2/' + base_fname + '.faces.txt') # get the sub images sub_images = face_finder.get_sub_images_from_file( original_image_file=fname, faces_file=faces_file) for n_face, sub_image in enumerate(sub_images): cv2.imshow('face_%d' % n_face, sub_image) cv2.waitKey() # create sub images files sub_images_file = face_finder.create_sub_images_from_file( original_image_file=fname, faces_file=faces_file, target_folder=None) with open(faces_file, 'r') as fid: for i in range(len(expected_result)): line = fid.readline() self.assertEqual(line.strip(), expected_result[i].strip())
def testDetectFacesAndCreateFiles(self): ''' Go through two images, the first with 1 face, the second with 4 faces Assert that the detected faces are correct, and draw them. Also creates output images of the padded faces ''' fnames = ['./resources/cascade/Fayssal_Mekdad_0002.jpg', './resources/cascade/family-home.png'] expected_results = [['x,y,dx,dy,score,angle,type\n', '61,62,132,132,344,0.0,haar'], ['x,y,dx,dy,score,angle,type\n', '327,101,121,121,154,0.0,lbp\n', '237,106,113,113,139,0.0,lbp\n', '164,49,91,91,49,0.0,lbp\n', '434,86,94,94,95,0.0,lbp\n'] ] for n_image in range(len(fnames)): fname = fnames[n_image] expected_result = expected_results[n_image] _, base_fname = os.path.split(fname) face_finder = CascadeFaceFinder(haar_file = '../resources/haarcascade_frontalface_default.xml', lbp_file = '../resources/lbpcascade_frontalface.xml') faces_file = face_finder.create_faces_file(fname, is_overwrite = True, target_file = './outputs/cascade/2/' + base_fname + '.faces.txt') # get the sub images sub_images = face_finder.get_sub_images_from_file(original_image_file = fname, faces_file = faces_file) for n_face, sub_image in enumerate(sub_images): cv2.imshow('face_%d' %n_face, sub_image) cv2.waitKey() # create sub images files sub_images_file = face_finder.create_sub_images_from_file(original_image_file = fname, faces_file = faces_file, target_folder = None) with open(faces_file,'r') as fid: for i in range(len(expected_result)): line = fid.readline() self.assertEqual(line.strip(), expected_result[i].strip())