[Python] Calculate the distance on a document from point to point in relative units [closed]

Discussão em 'Python' iniciado por Stack, Dezembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    I have a template pdf file (although for solving this problem it is absolutely not important, the file can be like an image). The file size is

    dimensions = (5725, 4015), where dimensions[0] - axis x, dimensions[1] - axis y

    In this template document, information is presented as key: value. Conditional example: Name - Mark, Profession - plumber, etc.

    I have the coordinates of the upper right corners of the key and value. For example, for the string "Name - Mark":

    point_for_key = (2027.1044921875, 1610.15625)

    point_for_value = (2725.0244140625, 1610.15625)

    Next, I look for the distance between these two points, so that in the following documents, knowing the coordinates for the key and the distance to the value, I can correctly find the value

    distance_value_tag = math.dist(point_for_key, point_for_value)
    print(distance_value_tag) # *697.919921875*


    It is clear that I get distance_value_tag in absolute units. That is (it was not in vain that I specified the document size at the beginning), if the dimensions of the next document changes (but it will correspond to the template document), then as I understand it, distance_value_tag will not be relevant. I somehow need to calculate distance_value_tag in relative units and recalculate distance_value_tag for each subsequent document depending on its size.

    For example, if I get a document of the same template, but with dimensions = (7442, 5220), then the distance_value_tag that I calculated for the template document will be irrelevant on the new document, and I will not find the value for the key I need.

    How to recalculate the distance_value_tag in relative units?

    Continue reading...

Compartilhe esta Página