bhagwandas commited on
Commit
28c9014
·
verified ·
1 Parent(s): 476c0f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -20
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
- crack_lengths = [cv2.arcLength(cnt, True) for cnt in contours]
21
- crack_widths = [cv2.boundingRect(cnt)[2] for cnt in contours]
 
 
 
 
 
22
 
23
- return edges, crack_lengths, crack_widths
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, crack_lengths, crack_widths = analyze_crack(image)
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
- # Discussion Tab
75
- st.subheader("Discussion")
 
 
 
 
 
76
  st.write("Cracks are classified based on their length and width:")
77
- st.write("- **Major:** Cracks exceeding 150 pixels in length or 20 pixels in width indicate severe damage and require immediate attention.")
78
- st.write("- **Moderate:** Cracks between 80-150 pixels in length or 10-20 pixels in width are moderate and should be monitored closely.")
79
- st.write("- **Minor:** Cracks below 80 pixels in length or 10 pixels in width are minor and may not require immediate intervention but should be observed over time.")
80
 
81
  # Visualization
82
- fig1 = px.histogram(data, x="Crack Length (pixels)", color="Severity", title="Crack Length Distribution", nbins=10)
83
- fig2 = px.histogram(data, x="Crack Width (pixels)", color="Severity", title="Crack Width Distribution", nbins=10)
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()