File size: 2,445 Bytes
0542b72
 
 
 
 
 
 
fe68c34
0542b72
 
 
 
 
fe68c34
 
 
0542b72
 
 
fe68c34
 
 
 
 
 
0542b72
 
 
fe68c34
0542b72
 
 
fe68c34
 
0542b72
fe68c34
0542b72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe68c34
0542b72
 
 
 
 
 
 
 
 
 
 
 
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
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

# Load models for solar and windmill detection
from models.solar_model import load_solar_model
from models.windmill_model import load_windmill_model

# Root folder for videos
VIDEO_FOLDER = "./data"  # Ensure your videos are placed in this folder

def main():
    st.title("Solar Panel and Windmill Fault Detection")

    # Choose video for live feed simulation
    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}")

        # Open the video using OpenCV
        cap = cv2.VideoCapture(video_path)

        if not cap.isOpened():
            st.error("Error opening video stream or file")
            return

        # Placeholder for displaying frames
        stframe = st.empty()

        # Choose fault detection type
        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

            # Convert the frame to RGB (Streamlit uses RGB)
            frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

            # Preprocess the frame and detect faults
            faults = detect_faults_solar(model, frame_rgb) if choice == "Solar Panel" else detect_faults_windmill(model, frame_rgb)

            # Draw bounding boxes and labels for detected faults
            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)

            # Update the live feed with the processed frame
            stframe.image(frame_rgb, channels="RGB", use_column_width=True)

        cap.release()

if __name__ == "__main__":
    main()