ayushsaun commited on
Commit
ebce887
·
1 Parent(s): 363db49

minor bug fix

Browse files
Files changed (1) hide show
  1. inference.py +17 -2
inference.py CHANGED
@@ -95,7 +95,13 @@ class SlidingWindowRefiner:
95
  return 0
96
 
97
  matches = self.flann.knnMatch(self.template_desc, desc, k=2)
98
- good = [m for m, n in matches if m.distance < 0.7 * n.distance]
 
 
 
 
 
 
99
 
100
  if not good:
101
  return 0
@@ -271,6 +277,8 @@ class ObjectTrackerInference:
271
  frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
272
  total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
273
 
 
 
274
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
275
  out = cv2.VideoWriter(output_path, fourcc, fps, (frame_width, frame_height))
276
 
@@ -281,6 +289,8 @@ class ObjectTrackerInference:
281
  current_bbox = initial_bbox
282
  frame_idx = 0
283
 
 
 
284
  while True:
285
  ret, frame = cap.read()
286
  if not ret:
@@ -320,11 +330,16 @@ class ObjectTrackerInference:
320
  x, y, w, h = map(int, current_bbox)
321
  cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 2)
322
  cv2.putText(frame, f'Frame: {frame_idx}', (10, 30),
323
- cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
324
 
325
  out.write(frame)
326
  frame_idx += 1
 
 
 
327
 
328
  cap.release()
329
  out.release()
 
 
330
  return output_path
 
95
  return 0
96
 
97
  matches = self.flann.knnMatch(self.template_desc, desc, k=2)
98
+
99
+ good = []
100
+ for match_pair in matches:
101
+ if len(match_pair) == 2:
102
+ m, n = match_pair
103
+ if m.distance < 0.7 * n.distance:
104
+ good.append(m)
105
 
106
  if not good:
107
  return 0
 
277
  frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
278
  total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
279
 
280
+ print(f"Video: {frame_width}x{frame_height}, {total_frames} frames") # 🔹 ADD THIS
281
+
282
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
283
  out = cv2.VideoWriter(output_path, fourcc, fps, (frame_width, frame_height))
284
 
 
289
  current_bbox = initial_bbox
290
  frame_idx = 0
291
 
292
+ print("Tracking object...") # 🔹 ADD THIS
293
+
294
  while True:
295
  ret, frame = cap.read()
296
  if not ret:
 
330
  x, y, w, h = map(int, current_bbox)
331
  cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 2)
332
  cv2.putText(frame, f'Frame: {frame_idx}', (10, 30),
333
+ cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
334
 
335
  out.write(frame)
336
  frame_idx += 1
337
+
338
+ if frame_idx % 30 == 0: # 🔹 ADD THIS
339
+ print(f"Processed {frame_idx}/{total_frames} frames")
340
 
341
  cap.release()
342
  out.release()
343
+
344
+ print(f"Tracking complete! Video saved to: {output_path}") # 🔹 ADD THIS
345
  return output_path