File size: 3,298 Bytes
aae87aa 476c0f9 aae87aa 476c0f9 aae87aa 476c0f9 aae87aa 476c0f9 aae87aa 476c0f9 aae87aa 476c0f9 aae87aa 476c0f9 aae87aa 476c0f9 aae87aa 476c0f9 |
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 83 84 85 86 87 88 89 |
import streamlit as st
import cv2
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import plotly.express as px
from PIL import Image
def analyze_crack(image):
# Convert image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Edge detection
edges = cv2.Canny(gray, 50, 150)
# Finding contours
contours, _ = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# Calculate crack metrics
crack_lengths = [cv2.arcLength(cnt, True) for cnt in contours]
crack_widths = [cv2.boundingRect(cnt)[2] for cnt in contours]
return edges, crack_lengths, crack_widths
def classify_crack(length, width):
if length > 150 or width > 20:
return "Major"
elif length > 80 or width > 10:
return "Moderate"
else:
return "Minor"
def main():
st.set_page_config(page_title='Structural Integrity Analyst', layout='wide', initial_sidebar_state='expanded')
st.title('๐๏ธ Structural Integrity Analyst')
st.sidebar.header("Upload Crack Image")
uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
image = np.array(image)
edges, crack_lengths, crack_widths = analyze_crack(image)
# Classification
classifications = [classify_crack(l, w) for l, w in zip(crack_lengths, crack_widths)]
# Organize layout
col1, col2 = st.columns(2)
with col1:
st.subheader("Uploaded Image")
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
with col2:
st.subheader("Processed Crack Detection")
fig, ax = plt.subplots()
ax.imshow(edges, cmap='gray')
ax.axis("off")
st.pyplot(fig)
# Data Analysis
data = pd.DataFrame({
"Crack Length (pixels)": crack_lengths,
"Crack Width (pixels)": crack_widths,
"Severity": classifications
})
st.subheader("Crack Metrics & Classification")
st.dataframe(data)
# Discussion Tab
st.subheader("Discussion")
st.write("Cracks are classified based on their length and width:")
st.write("- **Major:** Cracks exceeding 150 pixels in length or 20 pixels in width indicate severe damage and require immediate attention.")
st.write("- **Moderate:** Cracks between 80-150 pixels in length or 10-20 pixels in width are moderate and should be monitored closely.")
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.")
# Visualization
fig1 = px.histogram(data, x="Crack Length (pixels)", color="Severity", title="Crack Length Distribution", nbins=10)
fig2 = px.histogram(data, x="Crack Width (pixels)", color="Severity", title="Crack Width Distribution", nbins=10)
st.plotly_chart(fig1, use_container_width=True)
st.plotly_chart(fig2, use_container_width=True)
if __name__ == "__main__":
main() |