Skip to content
Snippets Groups Projects
Commit 3b7cdc75 authored by David's avatar David
Browse files

Small bugfixes

parent a4d8764e
No related branches found
No related tags found
No related merge requests found
*.bak
pickled_fingerslist
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
......
import pickle
from os.path import exists
from pathlib import Path
class FingersGenerator:
picklefile = r"../.pickled_fingerslist"
picklefile = r"pickled_fingerslist"
def __init__(self) -> None:
pass
......@@ -12,8 +12,9 @@ class FingersGenerator:
import Finger
# The FingersList variable is stored in a pickle file as it is constant, there is no need to create the list
# every time the program runs
if not exists(self.picklefile):
path = Path(self.picklefile)
print(path.is_file())
if not path.is_file():
# Creates the fingers
Thumb = Finger.Finger(name = "Thumb", finger_id=1, ids=[1,2,3,4])
......
......@@ -19,9 +19,6 @@ import cv2
import time
from pynput import keyboard
import modules.HandDetector as HandDetector
import modules.GestureLibs.GestureDetector as GestureDetector
import modules.GestureLibs.GestureGenerator as GestureGenerator
import modules.FingersGenerator as FingersGenerator
'''
TODO
......@@ -44,14 +41,16 @@ def get_arguments():
debug = True
else:
debug = False
camera_dir = os.environ["CAMERA_DIR"]
if camera_dir == "":
try:
camera_dir = os.environ["CAMERA_DIR"]
except KeyError:
camera_dir = "/dev/video0"
print("No camera directory specified, going with default /dev/video0")
config_path = os.environ["CONFIG_PATH"]
if config_path == "":
try:
config_path = os.environ["CONFIG_PATH"]
except KeyError:
config_path = ".config"
print("config file not specified, defaulting to '.config'")
......@@ -68,14 +67,15 @@ class Run:
self.camera_dir = camera_dir
self.config = config_path
global FingersGenerator
import modules.FingersGenerator as FingersGenerator
FingersGenerator = FingersGenerator.FingersGenerator()
self.FingersList = FingersGenerator.create_fingers()
global GestureGenerator
import modules.GestureLibs.GestureGenerator as GestureGenerator
GestureGenerator = GestureGenerator.GestureGenerator(self.config)
self.GestureList = GestureGenerator.read_config()
global GestureDetector
import modules.GestureLibs.GestureDetector as GestureDetector
GestureDetector = GestureDetector.GestureDetector()
GestureDetector.parse_fingertips()
......@@ -84,28 +84,34 @@ class Run:
global logging_list
global fps_list
capture = cv2.VideoCapture(0)
capture = cv2.VideoCapture(self.camera_dir)
detector = HandDetector.HandDetector()
prevTime = 0
currTime = 0
try:
while True:
_, frame = capture.read()
frame = cv2.flip(frame, 1)
frame = detector.fdHands(frame)
while True:
_, frame = capture.read()
frame = cv2.flip(frame, 1)
frame = detector.fdHands(frame)
lmList = detector.fdPositions(frame)
logging_list.append(lmList)
if self.debug:
currTime = time.time()
fps = 1 / (currTime-prevTime)
prevTime = currTime
fps_list.append(fps)
lmList = detector.fdPositions(frame)
logging_list.append(lmList)
cv2.putText(frame, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3, (0,0,255), thickness=3)
cv2.imshow("Video", frame)
cv2.waitKey(1)
if self.debug:
currTime = time.time()
fps = 1 / (currTime-prevTime)
prevTime = currTime
fps_list.append(fps)
cv2.putText(frame, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3, (0,0,255), thickness=3)
cv2.imshow("Video", frame)
cv2.waitKey(1)
except BaseException as e:
print(e)
print("Video ended")
class ProcessController:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment