Пример #1
0
    def get_closest_label(self, sp):
        """
        find in label maps the label whose centroid is the closest to 
        """
        loc_compare = self.locs.loc[self.locs['frame'] == sp['frame']]
        if (loc_compare.shape[0] == 0):
            return None

        dists = [
            np.linalg.norm(np.array((sp['x'], sp['y'])) - np.array(r_compare))
            for r_compare in [(
                x, y) for x, y in zip(loc_compare['x'], loc_compare['y'])]
        ]
        loc_min = loc_compare.iloc[np.argmin(dists)]
        i_min, j_min = csv.coord2Pixel(loc_min['x'], loc_min['y'],
                                       self.shape[1], self.shape[0])
        return self.labels[sp['frame'], i_min, j_min]
Пример #2
0
    def is_entrance(self, loc_2d, idx=None):

        # idx is row index of gaze file, and also entrance masks

        i_gaze, j_gaze = csv.coord2Pixel(loc_2d['x'], loc_2d['y'],
                                         self.shape[1], self.shape[0])

        if (self.mask_path is not None):
            return self.masks[idx].astype(bool)[i_gaze, j_gaze]
        else:
            mask = np.zeros(self.shape, dtype=bool)
            rr, cc = circle(i_gaze,
                            j_gaze,
                            self.shape[0] * self.entrance_radius,
                            shape=self.shape)
            mask[rr, cc] = True
            return mask[i_gaze, j_gaze]
Пример #3
0
 def get_i_j(self, loc):
     i, j = csv.coord2Pixel(loc['x'], loc['y'], self.shape[1],
                            self.shape[0])
     return i, j