Я пытаюсь написать функцию, которая принимает следующие аргументы:
def get_square(n, size, ebt):
'''
n is the number of square
size is the size of the rectangle, in our case size=w=h
ebt stand for elevation body temperature, it will a constant value
'''
return
Первая координата квадрата вычисляется таким образом. Обратите внимание, что размер = h = w
Как показано на диаграмме ниже, при увеличении n у нас должно быть больше квадратов (форма сетки) , функция должна возвращать x, y, w, h каждого квадрата в текстовом файле, как показано ниже (если n = 3):
Prediction_Region = x1, y1, w1, h1, x2, y2, w2, h2, x3, y3, w3, h3
Max_Temperture = ebt, ebt, ebt
Я пытался реализовать несколько попыток, но мне кажется, что я что-то упустил.
что код например, я пытаюсь вызвать эту функцию из терминала
import os, sys
import re
import math
import argparse
import numpy as np
FILE_NAME = 'output.txt'
def square(n, size, ebt):
xs = 320
ys = 256
nx = int(xs)/2 - size/2
ny = int(ys)/2 - size/2
# the main thing should be here, but I am not able to implement it due to few error
return
# this is to write the output of square function in a text file.
def writetoendofline(lines, line_no, append_txt):
lines[line_no] = lines[line_no].replace('\n', '') + append_txt + '\n'
# open the file
with open(FILE_NAME, 'r') as txtfile:
lines = txtfile.readlines()
# this function take the line number and append a value at the end of it
# ultimately the output of square function should be entered here
writetoendofline(lines, 1, '23 ')
# writetoendofline(lines, 0, nx)
# write to the file
with open(FILE_NAME, 'w') as txtfile:
txtfile.writelines(lines)
# write to the file
txtfile.close()
if __name__ == '__main__':
n = sys.argv[1]
size = sys.argv[2]
ebt = sys.argv[3]
square(n, size, ebt)