# Copyright 2021 Huawei Technologies Co., Ltd

#

# Licensed under the BSD 3-Clause License  (the "License");

# you may not use this file except in compliance with the License.

# You may obtain a copy of the License at

#

# https://opensource.org/licenses/BSD-3-Clause

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.



import numpy as np





def ioa_with_anchors(anchors_min, anchors_max, box_min, box_max):

    # calculate the overlap proportion between the anchor and all bbox for supervise signal,

    # the length of the anchor is 0.01

    len_anchors = anchors_max - anchors_min

    int_xmin = np.maximum(anchors_min, box_min)

    int_xmax = np.minimum(anchors_max, box_max)

    inter_len = np.maximum(int_xmax - int_xmin, 0.)

    scores = np.divide(inter_len, len_anchors)

    return scores





def iou_with_anchors(anchors_min, anchors_max, box_min, box_max):

    """Compute jaccard score between a box and the anchors.

    """

    len_anchors = anchors_max - anchors_min

    int_xmin = np.maximum(anchors_min, box_min)

    int_xmax = np.minimum(anchors_max, box_max)

    inter_len = np.maximum(int_xmax - int_xmin, 0.)

    union_len = len_anchors - inter_len + box_max - box_min

    # print inter_len,union_len

    jaccard = np.divide(inter_len, union_len)

    return jaccard