Skip to content
Open
Changes from 1 commit
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
34 changes: 32 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,33 @@
import cv2
import os
import threading
from threading import *


class WebcamStream:
def __init__(self,id=0):
self.id = id
self.cap = cv2.VideoCapture(id)
self.start_flag = False


def start(self):
self.t = Thread(target=self.update)
self.t.daemon = True
self.t.start()
self.start_flag = True


def update(self):
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):
return self.frame


class HAL:
Expand All @@ -8,15 +36,17 @@ 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)
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()
if(self.cameraCapture.start_flag==False):
self.cameraCapture.start()
frame = self.cameraCapture.read()
return frame

def getBenchmarkVid(self):
Expand Down