Skip to content

Instantly share code, notes, and snippets.

@xictus77
Created January 14, 2022 08:09
Show Gist options
  • Save xictus77/8f879d7b1b6c096bf33f02eae976b315 to your computer and use it in GitHub Desktop.
Save xictus77/8f879d7b1b6c096bf33f02eae976b315 to your computer and use it in GitHub Desktop.
Initialize variables for obstruction detection
# initialize the first frame in the video stream
# firstFrame = None
firstFrame = None
status_list = [None, None]
times = []
timer = []
df = pd.DataFrame(columns = ["Start","End", "duration_in_sec"])
fps_start_time = datetime.now()
fps = 0
total_frames = 0
object_id_list = []
dtime = dict()
dwell_time = dict()
allowable_duration = 10.0 # stipulated allowable duration for static obstruction in seconds
timestr = time.strftime("%H%M%S")
t = int(timestr)
filename = "sample_camera/file_%a.avi" % t
filename_d = "sample_camera/file_d_%a.avi" % t
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
# variables for drawing ROI
points = [(919.2771084337348,417.8554216867469),
(1472,1079),
(818,1079),
(787.9518072289156,884.1204819277108),
(762.6506024096385,428.69879518072287)]
points_roi = polys
print(f'ROIS LOADED: \n{points_roi}')
"""
points = [(12.668639053254438, 281.6568047337278),
(115.62721893491124, 197.0414201183432),
(396.10059171597635, 193.49112426035504),
(519.1775147928994, 485.79881656804736),
(12.668639053254438, 495.85798816568047)]
"""
points_resized = (np.int32(np.int32(points)/2)) # rescale points as the frame is resized from 1920 px to 960 px
polygon = [np.int32(points)]
# initialize our centroid tracker and frame dimensions -- added for centroid tracker
ct = CentroidTracker()
(H, W) = (None, None)
# initialize colors
GREEN = (0 , 255, 0)
RED = (0, 0, 255)
BLUE = (255, 0 ,0)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
# Define the codec and create VideoWriter object.The output is stored in 'output.avi' file.
out = cv2.VideoWriter(filename, fourcc, 25.0, (960, 540))
out_det = cv2.VideoWriter(filename_d, fourcc, 25.0, (960, 540))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment