Converting bounding boxes from labels.json file to pixel values

Yves Guena 20 Reputation points
2024-01-30T18:09:36.4066667+00:00

How can I convert the bounding boxes from a labels.json file to pixel values? The file follows the schema at "https://schema.cognitiveservices.azure.com/formrecognizer/2021-03-01/labels.json". Here is an example bounding box from the file:

{
    "page": 1,
    "text": "1AJ",
    "boundingBoxes": [
        [
            0.6822429906542056,
            0.07027328499721137,
            0.6919951239333604,
            0.06748466257668712,
            0.6924014628199918,
            0.08087005019520357,
            0.6822429906542056,
            0.08198549916341327
        ]
    ]
}

I need to convert these bounding boxes to pixel values. Can you provide any guidance or resources on how to do this?

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,228 questions
0 comments No comments
{count} votes

Accepted answer
  1. dupammi 4,250 Reputation points Microsoft Vendor
    2024-01-31T08:26:25.1+00:00

    Hi @Yves Guena ,

    Thank you for using Microsoft Q&A. Form Recognizer does not have an inbuilt function to convert bounding boxes from a labels.json file to pixel values. However, you can use the formula pixel_value = bounding_box_value * image_size to calculate the pixel values for the bounding boxes.For example, if the image size is 1000x1000 pixels and the bounding box value is [0.6822429906542056,0.07027328499721137], you can calculate the pixel values as follows:

    x1 = 0.6822429906542056 * 1000 = 682.2429906542056
    y1 = 0.07027328499721137 * 1000 = 70.27328499721137
    

    To use this formula, you need to know the size of the image in pixels and the normalized coordinates for the bounding boxes from the labels.json file.

    You can then use the formula to calculate the pixel values for the bounding boxes. Hope this helps.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful