【问题标题】:How to use Azure custom vision service response boundingBox to plot shape如何使用 Azure 自定义视觉服务响应 boundingBox 绘制形状
【发布时间】:2018-11-20 12:36:54
【问题描述】:

我正在使用 Azure 认知服务 custom vision service 从捕获的图像中检测形状。根据他们的文档,我按照他们的格式收到了回复。

但是在图像上方绘制形状是一个面临的问题。

{
    "id": "0fbda4ee-8956-4979-bf57-a252441af98d",
    "project": "9ca4032b-beeb-40ad-9396-1c3fcfd9ba89",
    "iteration": "27c85265-a158-4fc4-b22a-d535dd758d80",
    "created": "2018-06-11T09:34:29.9496528Z",
    "predictions": [
        {
            "probability": 0.0102891214,
            "tagId": "677afcf8-bc4a-493f-b588-707663286125",
            "tagName": "ball",
            "boundingBox": {
                "left": 0.2889924,
                "top": 0.0169312358,
                "width": 0.7007024,
                "height": 0.8284572
            }
        },
        {
            "probability": 0.012788726,
            "tagId": "ca844f08-b6c0-4d9a-9010-73945d442708",
            "tagName": "cricket ball",
            "boundingBox": {
                "left": 0.304018974,
                "top": 0.413163722,
                "width": 0.299461246,
                "height": 0.436399817
            }
        },
        {
            "probability": 0.0229086485,
            "tagId": "ca844f08-b6c0-4d9a-9010-73945d442708",
            "tagName": "cricket ball",
            "boundingBox": {
                "left": 0.2889924,
                "top": 0.0169312358,
                "width": 0.7007024,
                "height": 0.8284572
            }
        },
        {
            "probability": 0.0100123268,
            "tagId": "4672144d-5593-446f-be63-5144a35d0e6e",
            "tagName": "pipe",
            "boundingBox": {
                "left": 0.711509764,
                "top": 0.377838552,
                "width": 0.07217276,
                "height": 0.113578767
            }
        },
        {
            "probability": 0.0167990718,
            "tagId": "4672144d-5593-446f-be63-5144a35d0e6e",
            "tagName": "pipe",
            "boundingBox": {
                "left": 0.9821227,
                "top": 0.9500536,
                "width": 0.0115685463,
                "height": 0.033854425
            }
        },
        {
            "probability": 0.923659563,
            "tagId": "4672144d-5593-446f-be63-5144a35d0e6e",
            "tagName": "pipe",
            "boundingBox": {
                "left": 0.288039029,
                "top": 0.411838,
                "width": 0.291451037,
                "height": 0.4237842
            }
        }
    ]
}

以上是我在自定义视觉 API 调用中得到的响应。但问题在于boundingBox。它的值总是从 0 开始的分数。现在,如果我想使用它并想绘制​​一个正方形,那么这是不可能的,因为我不知道从该值绘制正方形/矩形背后的确切逻辑。

如何使用这些值并使用它绘制矩形/正方形?

【问题讨论】:

    标签: computer-vision microsoft-cognitive azure-cognitive-services


    【解决方案1】:

    回复/TL;DR

    这些 boundingBox 值是图像原始大小的百分比,因此您可以通过将这些值乘以图像宽度(对于左侧和宽度值)或图像高度(对于顶部和高度值)来绘制矩形。

    记住位置是从左上角开始表示的,所以位置0,0就是这个角。

    带有示例的详细信息

    我有一个小的定制视觉检测可乐瓶。

    原图如下:

    我使用自定义视觉门户进行预测并得到以下结果 - 让我们专注于这个得分为 87.5% 的突出显示结果:

    使用 API(here 可用),我还进行了预测操作并获得了(以及其他详细信息)这个预测:

    {
        "probability": 0.875464261,
        "tagId": "1932c95f-ed4a-4675-bde4-c2457e1389e6",
        "tagName": "CocaLight",
        "boundingBox": {
          "left": 0.453497916,
          "top": 0.0,
          "width": 0.2523211,
          "height": 0.8738168
        }
    }
    

    考虑到我的图像尺寸是 800 x 652(所以 ImageWidth 800,ImageHeight 652):

    矩形绘制

    左上点位置?

    • x(到左边框的垂直距离)= API x ImageWidth 的左值 => 0.453497916 x 800 = 362
    • y(距顶部边框的水平距离)= API x ImageHeight 的顶部值 => 0.0 x 652 = 0

    所以我的矩形起始位置是 (362,0)。

    尺寸?

    • 矩形宽度 = API x ImageWidth 的宽度 => 201
    • 矩形高度 = API x ImageHeight 的高度 => 569

    我们来画吧!

    看起来不错!

    【讨论】:

    • 很好解释。易于理解。我会尝试并让你知道。谢谢。
    • @Nicolas R 非常好的解释。我希望认知服务能够像这样更新他们的描述以绘制形状。非常好。非常感谢。我会试试看。
    猜你喜欢
    • 1970-01-01
    • 2022-11-21
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多