Update app.py
Browse files
app.py
CHANGED
@@ -17,10 +17,15 @@ def analyze_crack(image):
|
|
17 |
contours, _ = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
18 |
|
19 |
# Calculate crack metrics
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
return edges,
|
24 |
|
25 |
def classify_crack(length, width):
|
26 |
if length > 150 or width > 20:
|
@@ -30,6 +35,14 @@ def classify_crack(length, width):
|
|
30 |
else:
|
31 |
return "Minor"
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def main():
|
34 |
st.set_page_config(page_title='Structural Integrity Analyst', layout='wide', initial_sidebar_state='expanded')
|
35 |
|
@@ -42,10 +55,7 @@ def main():
|
|
42 |
image = Image.open(uploaded_file)
|
43 |
image = np.array(image)
|
44 |
|
45 |
-
edges,
|
46 |
-
|
47 |
-
# Classification
|
48 |
-
classifications = [classify_crack(l, w) for l, w in zip(crack_lengths, crack_widths)]
|
49 |
|
50 |
# Organize layout
|
51 |
col1, col2 = st.columns(2)
|
@@ -62,28 +72,29 @@ def main():
|
|
62 |
st.pyplot(fig)
|
63 |
|
64 |
# Data Analysis
|
65 |
-
data = pd.DataFrame(
|
66 |
-
"Crack Length (pixels)": crack_lengths,
|
67 |
-
"Crack Width (pixels)": crack_widths,
|
68 |
-
"Severity": classifications
|
69 |
-
})
|
70 |
|
71 |
st.subheader("Crack Metrics & Classification")
|
72 |
st.dataframe(data)
|
73 |
|
74 |
-
#
|
75 |
-
st.subheader("
|
|
|
|
|
|
|
|
|
|
|
76 |
st.write("Cracks are classified based on their length and width:")
|
77 |
-
st.write("- **Major:**
|
78 |
-
st.write("- **Moderate:**
|
79 |
-
st.write("- **Minor:**
|
80 |
|
81 |
# Visualization
|
82 |
-
fig1 = px.histogram(data, x="
|
83 |
-
fig2 = px.histogram(data, x="
|
84 |
|
85 |
st.plotly_chart(fig1, use_container_width=True)
|
86 |
st.plotly_chart(fig2, use_container_width=True)
|
87 |
|
88 |
if __name__ == "__main__":
|
89 |
-
main()
|
|
|
17 |
contours, _ = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
18 |
|
19 |
# Calculate crack metrics
|
20 |
+
crack_data = []
|
21 |
+
for cnt in contours:
|
22 |
+
length = cv2.arcLength(cnt, True)
|
23 |
+
x, y, w, h = cv2.boundingRect(cnt)
|
24 |
+
width = w
|
25 |
+
severity = classify_crack(length, width)
|
26 |
+
crack_data.append({"Length": length, "Width": width, "Severity": severity, "X": x, "Y": y})
|
27 |
|
28 |
+
return edges, crack_data
|
29 |
|
30 |
def classify_crack(length, width):
|
31 |
if length > 150 or width > 20:
|
|
|
35 |
else:
|
36 |
return "Minor"
|
37 |
|
38 |
+
def generate_description(severity):
|
39 |
+
if severity == "Major":
|
40 |
+
return "This crack is classified as major, indicating significant structural distress. Major cracks can compromise the integrity of the structure and require immediate intervention. These are typically caused by foundation settlement, excessive load, or material failure. Professional assessment is advised."
|
41 |
+
elif severity == "Moderate":
|
42 |
+
return "This crack is classified as moderate. While not immediately critical, it suggests progressive structural movement or material fatigue. Monitoring and remedial measures, such as crack sealing or reinforcement, should be considered."
|
43 |
+
else:
|
44 |
+
return "This crack is minor and likely due to surface shrinkage or thermal expansion. While not structurally concerning, periodic monitoring is recommended to ensure it does not propagate further."
|
45 |
+
|
46 |
def main():
|
47 |
st.set_page_config(page_title='Structural Integrity Analyst', layout='wide', initial_sidebar_state='expanded')
|
48 |
|
|
|
55 |
image = Image.open(uploaded_file)
|
56 |
image = np.array(image)
|
57 |
|
58 |
+
edges, crack_data = analyze_crack(image)
|
|
|
|
|
|
|
59 |
|
60 |
# Organize layout
|
61 |
col1, col2 = st.columns(2)
|
|
|
72 |
st.pyplot(fig)
|
73 |
|
74 |
# Data Analysis
|
75 |
+
data = pd.DataFrame(crack_data)
|
|
|
|
|
|
|
|
|
76 |
|
77 |
st.subheader("Crack Metrics & Classification")
|
78 |
st.dataframe(data)
|
79 |
|
80 |
+
# Description of Cracks
|
81 |
+
st.subheader("Crack Analysis & Recommendations")
|
82 |
+
for _, row in data.iterrows():
|
83 |
+
st.write(f"**Crack at (X: {row['X']}, Y: {row['Y']})** - {generate_description(row['Severity'])}")
|
84 |
+
|
85 |
+
# Discussion
|
86 |
+
st.subheader("Discussion on Crack Severity")
|
87 |
st.write("Cracks are classified based on their length and width:")
|
88 |
+
st.write("- **Major:** Significant structural impact, requires immediate repair and engineering assessment.")
|
89 |
+
st.write("- **Moderate:** Moderate concern, monitoring required, may need localized reinforcement.")
|
90 |
+
st.write("- **Minor:** Surface-level cracks, not structurally critical but should be observed over time.")
|
91 |
|
92 |
# Visualization
|
93 |
+
fig1 = px.histogram(data, x="Length", color="Severity", title="Crack Length Distribution", nbins=10)
|
94 |
+
fig2 = px.histogram(data, x="Width", color="Severity", title="Crack Width Distribution", nbins=10)
|
95 |
|
96 |
st.plotly_chart(fig1, use_container_width=True)
|
97 |
st.plotly_chart(fig2, use_container_width=True)
|
98 |
|
99 |
if __name__ == "__main__":
|
100 |
+
main()
|