Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,15 +42,6 @@ logging.basicConfig(
|
|
| 42 |
format="%(asctime)s - %(levelname)s - %(message)s"
|
| 43 |
)
|
| 44 |
|
| 45 |
-
import cv2
|
| 46 |
-
from controller import detect_under_construction_objects
|
| 47 |
-
|
| 48 |
-
# Set mode: "bridge", "culvert", or "earthwork"
|
| 49 |
-
mode = "bridge"
|
| 50 |
-
|
| 51 |
-
# Try video file path first or webcam
|
| 52 |
-
video_source = '/path/to/your/video.mp4' # Change this to your video file path or try index 1
|
| 53 |
-
cap = cv2.VideoCapture(video_source)
|
| 54 |
|
| 55 |
if not cap.isOpened():
|
| 56 |
print(f"Error: Could not open video source {video_source}. Trying camera.")
|
|
@@ -60,29 +51,7 @@ if not cap.isOpened():
|
|
| 60 |
print("Error: Could not open camera or video source.")
|
| 61 |
exit()
|
| 62 |
|
| 63 |
-
|
| 64 |
-
ret, frame = cap.read() # Read a frame from the video source
|
| 65 |
-
if not ret:
|
| 66 |
-
print("Error: Failed to read frame.")
|
| 67 |
-
break
|
| 68 |
-
|
| 69 |
-
detections, annotated_frame = detect_under_construction_objects(frame, mode)
|
| 70 |
-
|
| 71 |
-
# Display the annotated frame
|
| 72 |
-
cv2.imshow("Detection", annotated_frame)
|
| 73 |
-
|
| 74 |
-
key = cv2.waitKey(1)
|
| 75 |
-
if key == ord("q"): # Press 'q' to quit
|
| 76 |
-
break
|
| 77 |
-
elif key == ord("1"): # Press '1' to detect bridge piers
|
| 78 |
-
mode = "bridge"
|
| 79 |
-
elif key == ord("2"): # Press '2' to detect culverts
|
| 80 |
-
mode = "culvert"
|
| 81 |
-
elif key == ord("3"): # Press '3' to detect earthwork
|
| 82 |
-
mode = "earthwork"
|
| 83 |
-
|
| 84 |
-
cap.release()
|
| 85 |
-
cv2.destroyAllWindows()
|
| 86 |
|
| 87 |
|
| 88 |
# Global variables
|
|
|
|
| 42 |
format="%(asctime)s - %(levelname)s - %(message)s"
|
| 43 |
)
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
if not cap.isOpened():
|
| 47 |
print(f"Error: Could not open video source {video_source}. Trying camera.")
|
|
|
|
| 51 |
print("Error: Could not open camera or video source.")
|
| 52 |
exit()
|
| 53 |
|
| 54 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
# Global variables
|