Browse Source

fix rows

master
Andreas Demmelbauer 3 years ago
parent
commit
b5c6cade76
2 changed files with 64 additions and 17 deletions
  1. +63
    -16
      gis-svg-stitcher.py
  2. +1
    -1
      requirements.txt

+ 63
- 16
gis-svg-stitcher.py View File

@@ -22,6 +22,18 @@ arg_parser.add_argument('Input',
help='Path where the FLIR tiles are') help='Path where the FLIR tiles are')




arg_parser.add_argument(
'--scale', action='store', default=15,
help="Scaling (higher number leads to bigger canvas and less dense tiles) (defaults to 15)",
type=int, dest='scale'
)

arg_parser.add_argument(
'--direction', action='store', default='both',
help="left, right, both (both is default)",
type=str, dest='direction'
)

arg_parser.add_argument( arg_parser.add_argument(
'--base_rotation', action='store', default=115, '--base_rotation', action='store', default=115,
help="Base orientation of drone in degrees (0-360) Defaults to 115", help="Base orientation of drone in degrees (0-360) Defaults to 115",
@@ -30,29 +42,30 @@ arg_parser.add_argument(


arg_parser.add_argument( arg_parser.add_argument(
'--rotation_corr_right', action='store', default=0, '--rotation_corr_right', action='store', default=0,
help="correction for tiles where drone flies into right direction",
help="rotation correction for tiles where drone flies into right direction",
type=int, dest='rotation_corr_right' type=int, dest='rotation_corr_right'
) )
arg_parser.add_argument( arg_parser.add_argument(
'--rotation_corr_left', action='store', default=0, '--rotation_corr_left', action='store', default=0,
help="correction for tiles where drone flies into left direction",
help="rotation correction for tiles where drone flies into left direction",
type=int, dest='rotation_corr_left' type=int, dest='rotation_corr_left'
) )


arg_parser.add_argument( arg_parser.add_argument(
'--scale', action='store', default=15,
help="Scaling (higher number leads to bigger canvas and less dense tiles) (defaults to 15)",
type=int, dest='scale'
'--pos_corr_right', action='store', default="0x0",
help="position correction for tiles where drone flies into right direction in pixels. eg. 10x80",
type=str, dest='pos_corr_right'
) )

arg_parser.add_argument( arg_parser.add_argument(
'--direction', action='store', default='both',
help="left, right, both (both is default)",
type=str, dest='direction'
'--pos_corr_left', action='store', default="0x0",
help="position correction for tiles where drone flies into left direction in pixels. eg. 10x80",
type=str, dest='pos_corr_left'
) )








args = arg_parser.parse_args() args = arg_parser.parse_args()


dirname = os.path.dirname(__file__) dirname = os.path.dirname(__file__)
@@ -213,6 +226,8 @@ for root_path, directories, file in os.walk(os.path.join(dirname, working_dir)):
g_pos_el = ET.SubElement(main_layer, 'g', attrib=g_pos_el_attributes) g_pos_el = ET.SubElement(main_layer, 'g', attrib=g_pos_el_attributes)


g_offset_corr_el_attributes = { g_offset_corr_el_attributes = {
'data-offset-corr-x': "{}".format(-image.width/2),
'data-offset-corr-y': "{}".format(-image.height/2),
'transform': "translate({}, {})".format(-image.width/2, -image.height/2), 'transform': "translate({}, {})".format(-image.width/2, -image.height/2),
'class': 'tile-offset-corr', 'class': 'tile-offset-corr',
} }
@@ -256,18 +271,47 @@ for index, el in enumerate(main_layer):
if(el.getprevious() is not None): if(el.getprevious() is not None):
prev_lon_offset = el.getprevious().attrib['data-lon-offset'] prev_lon_offset = el.getprevious().attrib['data-lon-offset']
lon_offset = el.attrib['data-lon-offset'] lon_offset = el.attrib['data-lon-offset']
if (prev_lon_offset > lon_offset or (prev_lon_offset == lon_offset and last_direction == 'left')):
# print('left {} -> {}'.format(prev_lon_offset, lon_offset))

# determine direction
direction = None
# print(prev_lon_offset - lon_offset)
if (prev_lon_offset == lon_offset):
direction = last_direction
# print('same lon!')
elif (float(prev_lon_offset) > float(lon_offset)):
direction = 'left'
elif (float(prev_lon_offset) < float(lon_offset)):
direction = 'right'

if (direction == 'left'):
# print('left {} | {} -> {}'.format(el.attrib['id'], prev_lon_offset, lon_offset))
el.attrib['data-direction'] = 'left' el.attrib['data-direction'] = 'left'
if (args.pos_corr_left):
offset_corr_x, offset_corr_y = args.pos_corr_left.split('x')
# print(offset_corr_x, offset_corr_y)
pos_corr_el = el[0]
corrected_pos_x = float(pos_corr_el.attrib['data-offset-corr-x']) + float(offset_corr_x)
corrected_pos_y = float(pos_corr_el.attrib['data-offset-corr-y']) + float(offset_corr_y)
pos_corr_el.attrib['transform'] = "translate({}px, {}px)".format(corrected_pos_x, corrected_pos_y)

if (args.rotation_corr_left): if (args.rotation_corr_left):
rot_el = el[0][0] rot_el = el[0][0]
corrected_rotation = float(rot_el.attrib['data-image-rotation']) + args.rotation_corr_left corrected_rotation = float(rot_el.attrib['data-image-rotation']) + args.rotation_corr_left
rot_el.attrib['data-image-rotation'] = str(corrected_rotation) rot_el.attrib['data-image-rotation'] = str(corrected_rotation)
image = rot_el[0] image = rot_el[0]
rot_el.attrib['transform'] = 'rotate({} {} {})'.format(str(corrected_rotation), str(int(image.attrib['width'])/2), str(int(image.attrib['height'])/2)) rot_el.attrib['transform'] = 'rotate({} {} {})'.format(str(corrected_rotation), str(int(image.attrib['width'])/2), str(int(image.attrib['height'])/2))
else:
# print('right {} -> {}'.format(prev_lon_offset, lon_offset))

if (direction == 'right'):
# print('right {} | {} -> {}'.format(el.attrib['id'], prev_lon_offset, lon_offset))
el.attrib['data-direction'] = 'right' el.attrib['data-direction'] = 'right'
if (args.pos_corr_right):
offset_corr_x, offset_corr_y = args.pos_corr_right.split('x')
# print(offset_corr_x, offset_corr_y)
pos_corr_el = el[0]
corrected_pos_x = float(pos_corr_el.attrib['data-offset-corr-x']) + float(offset_corr_x)
corrected_pos_y = float(pos_corr_el.attrib['data-offset-corr-y']) + float(offset_corr_y)
pos_corr_el.attrib['transform'] = "translate({}px, {}px)".format(corrected_pos_x, corrected_pos_y)

if (args.rotation_corr_right): if (args.rotation_corr_right):
rot_el = el[0][0] rot_el = el[0][0]
corrected_rotation = float(rot_el.attrib['data-image-rotation']) + args.rotation_corr_right corrected_rotation = float(rot_el.attrib['data-image-rotation']) + args.rotation_corr_right
@@ -278,13 +322,16 @@ for index, el in enumerate(main_layer):
# merge tiles into groups # merge tiles into groups
# Start new line # Start new line
if (args.direction == 'both' or args.direction == el.attrib['data-direction']): if (args.direction == 'both' or args.direction == el.attrib['data-direction']):
if (index == 1 or last_direction is not el.attrib['data-direction']):
current_row = ET.SubElement(tile_rows, 'g', attrib={ 'class': 'tile-row' })
copyElem = copy.deepcopy(el) copyElem = copy.deepcopy(el)
# if direction changes
if (index == 1 or last_direction != el.attrib['data-direction']):
# print('new row!')
current_row = ET.SubElement(tile_rows, 'g', attrib={ 'class': 'tile-row' })
# print (el.attrib['id'], el.attrib['data-direction'])
current_row.insert(0, copyElem) current_row.insert(0, copyElem)


last_direction = el.attrib['data-direction'] last_direction = el.attrib['data-direction']

# remove temporary group # remove temporary group
root.remove(main_layer) root.remove(main_layer)




+ 1
- 1
requirements.txt View File

@@ -5,7 +5,7 @@ argparse==1.4.0
pyproj==3.2.1 pyproj==3.2.1
flirimageextractor==1.4.0 flirimageextractor==1.4.0
opencv-contrib-python==4.5.3.56 opencv-contrib-python==4.5.3.56
numpy==1.19.5
numpy==1.21.2
pathlib==1.0.1 pathlib==1.0.1
selenium==3.141.0 selenium==3.141.0
rasterio==1.2.8 rasterio==1.2.8

Loading…
Cancel
Save