Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,6 +38,7 @@ def detect_faults(frame, results, frame_idx, fps):
|
|
| 38 |
mean_intensity = np.mean(roi)
|
| 39 |
area = (x2 - x1) * (y2 - y1)
|
| 40 |
|
|
|
|
| 41 |
if mean_intensity > 240:
|
| 42 |
label = "Burned Solar Panel" if area >= 10000 else "Burned Solar Cell"
|
| 43 |
color = (0, 0, 255)
|
|
@@ -51,25 +52,26 @@ def detect_faults(frame, results, frame_idx, fps):
|
|
| 51 |
continue
|
| 52 |
|
| 53 |
timestamp = round(frame_idx / fps, 2)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
})
|
| 66 |
-
|
| 67 |
-
|
| 68 |
cv2.rectangle(annotated_frame, (x1, y1), (x2, y2), color, 2)
|
| 69 |
cv2.putText(annotated_frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
|
| 70 |
|
| 71 |
return annotated_frame, faults_found
|
| 72 |
|
|
|
|
| 73 |
def process_video(video_path):
|
| 74 |
cap = cv2.VideoCapture(video_path)
|
| 75 |
if not cap.isOpened():
|
|
|
|
| 38 |
mean_intensity = np.mean(roi)
|
| 39 |
area = (x2 - x1) * (y2 - y1)
|
| 40 |
|
| 41 |
+
# Fault classification logic
|
| 42 |
if mean_intensity > 240:
|
| 43 |
label = "Burned Solar Panel" if area >= 10000 else "Burned Solar Cell"
|
| 44 |
color = (0, 0, 255)
|
|
|
|
| 52 |
continue
|
| 53 |
|
| 54 |
timestamp = round(frame_idx / fps, 2)
|
| 55 |
+
faults_found.append({
|
| 56 |
+
"Frame": frame_idx,
|
| 57 |
+
"Time (s)": timestamp,
|
| 58 |
+
"Fault Type": label,
|
| 59 |
+
"Confidence": round(float(box.conf[0]), 2) if box.conf is not None else None,
|
| 60 |
+
"Intensity": round(mean_intensity, 2),
|
| 61 |
+
"X1": x1,
|
| 62 |
+
"Y1": y1,
|
| 63 |
+
"X2": x2,
|
| 64 |
+
"Y2": y2,
|
| 65 |
+
"Box": f"({x1}, {y1}, {x2}, {y2})"
|
| 66 |
+
})
|
| 67 |
+
|
| 68 |
+
# Annotate frame
|
| 69 |
cv2.rectangle(annotated_frame, (x1, y1), (x2, y2), color, 2)
|
| 70 |
cv2.putText(annotated_frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
|
| 71 |
|
| 72 |
return annotated_frame, faults_found
|
| 73 |
|
| 74 |
+
|
| 75 |
def process_video(video_path):
|
| 76 |
cap = cv2.VideoCapture(video_path)
|
| 77 |
if not cap.isOpened():
|