File size: 2,585 Bytes
efb1638
417ab56
 
 
 
efb1638
417ab56
efb1638
417ab56
 
 
efb1638
417ab56
 
 
efb1638
417ab56
 
 
 
 
 
 
efb1638
417ab56
 
 
 
 
 
efb1638
417ab56
 
 
 
 
efb1638
417ab56
efb1638
417ab56
 
 
 
 
 
 
 
efb1638
417ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import cv2
import requests
from transformers import pipeline
from ultralytics import YOLO
import numpy as np
from io import BytesIO

# Initialize the object detection model
object_detector = pipeline("object-detection", model="facebook/detr-resnet-50")
thermal_model = YOLO("thermal_model.pt")

def detect_intrusion(image):
    detections = object_detector(image)
    return [d for d in detections if d['score'] > 0.7]

def detect_thermal_anomalies(image):
    results = thermal_model(image)
    flagged = []
    for r in results:
        if hasattr(r, 'temperature') and r.temperature > 75:
            flagged.append(r)
    return flagged

def detect_shading(image):
    # Basic approach to detect shadows or dust
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    _, thresh = cv2.threshold(gray, 120, 255, cv2.THRESH_BINARY)
    contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    return len(contours) > 5  # heuristic for detecting large shadow regions

def process_frame(frame):
    # Convert the frame into the format expected by the AI models
    detections = detect_intrusion(frame)
    thermal_anomalies = detect_thermal_anomalies(frame)
    shading = detect_shading(frame)

    return detections, thermal_anomalies, shading

def create_alert(detections, thermal_anomalies, shading):
    alert_message = "Solar Panel Fault Detected!"
    if detections:
        alert_message += " Intrusion detected!"
    if thermal_anomalies:
        alert_message += " Overheating detected!"
    if shading:
        alert_message += " Shading or dust detected!"

    # Optionally send to Salesforce or another CRM system
    payload = {
        "Alert_Type__c": "Fault Detected",
        "Message__c": alert_message,
        "Confidence_Score__c": 85  # Example value, replace with actual confidence
    }
    requests.post("YOUR_SALESFORCE_API_ENDPOINT", json=payload)

    return alert_message

# Streamlit interface
st.title("Solar Panel Fault Detection")
uploaded_file = st.file_uploader("Upload a video", type=["mp4"])

if uploaded_file:
    video_bytes = uploaded_file.read()
    video = cv2.VideoCapture(BytesIO(video_bytes))
    
    while video.isOpened():
        ret, frame = video.read()
        if not ret:
            break

        detections, thermal_anomalies, shading = process_frame(frame)
        alert_message = create_alert(detections, thermal_anomalies, shading)

        st.image(frame, caption="Current Frame", channels="BGR")
        st.write(alert_message)

        # Display alerts or other relevant info