hb-setosys commited on
Commit
7849b8f
·
verified ·
1 Parent(s): b0a9e04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -20,6 +20,27 @@ CONFIDENCE_THRESHOLD = 0.5
20
  # Distance threshold to avoid duplicate counts
21
  DISTANCE_THRESHOLD = 50
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  def count_unique_trucks(video_path):
24
  cap = cv2.VideoCapture(video_path)
25
  if not cap.isOpened():
@@ -34,16 +55,12 @@ def count_unique_trucks(video_path):
34
  # Extract filename from the path
35
  video_filename = os.path.basename(video_path).lower()
36
 
37
- # Dynamically adjust time interval based on filename
38
- if "fixed" in video_filename:
39
- time_interval = 2 # Process every 10 seconds for fixed camera
40
- elif "moving" in video_filename:
41
- time_interval = 7 # Process every 5 seconds for moving camera
42
- else:
43
- time_interval = 5 # Default to 7 seconds
44
 
 
 
45
  frame_skip = fps * time_interval # Convert time interval to frame count
46
- #frame_skip = fps * 7 # Skip frames every 5 seconds
47
 
48
  frame_count = 0
49
 
 
20
  # Distance threshold to avoid duplicate counts
21
  DISTANCE_THRESHOLD = 50
22
 
23
+ # Dictionary to define keyword-based time intervals
24
+ TIME_INTERVALS = {
25
+ "fixed": 2, # Fixed camera video
26
+ "moving": 5, # Moving camera video
27
+ "drone": 7, # Drone footage (slower interval)
28
+ "dashcam": 6, # Dashcam video
29
+ "highway": 7, # Highway footage
30
+ "city": 8, # City road footage
31
+ }
32
+
33
+ def determine_time_interval(video_filename):
34
+ """
35
+ Determines the time interval based on keywords found in the video filename.
36
+ Defaults to 7 seconds if no matching keyword is found.
37
+ """
38
+ for keyword, interval in TIME_INTERVALS.items():
39
+ if keyword in video_filename:
40
+ return interval
41
+ return 5 # Default interval if no keyword matches
42
+
43
+
44
  def count_unique_trucks(video_path):
45
  cap = cv2.VideoCapture(video_path)
46
  if not cap.isOpened():
 
55
  # Extract filename from the path
56
  video_filename = os.path.basename(video_path).lower()
57
 
58
+ # Extract filename from the path and convert to lowercase
59
+ video_filename = os.path.basename(video_path).lower()
 
 
 
 
 
60
 
61
+ # Determine the dynamic time interval based on filename keywords
62
+ time_interval = determine_time_interval(video_filename)
63
  frame_skip = fps * time_interval # Convert time interval to frame count
 
64
 
65
  frame_count = 0
66