fork download
  1. import cv2
  2. import numpy as np
  3. from tracker import *
  4.  
  5. # Create tracker object
  6. tracker = EuclideanDistTracker()
  7.  
  8. cap = cv2.VideoCapture("Video Source")
  9.  
  10. count = 0
  11.  
  12. while True:
  13. ret, frame = cap.read()
  14.  
  15. print("\n")
  16.  
  17. if(count != 0):
  18. print("Frame Count: ", count)
  19. frame = cv2.resize(frame, (0, 0), fx = 1.5, fy = 1.5)
  20. height, width, channels = frame.shape
  21.  
  22. # 1. Object Detection
  23. hsvFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
  24. sensitivity = 20
  25. white_lower = np.array([0,0,255-sensitivity])
  26. white_upper = np.array([255,sensitivity,255])
  27. white_mask = cv2.inRange(hsvFrame, white_lower, white_upper)
  28.  
  29. # Morphological Transform, Dilation
  30. kernal = np.ones((3, 3), "uint8")
  31. c = 1
  32.  
  33. contours_w, hierarchy_w = cv2.findContours(white_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
  34. detections = []
  35.  
  36. for contour_w in contours_w:
  37. area = cv2.contourArea(contour_w)
  38. if area > 200 and area < 100000:
  39. cv2.drawContours(frame, [contour_w], -1, (0, 0, 0), 1)
  40. x,y,w,h = cv2.boundingRect(contour_w)
  41. detections.append([x, y, w, h])
  42.  
  43. # 2. Object Tracking
  44. boxes_ids = tracker.update(detections)
  45. for box_id in boxes_ids:
  46. x, y, w, h, id = box_id
  47. cv2.putText(frame, str(id), (x - 8, y + 8), cv2.FONT_HERSHEY_PLAIN, 2, (0, 0, 0), 2)
  48. cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 0), 1)
  49.  
  50. cv2.imshow("Frame", frame)
  51. count += 1
  52. key = cv2.waitKey(0)
  53. if key == 27:
  54. break
  55.  
  56. cap.release()
  57. cv2.destroyAllWindows()
Runtime error #stdin #stdout #stderr 0.14s 23600KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'