Skip to content

Commit

Permalink
Fixed segmentation period
Browse files Browse the repository at this point in the history
  • Loading branch information
teapot2 committed Nov 7, 2023
1 parent d6fdf66 commit 159952d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
FRAME_HEIGHT = 480
FRAME_SIZE_BYTES = FRAME_HEIGHT * FRAME_WIDTH * 3

VIDEO_SEGMENTATION_INTERVAL = 20
VIDEO_SEGMENTATION_INTERVAL = 60
16 changes: 9 additions & 7 deletions create_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,36 @@ def process_camera(index, url, name, camera_id, shared_dict):
shm = shared_memory.SharedMemory(name=generate_shm_stream_name(index))

try:
storage_start_time = time.time()

while True:
ret, frame = cap.read()

if ret:
start_time = time.time()
function_start_time = time.time()

# Normalize frame to specified dimensions
frame = cv2.resize(frame, (config.FRAME_WIDTH, config.FRAME_HEIGHT))

frames.append(frame)

# Store frames as video locally
if (
len(frames)
% (cap.get(cv2.CAP_PROP_FPS) * config.VIDEO_SEGMENTATION_INTERVAL)
== 0
):
fps = cap.get(cv2.CAP_PROP_FPS)
segmentation_interval = config.VIDEO_SEGMENTATION_INTERVAL

if (function_start_time - storage_start_time) >= config.VIDEO_SEGMENTATION_INTERVAL:
print("Storing video data...")
store_video_data(frames, camera_id, cap.get(cv2.CAP_PROP_FPS))
frames.clear()
storage_start_time = function_start_time

# Vision processing logic goes here

send_frame_to_shared_memory(frame, shm)

# Update the shared dictionary with relevant information
shared_dict[index] = {
"execution_time": f"{time.time() - start_time:.5f} s",
"execution_time": f"{time.time() - function_start_time:.5f} s",
"camera_name": name,
"stream_name": generate_shm_stream_name(index),
"faces_detected": 0,
Expand Down

0 comments on commit 159952d

Please sign in to comment.