Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions exercises/static/exercises/human_detection/web-template/hal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
import cv2
import os
import threading
from threading import *

#Multi-threading frame access class
class WebcamStream:
def __init__(self,id=0):
self.id = id
self.cap = cv2.VideoCapture(id)
#flag to check if the thread is started
self.start_flag = False


def start(self):
#Seperate thread for update function
self.t = Thread(target=self.update)
self.t.daemon = True
self.t.start()
self.start_flag = True


def update(self):
#Access frames
while True:
self.flag,self.frame = self.cap.read()
if self.flag is False:
print("\nError getting Frame")
break
self.cap.release()

def read(self):
#returning the frames
return self.frame


class HAL:
Expand All @@ -8,15 +40,19 @@ def __init__(self):
# Saving the current path for later use.
# The current path is somehow required everytime for accessing files, when the exercise is running in the docker container.
self.current_path = os.path.dirname(os.path.abspath(__file__))
self.cameraCapture = cv2.VideoCapture(0)
#Custom class object
self.cameraCapture = WebcamStream(id=0)
self.benchmark_vid_capture = cv2.VideoCapture(self.current_path + "/benchmarking/test_vid/video.avi")
self.uploaded_vid_capture = cv2.VideoCapture(self.current_path + "/uploaded_video.mp4")
#path to the ground truth detections directory
self.gt_path = os.path.join(self.current_path, "benchmarking/groundtruths/")
self.frame_number = 0

def getImage(self):
success, frame = self.cameraCapture.read()
#Starting the thread if not started
if(self.cameraCapture.start_flag==False):
self.cameraCapture.start()
frame = self.cameraCapture.read()
return frame

def getBenchmarkVid(self):
Expand Down