Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,41 +14,6 @@ import numpy as np
|
|
| 14 |
import cv2
|
| 15 |
import time
|
| 16 |
|
| 17 |
-
def process_sequential(frame: np.ndarray):
|
| 18 |
-
# Detect bridge piers first
|
| 19 |
-
detections, annotated_frame = process_bridge_piers(frame)
|
| 20 |
-
cv2.imshow("Bridge Piers Detection", annotated_frame)
|
| 21 |
-
cv2.waitKey(1) # Wait for a short time (e.g., 1 ms)
|
| 22 |
-
time.sleep(1) # Pause for 1 second for the user to see the result
|
| 23 |
-
|
| 24 |
-
# Replay the video (or go to next frame if real-time processing)
|
| 25 |
-
cv2.imshow("Bridge Piers Detection", frame)
|
| 26 |
-
cv2.waitKey(1)
|
| 27 |
-
|
| 28 |
-
# Detect culverts next
|
| 29 |
-
detections, annotated_frame = process_culverts(frame)
|
| 30 |
-
cv2.imshow("Culverts Detection", annotated_frame)
|
| 31 |
-
cv2.waitKey(1)
|
| 32 |
-
time.sleep(1)
|
| 33 |
-
|
| 34 |
-
# Replay the video for culverts detection
|
| 35 |
-
cv2.imshow("Culverts Detection", frame)
|
| 36 |
-
cv2.waitKey(1)
|
| 37 |
-
|
| 38 |
-
# Detect earthwork activities
|
| 39 |
-
detections, annotated_frame = process_earthwork(frame)
|
| 40 |
-
cv2.imshow("Earthwork Detection", annotated_frame)
|
| 41 |
-
cv2.waitKey(1)
|
| 42 |
-
time.sleep(1)
|
| 43 |
-
|
| 44 |
-
# Replay the video for earthwork detection
|
| 45 |
-
cv2.imshow("Earthwork Detection", frame)
|
| 46 |
-
cv2.waitKey(1)
|
| 47 |
-
|
| 48 |
-
# Add more steps if needed...
|
| 49 |
-
|
| 50 |
-
cv2.waitKey(0) # Wait for a key press to close the window after detection
|
| 51 |
-
cv2.destroyAllWindows()
|
| 52 |
|
| 53 |
|
| 54 |
# Suppress Ultralytics warning by setting a writable config directory
|
|
@@ -76,6 +41,35 @@ logging.basicConfig(
|
|
| 76 |
level=logging.INFO,
|
| 77 |
format="%(asctime)s - %(levelname)s - %(message)s"
|
| 78 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
# Global variables
|
| 81 |
paused: bool = False
|
|
|
|
| 14 |
import cv2
|
| 15 |
import time
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
# Suppress Ultralytics warning by setting a writable config directory
|
|
|
|
| 41 |
level=logging.INFO,
|
| 42 |
format="%(asctime)s - %(levelname)s - %(message)s"
|
| 43 |
)
|
| 44 |
+
# controller.py
|
| 45 |
+
from services.under_construction.bridge_pier_check import process_bridge_piers
|
| 46 |
+
from services.under_construction.culvert_check import process_culverts
|
| 47 |
+
from services.under_construction.earthwork_detection import process_earthwork
|
| 48 |
+
|
| 49 |
+
def detect_under_construction_objects(frame, mode: str):
|
| 50 |
+
"""
|
| 51 |
+
Dispatches frame to the appropriate detection function based on mode.
|
| 52 |
+
Args:
|
| 53 |
+
frame: Input frame as a numpy array.
|
| 54 |
+
mode: One of "bridge", "culvert", "earthwork".
|
| 55 |
+
Returns:
|
| 56 |
+
Tuple of (detections, annotated_frame)
|
| 57 |
+
"""
|
| 58 |
+
if mode == "bridge":
|
| 59 |
+
return process_bridge_piers(frame)
|
| 60 |
+
elif mode == "culvert":
|
| 61 |
+
return process_culverts(frame)
|
| 62 |
+
elif mode == "earthwork":
|
| 63 |
+
return process_earthwork(frame)
|
| 64 |
+
else:
|
| 65 |
+
raise ValueError(f"Unknown mode: {mode}")
|
| 66 |
+
# main.py (or your video loop)
|
| 67 |
+
from controller import detect_under_construction_objects
|
| 68 |
+
|
| 69 |
+
# Assume `mode` is selected externally: "bridge", "culvert", or "earthwork"
|
| 70 |
+
mode = "bridge" # change as needed
|
| 71 |
+
detections, annotated_frame = detect_under_construction_objects(frame, mode)
|
| 72 |
+
|
| 73 |
|
| 74 |
# Global variables
|
| 75 |
paused: bool = False
|