Как рассчитать и попасть на какую сетку попали компоненты? - PullRequest
0 голосов
/ 25 мая 2020

Я работаю над генератором кода на стороне клиента и не смог вычислить значения обнаруженных ящиков с сеткой. размер сетки 80 x 80 и ширина = 960. Есть ли способ узнать, на какой сетке лежат компоненты l ie. Вот команда для создания сетки import matplotlib.pyplot as plt import matplotlib.ticker as plticker try: from PIL import Image, кроме ImportError: import Image

# Open image file
image = Image.open('static/img/z_6.png')
my_dpi=300.

# Set up figure
fig=plt.figure(figsize= 
(float(image.size[0])/my_dpi,float(image.size[1])/my_dpi),dpi=my_dpi)
ax=fig.add_subplot(111)

# Remove whitespace from around the image
fig.subplots_adjust(left=0,right=1,bottom=0,top=1)

# Set the gridding interval: here we use the major tick interval
myInterval=80.
loc = plticker.MultipleLocator(base=myInterval)
ax.xaxis.set_major_locator(loc)
ax.yaxis.set_major_locator(loc)

# Add the grid
ax.grid(which='major', axis='both', linestyle='-', color='g')

# Add the image
ax.imshow(image)

# Find number of gridsquares in x and y direction
nx=abs(int(float(ax.get_xlim()[1]-ax.get_xlim()[0])/float(myInterval)))
ny=abs(int(float(ax.get_ylim()[1]-ax.get_ylim()[0])/float(myInterval)))

# Save the figure
fig.savefig('image1.jpg')

, и у меня есть этот файл сына для ящиков

[
    {
    "id": 13,
    "name": "Button",
    "accuracy": 99.99,
    "xmin": 433,
    "ymin": 535,
    "xmax": 611,
    "ymax": 599,
    "width": 178,
    "height": 64
},
{
    "id": 10,
    "name": "Paragraph",
    "accuracy": 99.98,
    "xmin": 86,
    "ymin": 225,
    "xmax": 318,
    "ymax": 329,
    "width": 232,
    "height": 104
},
{
    "id": 10,
    "name": "Paragraph",
    "accuracy": 99.96,
    "xmin": 634,
    "ymin": 228,
    "xmax": 859,
    "ymax": 324,
    "width": 225,
    "height": 96
}]

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...