Example #1
0
    def __init__(self,
                 weights_1st_stage,
                 scale_space_sizes_idxs,
                 num_win_psz=130,
                 edge=EDGE,
                 base_log=BASE_LOG,
                 min_edge_log=MIN_EDGE_LOG,
                 edge_log_range=EDGE_LOG_RANGE):

        self.filter_tig = FilterTIG()
        self.weights_1st_stage = weights_1st_stage
        self.filter_tig.update(self.weights_1st_stage)
        self.filter_tig.reconstruct(self.weights_1st_stage)
        self.scale_space_sizes_idxs = scale_space_sizes_idxs
        self.base_log = base_log
        self.min_edge_log = min_edge_log
        self.edge_log_range = edge_log_range
        self.edge = edge
        self.num_win_psz = num_win_psz
Example #2
0
 def __init__(self, weights_1st_stage, scale_space_sizes_idxs, num_win_psz = 130, edge = EDGE, base_log = BASE_LOG, min_edge_log = MIN_EDGE_LOG, edge_log_range = EDGE_LOG_RANGE):
     
     self.filter_tig = FilterTIG()
     self.weights_1st_stage = weights_1st_stage
     self.filter_tig.update(self.weights_1st_stage)
     self.filter_tig.reconstruct(self.weights_1st_stage) 
     self.scale_space_sizes_idxs = scale_space_sizes_idxs
     self.base_log = base_log
     self.min_edge_log = min_edge_log   
     self.edge_log_range = edge_log_range 
     self.edge = edge
     self.num_win_psz = num_win_psz
Example #3
0
class FirstStagePrediction(object):
    def __init__(self,
                 weights_1st_stage,
                 scale_space_sizes_idxs,
                 num_win_psz=130,
                 edge=EDGE,
                 base_log=BASE_LOG,
                 min_edge_log=MIN_EDGE_LOG,
                 edge_log_range=EDGE_LOG_RANGE):

        self.filter_tig = FilterTIG()
        self.weights_1st_stage = weights_1st_stage
        self.filter_tig.update(self.weights_1st_stage)
        self.filter_tig.reconstruct(self.weights_1st_stage)
        self.scale_space_sizes_idxs = scale_space_sizes_idxs
        self.base_log = base_log
        self.min_edge_log = min_edge_log
        self.edge_log_range = edge_log_range
        self.edge = edge
        self.num_win_psz = num_win_psz

    def predict(self, image, nss=2):

        bbs = []
        img_h, img_w, nch = image.shape
        for size_idx in self.scale_space_sizes_idxs:
            w = round(
                pow(self.base_log,
                    size_idx % self.edge_log_range + self.min_edge_log))
            h = round(
                pow(self.base_log,
                    size_idx // self.edge_log_range + self.min_edge_log))
            if (h > img_h * self.base_log) or (w > img_w * self.base_log):
                continue
            h = min(h, img_h)
            w = min(w, img_w)
            new_w = int(round(float(self.edge) * img_w / w))
            new_h = int(round(float(self.edge) * img_h / h))
            img_resized = cv2.resize(image, (new_w, new_h))
            grad = rgb_gradient(img_resized)
            match_map = self.filter_tig.match_template(grad)
            points = self.filter_tig.non_maxima_suppression(
                match_map, nss, self.num_win_psz, False)
            ratio_x = w / self.edge
            ratio_y = h / self.edge
            i_max = min(len(points), self.num_win_psz)
            for i in xrange(i_max):
                point, score = points[i]
                x0 = int(round(point[0] * ratio_x))
                y0 = int(round(point[1] * ratio_y))
                x1 = min(img_w, int(x0 + w))
                y1 = min(img_h, int(y0 + h))
                x0 = x0 + 1
                y0 = y0 + 1
                bbs.append(((x0, y0, x1, y1), score, size_idx))
        return bbs
Example #4
0
class FirstStagePrediction(object):
    def __init__(
        self,
        weights_1st_stage,
        scale_space_sizes_idxs,
        num_win_psz=130,
        edge=EDGE,
        base_log=BASE_LOG,
        min_edge_log=MIN_EDGE_LOG,
        edge_log_range=EDGE_LOG_RANGE,
    ):

        self.filter_tig = FilterTIG()
        self.weights_1st_stage = weights_1st_stage
        self.filter_tig.update(self.weights_1st_stage)
        self.filter_tig.reconstruct(self.weights_1st_stage)
        self.scale_space_sizes_idxs = scale_space_sizes_idxs
        self.base_log = base_log
        self.min_edge_log = min_edge_log
        self.edge_log_range = edge_log_range
        self.edge = edge
        self.num_win_psz = num_win_psz

    def predict(self, image, nss=2):

        bbs = []
        img_h, img_w, nch = image.shape
        for size_idx in self.scale_space_sizes_idxs:
            w = round(pow(self.base_log, size_idx % self.edge_log_range + self.min_edge_log))
            h = round(pow(self.base_log, size_idx // self.edge_log_range + self.min_edge_log))
            if (h > img_h * self.base_log) or (w > img_w * self.base_log):
                continue
            h = min(h, img_h)
            w = min(w, img_w)
            new_w = int(round(float(self.edge) * img_w / w))
            new_h = int(round(float(self.edge) * img_h / h))
            img_resized = cv2.resize(image, (new_w, new_h))
            grad = rgb_gradient(img_resized)
            match_map = self.filter_tig.match_template(grad)
            points = self.filter_tig.non_maxima_suppression(match_map, nss, self.num_win_psz, False)
            ratio_x = w / self.edge
            ratio_y = h / self.edge
            i_max = min(len(points), self.num_win_psz)
            for i in xrange(i_max):
                point, score = points[i]
                x0 = int(round(point[0] * ratio_x))
                y0 = int(round(point[1] * ratio_y))
                x1 = min(img_w, int(x0 + w))
                y1 = min(img_h, int(y0 + h))
                x0 = x0 + 1
                y0 = y0 + 1
                bbs.append(((x0, y0, x1, y1), score, size_idx))
        return bbs