How to use Azure custom vision service response boundingBox to plot shape

后端 未结 1 677
無奈伤痛
無奈伤痛 2021-02-08 23:06

I am using Azure cognitive-service custom vision service to detect shapes from capture images. As per their documentation, I got the response as per their format.

But I

相关标签:
1条回答
  • 2021-02-08 23:42

    Reply / TL;DR

    These boundingBox values are in percent of the image original size, so you can draw the rectangle by multiplying the values by the image width (for left and width values) or by the image height (for top and height values).

    Keep in mind that the position is expressed from the top left corner, so position 0,0 is this corner.

    Details with a sample

    I got a small custom vision detecting cola bottles.

    Original image is the following one:

    I used the Custom Vision portal to make a prediction and got the following result - let's focus on this highlighted result with a 87,5% score:

    Using the API (available here), I also made the Predict operation and got (among other details) this prediction:

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

    Considering that my image dimension is 800 x 652 (so ImageWidth 800, ImageHeight 652):

    Rectangle draw

    Top left point position?

    • x (vertical distance from the left border) = left value from API x ImageWidth => 0.453497916 x 800 = 362
    • y (horizontal distance from the top border) = top value from the API x ImageHeight => 0.0 x 652 = 0

    So my rectangle starting position is (362,0).

    Size?

    • Rectangle width = width from the API x ImageWidth => 201
    • Rectangle height = height from the API x ImageHeight => 569

    Let's draw it!

    Looks right!

    0 讨论(0)
提交回复
热议问题