File size: 2,137 Bytes
aae87aa |
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 |
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 main():
st.set_page_config(page_title='Structural Integrity Analyst', layout='wide')
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)
st.subheader("Uploaded Image")
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
# Display processed image
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
})
st.subheader("Crack Metrics")
st.dataframe(data)
# Visualization
fig1 = px.histogram(data, x="Crack Length (pixels)", title="Crack Length Distribution", nbins=10)
fig2 = px.histogram(data, x="Crack Width (pixels)", 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()
|