def __init__(self, capture, width, height, fps): self.device = None self.width = width self.height = height self.fps = fps self.device = capture escapi.count_capture_devices() self.name = str(escapi.device_name(self.device).decode('utf8')) self.buffer = escapi.init_camera(self.device, self.width, self.height, self.fps) escapi.do_capture(self.device)
"When set to 1, experimental blink detection and gaze tracking are enabled, which makes things slightly slower", default=1) parser.add_argument( "--face-id-offset", type=int, help= "When set, this offset is added to all face ids, which can be useful for mixing tracking data from multiple network sources", default=0) args = parser.parse_args() os.environ["OMP_NUM_THREADS"] = "1" if os.name == 'nt' and args.list_cameras > 0: import escapi escapi.init() camera_count = escapi.count_capture_devices() if args.list_cameras == 1: print("Available cameras:") for i in range(camera_count): camera_name = escapi.device_name(i).decode() if args.list_cameras == 1: print(f"{i}: {camera_name}") else: print(camera_name) sys.exit(0) import numpy as np import time import cv2 import socket import struct
def __init__(self, capture, raw_rgb, width, height, fps, use_dshowcapture=False, dcap=None): self.reader = None self.name = str(capture) try: if raw_rgb > 0: self.reader = RawReader(width, height) elif os.path.exists(capture): self.reader = VideoReader(capture) elif capture == str(try_int(capture)): if os.name == 'nt': # Try with DShowCapture good = True name = "" try: if use_dshowcapture: self.reader = DShowCaptureReader(int(capture), width, height, fps, dcap=dcap) name = self.reader.name good = test_reader(self.reader) self.name = name else: good = False except: print("DShowCapture exception: ") traceback.print_exc() good = False if good: return # Try with Escapi good = True try: print( f"DShowCapture failed. Falling back to escapi for device {name}.", file=sys.stderr) escapi.init() devices = escapi.count_capture_devices() found = None for i in range(devices): escapi_name = str( escapi.device_name(i).decode('utf8')) if name == escapi_name: found = i if found is None: good = False else: print(f"Found device {name} as {i}.", file=sys.stderr) self.reader = EscapiReader(found, width, height, fps) good = test_reader(self.reader) except: print("Escapi exception: ") traceback.print_exc() good = False if good: return # Try with OpenCV print( f"Escapi failed. Falling back to OpenCV. If this fails, please change your camera settings.", file=sys.stderr) self.reader = OpenCVReader(int(capture), width, height, fps) self.name = self.reader.name else: self.reader = OpenCVReader(int(capture), width, height, fps) except Exception as e: print("Error: " + str(e)) if self.reader is None or not self.reader.is_open(): print("There was no valid input.") sys.exit(0)