def __init__(self, enabled, log_level=None, width=None, height=None, fps=None, name=None, display_flags=0, display_depth=0): super(PygameStream, self).__init__(enabled, log_level, name) self.fps = fps self.width = width self.height = height if self.fps is None: self.delay = 0.0 else: self.delay = 1 / fps self.display_size = (width, height) if self.width is None or self.height is None or self.fps is None: platform = get_platform() if platform != "mac": os.environ["SDL_VIDEODRIVER"] = "dummy" self.display = "dummy" else: self.display = pygame.display.set_mode(self.display_size, display_flags, display_depth)
def __init__(self, name, width=None, height=None, show=True, skip_count=0, enabled=True): self.file_name = "" self.directory = "" self.full_path = "" self.is_live = None self.name = name self.capture = None self.frame = None self.show = show self.record = False self.enabled = enabled self.fps = 0.0 self.fps_sum = 0.0 self.num_frames = 0 self.length_sec = 0.0 self.length_msec = 0.0 self.start_time = 0.0 self.current_time = 0.0 self.prev_t = None self.width = width self.height = height self.resize_frame = False self.sync_up_error = None self.video_writer = None self.is_recording = False self.start_frame = 0 self.loop_video = False self.frame_skip_count = skip_count platform = get_platform() if platform == "linux": self.key_codes = { 65362: "up", 65364: "down", 65361: "left", 65363: "right", } elif platform == "mac": self.key_codes = { 63232: "up", 63233: "down", 63234: "left", 63235: "right", } else: self.key_codes = {}
def __init__(self, axes_mapping, axes_dead_zones, button_mapping): """ :param axes_mapping: A list of axis names that correspond to the axis number pygame assigns :param axes_dead_zones: If the corresponding axis number is less than a value in this list, it is considered zero :param button_mapping: A list of button names that correspond to the button number pygame assigns """ platform = get_platform() if platform != "mac": os.environ["SDL_VIDEODRIVER"] = "dummy" pygame.init() pygame.joystick.init() # search for all available joysticks and initialize them joysticks = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())] if len(joysticks) == 0: raise JoysticksNotFoundError("No joysticks found!") for joy in joysticks: joy.init() # print(joy.get_name(), joy.get_id(), joy.get_init(), # joy.get_numaxes()) self.axis_to_name = axes_mapping self.button_to_name = button_mapping # create dictionaries that maps names to button/axis IDs self.name_to_axis = self.create_mapping(axes_mapping) self.name_to_button = self.create_mapping(button_mapping) self.dead_zones = [abs(value) for value in axes_dead_zones] self.axis_flipped = [math.copysign(1, value) for value in axes_dead_zones] # current values self.axes = [0.0] * len(axes_mapping) self.buttons = [False] * len(button_mapping) self.dpad = (0, 0) self.axis_changed = [False] * len(axes_mapping) self.prev_buttons = [False] * len(button_mapping) self.prev_dpad = (0, 0) self.t0 = time.time() self.active = False super(BuggyJoystick, self).__init__()
def __init__(self, capture, pipeline=None, enabled=True, debug=False, name=None, enable_slider=False): self.capture = capture if name is None: name = self.capture.name super(CameraViewer, self).__init__(enabled, debug, False, True, name) self.pipeline = pipeline if self.enabled: cv2.namedWindow(self.name) self.key = -1 self.slider_pos = 0 self.slider_name = "frame:" self.enable_slider = enable_slider self.slider_ticks = int(self.capture.capture.get(cv2.CAP_PROP_FRAME_WIDTH) // 3) if self.slider_ticks > self.capture.num_frames: self.slider_ticks = self.capture.num_frames if self.enabled and self.enable_slider: cv2.createTrackbar(self.slider_name, self.name, 0, self.slider_ticks, self.on_slider) platform = get_platform() if platform == "linux": self.key_codes = { 65362: "up", 65364: "down", 65361: "left", 65363: "right", } elif platform == "mac": self.key_codes = { 63232: "up", 63233: "down", 63234: "left", 63235: "right", } else: self.key_codes = {}
def init_recording(self): if not self.is_recording: if self.file_name.endswith('avi'): codec = 'MJPG' elif self.file_name.endswith('mp4'): if get_platform() == 'mac': codec = 'mp4v' else: # TODO: Figure out mp4 recording in ubuntu # codec = 'X264' codec = 'MJPG' self.file_name = self.file_name[:-3] + "avi" self.full_path = self.full_path[:-3] + "avi" else: raise ValueError("Invalid file format") fourcc = cv2.VideoWriter_fourcc(*codec) self.video_writer = cv2.VideoWriter() self.video_writer.open(self.full_path, fourcc, self.fps_sum / self.num_frames, (self.width, self.height), True) self.is_recording = True
def __init__(self, width=None, height=None, capture_number=None, enabled=True, debug=False, name=None, skip_count=0, logger=None, video_recorder=None): super(CvCamera, self).__init__(enabled, debug, True, False, name, logger, video_recorder) self.capture_number = capture_number self.width = width self.height = height self.resize_frame = False self.skip_count = skip_count self.key = -1 platform = get_platform() if platform == "linux": self.key_codes = { 65362: "up", 65364: "down", 65361: "left", 65363: "right", } elif platform == "mac": self.key_codes = { 63232: "up", 63233: "down", 63234: "left", 63235: "right", } else: self.key_codes = {}
def __init__(self, enabled=True, log_level=None, name=None, enable_slider=False): super(CameraViewer, self).__init__(enabled, name, log_level) if self.enabled: cv2.namedWindow(self.name) self.key = -1 self.slider_pos = 0 self.slider_name = "frame:" self.enable_slider = enable_slider self.slider_ticks = 0 self.capture = None self.pipeline = None platform = get_platform() if platform == "linux": self.key_codes = { 65362: "up", 65364: "down", 65361: "left", 65363: "right", } elif platform == "mac": self.key_codes = { 63232: "up", 63233: "down", 63234: "left", 63235: "right", } else: self.key_codes = {}
def start_recording(self, capture): if self.enabled: self.make_dir() self.capture = capture self.width = capture.width self.height = capture.height if self.file_name.endswith('avi'): codec = 'MJPG' elif self.file_name.endswith('mp4'): if get_platform() == 'mac': codec = 'MP4V' else: # TODO: Figure out mp4 recording in linux # codec = 'DIVX' codec = 'MJPG' self.file_name = self.file_name[:-3] + "avi" self.full_path = self.full_path[:-3] + "avi" else: raise ValueError("Invalid file format") self.fourcc = cv2.VideoWriter_fourcc(*codec) self.video_writer = cv2.VideoWriter() self.is_recording = True