(self, pred, _bitmap, dest_width, dest_height)
return boxes, scores
_bitmap: single map with shape (H, W),
            whose values are binarized as {0, 1}
_bitmap: single map with shape (H, W),
            whose values are binarized as {0, 1}
_bitmap : single map with shape ( H W ) whose values are binarized as { 0 1 }
def polygons_from_bitmap(self, pred, _bitmap, dest_width, dest_height):
        '''
        _bitmap: single map with shape (H, W),
            whose values are binarized as {0, 1}
        '''

        assert len(_bitmap.shape) == 2
        bitmap = _bitmap.cpu().numpy()  # The first channel
        pred = pred.cpu().detach().numpy()
        height, width = bitmap.shape
        boxes = []
        scores = []

        contours, _ = cv2.findContours((bitmap * 255).astype(np.uint8), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

        for contour in contours[:self.max_candidates]:
            epsilon = 0.005 * cv2.arcLength(contour, True)
            approx = cv2.approxPolyDP(contour, epsilon, True)
            points = approx.reshape((-1, 2))
            if points.shape[0] < 4:
                continue
            # _, sside = self.get_mini_boxes(contour)
            # if sside < self.min_size:
            #     continue
            score = self.box_score_fast(pred, contour.squeeze(1))
            if self.box_thresh > score:
                continue

            if points.shape[0] > 2:
                box = self.unclip(points, unclip_ratio=self.unclip_ratio)
                if len(box) > 1:
                    continue
            else:
                continue
            box = box.reshape(-1, 2)
            _, sside = self.get_mini_boxes(box.reshape((-1, 1, 2)))
            if sside < self.min_size + 2:
                continue

            if not isinstance(dest_width, int):
                dest_width = dest_width.item()
                dest_height = dest_height.item()

            box[:, 0] = np.clip(np.round(box[:, 0] / width * dest_width), 0, dest_width)
            box[:, 1] = np.clip(np.round(box[:, 1] / height * dest_height), 0, dest_height)
            boxes.append(box)
            scores.append(score)
        return boxes, scores
def polygons_from_bitmap ( self , pred , _bitmap , dest_width , dest_height ) : assert len ( _bitmap . shape ) == 2 bitmap = _bitmap . cpu ( ) . numpy ( ) # The first channel pred = pred . cpu ( ) . detach ( ) . numpy ( ) height , width = bitmap . shape boxes = [ ] scores = [ ] contours , _ = cv2 . findContours ( ( bitmap * 255 ) . astype ( np . uint8 ) , cv2 . RETR_LIST , cv2 . CHAIN_APPROX_SIMPLE ) for contour in contours [ : self . max_candidates ] : epsilon = 0.005 * cv2 . arcLength ( contour , True ) approx = cv2 . approxPolyDP ( contour , epsilon , True ) points = approx . reshape ( ( - 1 , 2 ) ) if points . shape [ 0 ] < 4 : continue # _, sside = self.get_mini_boxes(contour) # if sside < self.min_size: #     continue score = self . box_score_fast ( pred , contour . squeeze ( 1 ) ) if self . box_thresh > score : continue if points . shape [ 0 ] > 2 : box = self . unclip ( points , unclip_ratio = self . unclip_ratio ) if len ( box ) > 1 : continue else : continue box = box . reshape ( - 1 , 2 ) _ , sside = self . get_mini_boxes ( box . reshape ( ( - 1 , 1 , 2 ) ) ) if sside < self . min_size + 2 : continue if not isinstance ( dest_width , int ) : dest_width = dest_width . item ( ) dest_height = dest_height . item ( ) box [ : , 0 ] = np . clip ( np . round ( box [ : , 0 ] / width * dest_width ) , 0 , dest_width ) box [ : , 1 ] = np . clip ( np . round ( box [ : , 1 ] / height * dest_height ) , 0 , dest_height ) boxes . append ( box ) scores . append ( score ) return boxes , scores