Exemplo n.º 1
0
    def makeClusterBack(self, isInterrupt):
        '''
        brief: make the clustering result
        :param isInterrupt: the running elapsed of per frame is exceed or not
        :return: back, the clustering mask
                area, the clustering area percentage
        '''
        back, circles = np.zeros((self.h, self.w), dtype=np.uint8), []
        for i, rect in enumerate(self.hisrects):
            if self.ovlcount[i] < self.retainov:
                continue

            ismerge, (xi, yi, wi, hi) = False, rect
            centeri, radiusi = (int(xi+wi/2), int(yi+hi/2)), int((wi+hi)/4)

            for j, (centerj, radiusj) in enumerate(circles):
                thresr = 1.25 * (radiusi + radiusj)
                if util.distance(centeri, centerj) < thresr:
                    ismerge = True
                    cv2.line(back, centeri, centerj, 255, int(thresr))

            if not ismerge:
                circles.append([centeri, radiusi])

        backrs, backsize = cv2.resize(back, (int(self.w/8), int(self.h/8))), self.w * self.h / 64
        area = 1.0 if isInterrupt else (len(np.argwhere(backrs > 8)) / backsize)
        return (cv2.merge([cv2.Sobel(back, cv2.CV_8UC1, 1, 1)] * 3), area)
Exemplo n.º 2
0
    def distance_table(self, data_table, cols, d_function):

        data_table[cols] = data_table.loc[:, cols].astype('float32')

        return pd.DataFrame(scipy.spatial.distance.squareform(
            util.distance(data_table.loc[:, cols], d_function)),
                            columns=data_table.index,
                            index=data_table.index).astype('float32')
Exemplo n.º 3
0
    def create_distance_table(data_table: pd.DataFrame, cols: List[str],
                              d_function: str) -> pd.DataFrame:
        """
        Create distance table between rows in the data table. Only cols are considered and the specified  distance
        function is used to compute the distance .

        :param data_table: DataFrame to calculate distance matrix for.
        :param cols: Cols to use for calculating distance between rows.
        :param d_function: Distance function to use for calculation. By now only euclidean is supported.
        :return: NxN matrix with distance from each point to each where N is the number of rows.
        """

        data_table[cols] = data_table.loc[:, cols].astype('float32')
        print(
            'Calculating distance matrix, this may take a while and your computer may be slower.'
        )
        return pd.DataFrame(scipy.spatial.distance.squareform(
            util.distance(data_table.loc[:, cols], d_function)),
                            columns=data_table.index,
                            index=data_table.index).astype('float32')
Exemplo n.º 4
0
 def distance_table(self, data_table, cols, d_function):
     return pd.DataFrame(scipy.spatial.distance.squareform(
         util.distance(data_table.ix[:, cols], d_function)),
                         columns=data_table.index,
                         index=data_table.index)