Exemplo n.º 1
0
    def test_C_adjust_mask(self):
        '''
			Initial Mask on line 2 and column 4 of the Ardis(64,64)
			01
			01

			Adjust Mask with a Subwindow located in x=13(column) and y=16(line) in a double ardis (128,128)
			0011
			0011
			0011
			0011

			The result should be this 4x4 mask located at line 2*2+16=20 and column 2*4+13=21
		'''
        fmask_gen = MaskTwoHorizontalFactory((2, 2)).next().next()[0]
        fmask_gen = FeatureMask(fmask_gen.mask, (2, 4))

        sw = windowgen.Subwindow(13, 16, ce=2.0)
        fmask_gen.adjust_mask(sw)

        mask_to_match = np.array([[0, 0, 1, 1], [0, 0, 1, 1], [0, 0, 1, 1],
                                  [0, 0, 1, 1]])
        size_to_match = (4, 4)
        location_to_match = (20, 21)

        fmask_match = FeatureMask(Mask(size_to_match, None), location_to_match,
                                  mask_to_match)
        assert fmask_gen == fmask_match
Exemplo n.º 2
0
    def test_B_ii_consistency(self):
        k1 = "%s/%s" % (config.TEST_IMG_PATH, "kramer1.pgm")
        k2 = "%s/%s" % (config.TEST_IMG_PATH, "kramer2.pgm")

        ii_k1 = misc.IntegralImage(k1)
        ii_k2 = misc.IntegralImage(k2)

        fmask_k1 = MaskTwoHorizontalFactory((16, 16)).next().next()[0]
        fmask_k1 = FeatureMask(fmask_k1.mask, (0, 0))

        fmask_k2 = MaskTwoHorizontalFactory((16, 16)).next().next()[0]
        fmask_k2 = FeatureMask(fmask_k2.mask, (0, 0))

        sw_k1 = windowgen.Subwindow(80, 94)
        sw_k2 = windowgen.Subwindow(0, 0)

        fmask_k1.adjust_mask(sw_k1)
        fmask_k2.adjust_mask(sw_k2)

        assert ii_k1.filter(fmask_k1) == ii_k2.filter(fmask_k2)
Exemplo n.º 3
0
    def run(self):
        Experiment.run(self)
        # face_filenames = random.sample(os.listdir(config.FACES_PATH),self.n_img)
        face_filenames = os.listdir(config.FACES_PATH)[:self.n_img]

        sw = windowgen.Subwindow(0, 0, (64, 64))

        true = 0
        for i in face_filenames:
            img_path = "%s/%s" % (config.FACES_PATH, i)
            true = true + 1 if self.det.is_face(img_path, sw) else true

        print "%d/%d" % (true, self.n_img)

        true = 0
        for scene_window in windowgen.get_next_random_image_window(
                config.SCENES_PATH_VALIDATION, self.n_img):
            img_path = scene_window.window_img_path
            true = true + 1 if self.det.is_face(img_path, sw) else true

        print "%d/%d" % (true, self.n_img)

        self.stop()
Exemplo n.º 4
0
def init():

    folder_faces = "%s/lfwcrop_grey/faces" % (config.DATASET_PATH, )
    folder_scenes = "%s/training non-face images" % (config.DATASET_PATH, )
    n = 3500
    T = 100

    n_faces = n
    n_non_faces = n

    face_filenames = os.listdir(folder_faces)[:n]

    faces = []
    non_faces = []
    '''
		Create a FeatureMaster instance for each image face exemplar and puts the correspondent generator
		in the appropriated list. 
	'''
    FeatureMaster.init_training_set()
    fm = FeatureMaster((64, 64), 4, 4, 1.25, 8, 8)
    for face_file in face_filenames:
        img_path = "%s/%s" % (folder_faces, face_file)
        faces.append(img_path)
        fm.add_image(img_path, FeatureMaster.FACE)
    '''It does the same for the scene images'''
    for scene_window in windowgen.get_next_random_image_window(
            folder_scenes, n):
        img_path = scene_window.window_img_path
        non_faces.append(img_path)
        fm.add_image(img_path, FeatureMaster.NON_FACE)

    print "END STAGE 1"

    fc = FeatureChooser((64, 64), fm, n_faces, n_non_faces)
    classifier = fc.find_hypothesis(T)

    with open('%s/%s_%d_%d.pk' % (config.CLASSIFIERS_PATH, 'classifier', n, T),
              'wb') as output:
        pickle.dump(classifier, output, pickle.HIGHEST_PROTOCOL)

    print "END STAGE 2"
    print classifier.hypothesis

    #Creating the Detector
    ng = 1
    ref_ardis = (64, 64)
    ref_mask = (8, 8)

    shift_step = 4
    fn = windowgen.SubwindowGenerator.FIXED_FACTOR

    det = Detector(classifier, ng, ref_ardis, ref_mask, shift_step=shift_step)

    true = 0
    for i in range(0, n):
        sw = windowgen.Subwindow(0, 0, (64, 64))
        true = true + 1 if det.is_face(faces[i], sw) else true

    print "%d/%d" % (true, n)

    true = 0
    for i in range(0, n):
        sw = windowgen.Subwindow(0, 0, (64, 64))
        true = true + 1 if det.is_face(non_faces[i], sw) else true

    print "%d/%d" % (true, n)