|
|
import streamlit as st |
|
|
import cv2 |
|
|
from services.video_service import process_video |
|
|
from services.detection_service import detect_faults_solar, detect_faults_windmill |
|
|
from services.thermal_service import detect_hotspots |
|
|
from services.shadow_detection import detect_shadows |
|
|
from PIL import Image |
|
|
import os |
|
|
|
|
|
|
|
|
from models.solar_model import load_solar_model |
|
|
from models.windmill_model import load_windmill_model |
|
|
|
|
|
|
|
|
VIDEO_FOLDER = "./data" |
|
|
|
|
|
def main(): |
|
|
st.title("Solar Panel and Windmill Fault Detection") |
|
|
|
|
|
|
|
|
video_file = st.selectbox("Choose a Video", [f for f in os.listdir(VIDEO_FOLDER) if f.endswith('.mp4')]) |
|
|
|
|
|
if video_file: |
|
|
video_path = os.path.join(VIDEO_FOLDER, video_file) |
|
|
st.write(f"Processing video: {video_file}") |
|
|
|
|
|
|
|
|
cap = cv2.VideoCapture(video_path) |
|
|
|
|
|
if not cap.isOpened(): |
|
|
st.error("Error opening video stream or file") |
|
|
return |
|
|
|
|
|
|
|
|
stframe = st.empty() |
|
|
|
|
|
|
|
|
choice = st.selectbox("Choose Fault Detection", ["Solar Panel", "Windmill"]) |
|
|
model = None |
|
|
if choice == "Solar Panel": |
|
|
model = load_solar_model() |
|
|
else: |
|
|
model = load_windmill_model() |
|
|
|
|
|
while cap.isOpened(): |
|
|
ret, frame = cap.read() |
|
|
if not ret: |
|
|
break |
|
|
|
|
|
|
|
|
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
|
|
|
|
|
|
|
|
faults = detect_faults_solar(model, frame_rgb) if choice == "Solar Panel" else detect_faults_windmill(model, frame_rgb) |
|
|
|
|
|
|
|
|
for fault in faults: |
|
|
x, y = int(fault['location'][0]), int(fault['location'][1]) |
|
|
cv2.putText(frame, f"Fault: {fault['type']}", (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2) |
|
|
cv2.rectangle(frame, (x-20, y-20), (x+80, y+40), (0, 0, 255), 2) |
|
|
|
|
|
|
|
|
stframe.image(frame_rgb, channels="RGB", use_column_width=True) |
|
|
|
|
|
cap.release() |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|