faultdetection3 / src /streamlit_app.py
Sanjayraju30's picture
Update src/streamlit_app.py
6fdfebc verified
raw
history blame
765 Bytes
import cv2
import numpy as np
import streamlit as st
from streamlit_webrtc import webrtc_streamer, VideoTransformerBase
st.title("Live Fault Detection in Utility Poles")
class FaultDetector(VideoTransformerBase):
def transform(self, frame):
img = frame.to_ndarray(format="bgr24")
# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Apply Gaussian blur
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
# Perform Canny edge detection
edges = cv2.Canny(blurred, 50, 150)
# Convert edges to 3-channel image
edges_colored = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
return edges_colored
webrtc_streamer(key="fault_detection", video_transformer_factory=FaultDetector)