umgefahren
commited on
Commit
·
3e97108
1
Parent(s):
181cd8e
Revert
Browse files- Dockerfile +0 -1
- main.py +43 -42
Dockerfile
CHANGED
@@ -37,7 +37,6 @@ RUN python -m pip install git+https://github.com/PatBall1/detectree2.git
|
|
37 |
RUN python -m pip install opencv-python
|
38 |
RUN python -m pip install requests
|
39 |
|
40 |
-
RUN python -m pip install plotly
|
41 |
RUN python -m pip install gradio
|
42 |
|
43 |
COPY --chown=user . $HOME/app
|
|
|
37 |
RUN python -m pip install opencv-python
|
38 |
RUN python -m pip install requests
|
39 |
|
|
|
40 |
RUN python -m pip install gradio
|
41 |
|
42 |
COPY --chown=user . $HOME/app
|
main.py
CHANGED
@@ -8,8 +8,8 @@ import gradio as gr
|
|
8 |
import rasterio
|
9 |
from rasterio.plot import show
|
10 |
import geopandas as gpd
|
|
|
11 |
from shapely.geometry import Point
|
12 |
-
import plotly.graph_objects as go
|
13 |
|
14 |
|
15 |
|
@@ -97,53 +97,54 @@ def greet(image_path: str):
|
|
97 |
# Set the interactive backend to Qt5Agg
|
98 |
# plt.switch_backend('Qt5Agg') # You have to install PyQt5
|
99 |
|
|
|
|
|
|
|
100 |
# Plotting
|
101 |
-
fig =
|
102 |
-
fig.add_trace(go.Image(z=tif_image.transpose((1, 2, 0))))
|
103 |
-
for idx, row in geojson_data.iterrows():
|
104 |
-
geojson_dict = json.loads(row['geometry'].to_json())
|
105 |
-
fig.add_trace(go.Scattergeo(
|
106 |
-
lon=[coord[0] for coord in geojson_dict['coordinates'][0]],
|
107 |
-
lat=[coord[1] for coord in geojson_dict['coordinates'][0]],
|
108 |
-
mode='lines',
|
109 |
-
line=dict(color='red'),
|
110 |
-
name=f'Polygon {idx}'
|
111 |
-
))
|
112 |
|
113 |
-
#
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
center=dict(
|
119 |
-
lon=tif_transform.c + (tif_transform.a * tif_image.width / 2),
|
120 |
-
lat=tif_transform.f + (tif_transform.e * tif_image.height / 2)
|
121 |
-
)
|
122 |
-
)
|
123 |
-
)
|
124 |
-
|
125 |
-
# Function to handle click events
|
126 |
-
def on_click(trace, points, state):
|
127 |
-
if points.point_inds:
|
128 |
-
idx = points.point_inds[0]
|
129 |
-
row = geojson_data.iloc[idx]
|
130 |
-
species_info = row['species']
|
131 |
-
confidence_score = row['Confidence_score']
|
132 |
-
text = f"Polygon {idx}\n\nConfidence:\n{confidence_score}\n\nSpecies and their probability:\n{species_info}"
|
133 |
-
fig.update_layout(annotations=[dict(
|
134 |
-
x=points.xs[0],
|
135 |
-
y=points.ys[0],
|
136 |
-
text=text,
|
137 |
-
showarrow=True,
|
138 |
-
arrowhead=7
|
139 |
-
)])
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
# Connect the click event to the handler function
|
142 |
-
|
143 |
-
trace.on_click(on_click)
|
144 |
|
145 |
-
|
146 |
|
|
|
147 |
|
148 |
#tif_file_name = "TreeCrownVectorDataset_761588_9673769_20_20_32720.tif"
|
149 |
#tif_input = "/Users/jonathanseele/ETH/Hackathons/EcoHackathon/WeCanopy/test/" + tif_file_name
|
|
|
8 |
import rasterio
|
9 |
from rasterio.plot import show
|
10 |
import geopandas as gpd
|
11 |
+
import matplotlib.pyplot as plt
|
12 |
from shapely.geometry import Point
|
|
|
13 |
|
14 |
|
15 |
|
|
|
97 |
# Set the interactive backend to Qt5Agg
|
98 |
# plt.switch_backend('Qt5Agg') # You have to install PyQt5
|
99 |
|
100 |
+
# Enable interactive mode
|
101 |
+
plt.ion()
|
102 |
+
|
103 |
# Plotting
|
104 |
+
fig, ax = plt.subplots(figsize=(10, 10))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
+
# Plot the RGB TIF image
|
107 |
+
show(tif_image, transform=tif_transform, ax=ax)
|
108 |
+
|
109 |
+
# Plot the GeoJSON polygons
|
110 |
+
geojson_data.plot(ax=ax, facecolor='none', edgecolor='red')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
+
# Set plot title
|
113 |
+
ax.set_title('TIF Image with Tree Crowns Overlay')
|
114 |
+
|
115 |
+
# Create an annotation box
|
116 |
+
annot = ax.annotate("", xy=(0, 0), xytext=(20, 20),
|
117 |
+
textcoords="offset points",
|
118 |
+
bbox=dict(boxstyle="round", fc="w"),
|
119 |
+
arrowprops=dict(arrowstyle="->"))
|
120 |
+
annot.set_visible(False)
|
121 |
+
|
122 |
+
# Create a function to handle mouse clicks
|
123 |
+
def on_click(event):
|
124 |
+
if event.inaxes is not None:
|
125 |
+
# Get the coordinates of the click
|
126 |
+
click_point = Point(event.xdata, event.ydata)
|
127 |
+
# Check if the click is within any of the polygons
|
128 |
+
for idx, row in geojson_data.iterrows():
|
129 |
+
if row['geometry'].contains(click_point):
|
130 |
+
# Access the properties dictionarㅋ
|
131 |
+
# Extract species and confidence score
|
132 |
+
species_info = row['species']
|
133 |
+
confidence_score = row['Confidence_score']
|
134 |
+
# Display information about the clicked polygon
|
135 |
+
annot.xy = (event.xdata, event.ydata)
|
136 |
+
text = f"Polygon {idx}\n\nConfidence:\n{confidence_score}\n\nSpecies and their probability:\n{species_info}"
|
137 |
+
annot.set_text(text)
|
138 |
+
annot.set_visible(True)
|
139 |
+
fig.canvas.draw()
|
140 |
+
break
|
141 |
+
|
142 |
# Connect the click event to the handler function
|
143 |
+
# cid = fig.canvas.mpl_connect('button_press_event', on_click)
|
|
|
144 |
|
145 |
+
figure = plt.figure()
|
146 |
|
147 |
+
return figure
|
148 |
|
149 |
#tif_file_name = "TreeCrownVectorDataset_761588_9673769_20_20_32720.tif"
|
150 |
#tif_input = "/Users/jonathanseele/ETH/Hackathons/EcoHackathon/WeCanopy/test/" + tif_file_name
|