-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
82 lines (73 loc) · 2.51 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import imageio
from algo import find_path, Point
from tmap import Map
import io
import os
import PySimpleGUI as sg
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
file_types = [("JPEG (*.jpg)", "*.jpg"),
("All files (*.*)", "*.*")]
def main():
layout = [
[sg.Image(key="-IMAGE-")],
[
sg.Text("x,y"),
sg.Input(size=(10, 1), key="coordOne"),
sg.Text("x,y"),
sg.Input(size=(10, 1), key="coordTwo"),
sg.Text("Scale/pixel"),
sg.Input(size=(5, 1), key="scale"),
sg.Text("Height scale"),
sg.Input(size=(5, 1), key="height_scale"),
[
sg.Text("Image File"),
sg.Input(size=(25, 1), key="-FILE-"),
sg.FileBrowse(file_types=file_types),
sg.Button("Load Image"),
],
],
]
window = sg.Window("Image Viewer", layout)
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
break
if event == "Load Image":
filename = values["-FILE-"]
coordOne = values["coordOne"]
coordTwo = values["coordTwo"]
pixel_scale = int(values["scale"])
height_scale = int(values["height_scale"])
c1 = [int(i) for i in coordOne.split(', ')]
c2 = [int(i) for i in coordTwo.split(', ')]
if os.path.exists(filename):
image = Image.open(values["-FILE-"])
image.thumbnail((400, 400))
bio = io.BytesIO()
image.save(bio, format="PNG")
window["-IMAGE-"].update(data=bio.getvalue())
img = imageio.imread(filename) # 512x1024x3 array
topo_map = Map(img, height_scale, pixel_scale)
secondOne = False
path = find_path(topo_map, Point(
c1[0], c1[1]), Point(c2[0], c2[1]))
dist = len(path) # multiply
an_array = np.array(path)
plt.imshow(an_array)
plt.show()
# Construct the shortest path
window.close()
if __name__ == "__main__":
main()
def main():
elements = [
[sg.Image(key="-IMAGE-")],
[
sg.Text("Image File"),
sg.Input(size=(25, 1), enable_events=True, key="-FILE-"),
sg.FileBrowse(file_types=file_types),
],
]
window = sg.Window("Image Viewer", elements)