Example #1
0
    def apply(self, face, patch_size=20, num_patches=50, visualize=False):

        patcher = Patcher(patch_size)
        patches = patcher.generate_patches(face, num_patches)

        if visualize:
            for patch in patches:
                cv2.rectangle(face,(patch[0][0],patch[0][1]),(patch[1][0],patch[1][1]),(255,0,0),1)

            cv2.imshow('img',face)
            cv2.waitKey(1500)
            cv2.destroyAllWindows()

        keypoints = np.array([])

        for i in range(patches.shape[0]):
            node = self.nodes[0]
            while not node.is_leaf:
                bt = binary_test(patches[i], face, node.params)
                #   If 0, go left, if 1 go right
                node = node.children[int(bt)]

            if keypoints.shape[0] == 0:
                keypoints = centroid(patches[i])+node.prob_dist[0]
            else:
                keypoints += centroid(patches[i])+node.prob_dist[0]

        keypoints /= patches.shape[0]
        return keypoints
Example #2
0
    def load_data_provider(self, data, patch_size=20, num_patches=50, num_params=20):
        self.data = data

        patcher = Patcher(patch_size)
        
        self.patches = np.array([])
        self.offsets = np.array([])
        self.indexes = np.array([])

        #   Extract patches and offsets from data provided.
        #   TODO: Restrict patch extraction to face bounding box

        for i, (image, eyes, keypoints, face, face_bbox, rkeypoints) in enumerate(self.data):
            patches = patcher.generate_patches(face, num_patches)
            offsets = patcher.calculate_offsets_from_patches(patches, rkeypoints)
            indexes = np.ones(patches.shape[0],dtype="int")*i

            if not self.patches.size:
                self.patches = patches
                self.offsets = offsets
                self.indexes = indexes
            else:
                self.patches = np.concatenate((self.patches, patches),axis=0)
                self.offsets = np.concatenate((self.offsets, offsets),axis=0)
                self.indexes = np.concatenate((self.indexes, indexes),axis=0)

        self.params_list = patcher.generate_parameters(num_params)