예제 #1
0
    def _get_rect_tensor_descs_no_overlap(self, rect, window_rect, factor):
        assert isinstance(rect, Rect)
        assert isinstance(window_rect, Rect)

        window_size = window_rect.height()
        map_size = window_size >> (factor + self.num_poolings)

        edge = window_size / map_size

        center = rect.center()
        sx = int(center.x - window_rect.left)
        sy = int(center.y - window_rect.top)
        x = int(sx / edge)
        y = int(sy / edge)

        res = []

        for dx in range(-3, 3):
            for dy in range(-2, 2):
                wx = x + dx
                wy = y + dy
                if 0 <= wx and wx < map_size and 0 <= wy and wy < map_size:
                    # window coord
                    wrect = Rect(wx * edge, wy * edge, (wx + 1) * edge, (wy + 1) * edge)
                    # img coord
                    wrect.move(window_rect.top, window_rect.left)

                    i = wrect.intersection(rect)

                    if i.valid(): #self._check_rect(rect, wrect):
                        # img coord
                        #i = wrect.intersection(rect)
                        qual_out = i.area() / float(wrect.area())
                        # if qual_out <= 0:
                        #     print rect ,wrect, i
                        # window coord
                        i.move(-wrect.top, -wrect.left)
                        # window 0..1 coord
                        i.stretch(1.0 / wrect.height(), 1.0 / wrect.width())

                        if qual_out > 0.01:
                            res.append((wy, wx, i.left, i.top, i.right, i.bottom, qual_out))

        return res