def _compute_similarity_matrix()

in cvat-serverless/functions/endpoints/openvino_reidentification.py [0:0]


def _compute_similarity_matrix(image0, boxes0, image1, boxes1,
    distance):
    def _int(number, upper):
        return math.floor(numpy.clip(number, 0, upper - 1))

    DISTANCE_INF = 1000.0

    matrix = numpy.full([len(boxes0), len(boxes1)], DISTANCE_INF, dtype=float)
    for row, box0 in enumerate(boxes0):
        w0, h0 = image0.size
        xtl0, xbr0, ytl0, ybr0 = (
            _int(box0["points"][0], w0), _int(box0["points"][2], w0),
            _int(box0["points"][1], h0), _int(box0["points"][3], h0)
        )

        for col, box1 in enumerate(boxes1):
            w1, h1 = image1.size
            xtl1, xbr1, ytl1, ybr1 = (
                _int(box1["points"][0], w1), _int(box1["points"][2], w1),
                _int(box1["points"][1], h1), _int(box1["points"][3], h1)
            )

            if not _match_boxes(box0, box1, distance):
                continue

            crop0 = image0.crop((xtl0, ytl0, xbr0, ybr0))
            crop1 = image1.crop((xtl1, ytl1, xbr1, ybr1))
            matrix[row][col] = _match_crops(crop0, crop1)

    return matrix