Пример #1
0
    def on_start(self, weak_heap: BackendWeakHeap,
                 reemit_frame_signal: BackendSignal, bc_in: BackendConnection,
                 bc_out: BackendConnection, animatables_path: Path):
        self.weak_heap = weak_heap
        self.reemit_frame_signal = reemit_frame_signal
        self.bc_in = bc_in
        self.bc_out = bc_out
        self.animatables_path = animatables_path

        self.pending_bcd = None

        self.tpsmm_model = None

        self.animatable_img = None
        self.driving_ref_kp = None
        self.last_driving_kp = None

        lib_os.set_timer_resolution(1)

        state, cs = self.get_state(), self.get_control_sheet()

        cs.device.call_on_selected(self.on_cs_device)
        cs.animatable.call_on_selected(self.on_cs_animatable)

        cs.animator_face_id.call_on_number(self.on_cs_animator_face_id)
        cs.relative_mode.call_on_flag(self.on_cs_relative_mode)
        cs.relative_power.call_on_number(self.on_cs_relative_power)
        cs.update_animatables.call_on_signal(self.update_animatables)
        cs.reset_reference_pose.call_on_signal(self.on_cs_reset_reference_pose)

        cs.device.enable()
        cs.device.set_choices(TPSMM.get_available_devices(),
                              none_choice_name='@misc.menu_select')
        cs.device.select(state.device)
Пример #2
0
    def on_start(self, weak_heap: BackendWeakHeap,
                 reemit_frame_signal: BackendSignal, bc_in: BackendConnection,
                 bc_out: BackendConnection):
        self.weak_heap = weak_heap
        self.reemit_frame_signal = reemit_frame_signal
        self.bc_in = bc_in
        self.bc_out = bc_out
        self.pending_bcd = None
        self.out_merged_frame = None

        lib_os.set_timer_resolution(1)

        state, cs = self.get_state(), self.get_control_sheet()
        cs.device.call_on_selected(self.on_cs_device)
        cs.face_x_offset.call_on_number(self.on_cs_face_x_offset)
        cs.face_y_offset.call_on_number(self.on_cs_face_y_offset)
        cs.face_scale.call_on_number(self.on_cs_face_scale)

        cs.face_mask_source.call_on_flag(self.on_cs_face_mask_source)
        cs.face_mask_celeb.call_on_flag(self.on_cs_face_mask_celeb)
        cs.face_mask_lmrks.call_on_flag(self.on_cs_face_mask_lmrks)

        cs.face_mask_erode.call_on_number(self.on_cs_mask_erode)
        cs.face_mask_blur.call_on_number(self.on_cs_mask_blur)

        cs.color_compression.call_on_number(self.on_cs_color_compression)
        cs.face_opacity.call_on_number(self.on_cs_face_opacity)

        cs.device.enable()
        cs.device.set_choices(['CPU'] + lib_cl.get_available_devices_info(),
                              none_choice_name='@misc.menu_select')
        cs.device.select(state.device if state.device is not None else 'CPU')
Пример #3
0
    def on_start(self, weak_heap : BackendWeakHeap, reemit_frame_signal : BackendSignal,
                       bc_in : BackendConnection,
                       bc_out : BackendConnection,
                       ):
        self.weak_heap = weak_heap
        self.reemit_frame_signal = reemit_frame_signal
        self.bc_in = bc_in
        self.bc_out = bc_out
        self.pending_bcd = None
        self.opencv_lbf = None
        self.google_facemesh = None
        self.insightface_2d106 = None
        self.temporal_lmrks = []

        lib_os.set_timer_resolution(1)

        state, cs = self.get_state(), self.get_control_sheet()
        cs.marker_type.call_on_selected(self.on_cs_marker_type)
        cs.device.call_on_selected(self.on_cs_devices)
        cs.marker_coverage.call_on_number(self.on_cs_marker_coverage)
        cs.temporal_smoothing.call_on_number(self.on_cs_temporal_smoothing)

        cs.marker_type.enable()
        cs.marker_type.set_choices(MarkerType, MarkerTypeNames, none_choice_name=None)
        cs.marker_type.select(state.marker_type if state.marker_type is not None else MarkerType.GOOGLE_FACEMESH)
Пример #4
0
    def on_start(self, weak_heap: BackendWeakHeap,
                 reemit_frame_signal: BackendSignal,
                 bc_out: BackendConnection):
        self.weak_heap = weak_heap
        self.reemit_frame_signal = reemit_frame_signal
        self.bc_out = bc_out
        self.bcd_uid = 0
        self.pending_bcd = None
        self.fp: lib_player.FramePlayer = None
        self.last_p_frame = None
        lib_os.set_timer_resolution(4)

        state, cs = self.get_state(), self.get_control_sheet()

        cs.input_type.call_on_selected(self.on_cs_input_type_selected)
        cs.input_paths.call_on_paths(self.on_cs_input_paths)
        cs.target_width.call_on_number(self.on_cs_target_width)
        cs.fps.call_on_number(self.on_cs_fps)
        cs.is_realtime.call_on_flag(self.on_cs_is_realtime)
        cs.is_autorewind.call_on_flag(self.on_cs_is_autorewind)
        cs.frame_index.call_on_number(self.on_cs_frame_index)

        cs.play.call_on_signal(self.on_cs_play)
        cs.pause.call_on_signal(self.on_cs_pause)
        cs.seek_begin.call_on_signal(self.on_cs_seek_begin)
        cs.seek_backward.call_on_signal(self.on_cs_seek_backward)
        cs.seek_forward.call_on_signal(self.on_cs_seek_forward)
        cs.seek_end.call_on_signal(self.on_cs_seek_end)

        cs.input_type.enable()
        cs.input_type.set_choices(InputType, InputTypeNames)
        cs.input_type.select(state.input_type)
Пример #5
0
    def on_start(self, weak_heap: BackendWeakHeap,
                 reemit_frame_signal: BackendSignal, bc_in: BackendConnection,
                 bc_out: BackendConnection):
        self.weak_heap = weak_heap
        self.reemit_frame_signal = reemit_frame_signal
        self.bc_in = bc_in
        self.bc_out = bc_out
        self.pending_bcd = None

        lib_os.set_timer_resolution(1)

        state, cs = self.get_state(), self.get_control_sheet()
        cs.median_blur_per.call_on_number(self.on_cs_median_blur_per)
        cs.degrade_bicubic_per.call_on_number(self.on_cs_degrade_bicubic_per)

        cs.median_blur_per.enable()
        cs.median_blur_per.set_config(
            lib_csw.Number.Config(min=0,
                                  max=100,
                                  step=1,
                                  decimals=0,
                                  allow_instant_update=True))
        cs.median_blur_per.set_number(
            state.median_blur_per if state.median_blur_per is not None else 0)

        cs.degrade_bicubic_per.enable()
        cs.degrade_bicubic_per.set_config(
            lib_csw.Number.Config(min=0,
                                  max=100,
                                  step=1,
                                  decimals=0,
                                  allow_instant_update=True))
        cs.degrade_bicubic_per.set_number(
            state.degrade_bicubic_per if state.
            degrade_bicubic_per is not None else 0)
Пример #6
0
    def on_start(self, weak_heap: BackendWeakHeap,
                 reemit_frame_signal: BackendSignal, bc_in: BackendConnection,
                 bc_out: BackendConnection, dfm_models_path: Path):
        self.weak_heap = weak_heap
        self.reemit_frame_signal = reemit_frame_signal
        self.bc_in = bc_in
        self.bc_out = bc_out
        self.dfm_models_path = dfm_models_path

        self.pending_bcd = None

        self.dfm_model_initializer = None
        self.dfm_model = None

        lib_os.set_timer_resolution(1)

        state, cs = self.get_state(), self.get_control_sheet()

        cs.model.call_on_selected(self.on_cs_model)
        cs.device.call_on_selected(self.on_cs_device)
        cs.swap_all_faces.call_on_flag(self.on_cs_swap_all_faces)
        cs.face_id.call_on_number(self.on_cs_face_id)
        cs.morph_factor.call_on_number(self.on_cs_morph_factor)
        cs.presharpen_amount.call_on_number(self.on_cs_presharpen_amount)
        cs.pre_gamma_red.call_on_number(self.on_cs_pre_gamma_red)
        cs.pre_gamma_green.call_on_number(self.on_cs_pre_gamma_green)
        cs.pre_gamma_blue.call_on_number(self.on_cs_pre_gamma_blue)
        cs.post_gamma_red.call_on_number(self.on_cs_post_gamma_red)
        cs.post_gamma_blue.call_on_number(self.on_cs_post_gamma_blue)
        cs.post_gamma_green.call_on_number(self.on_cs_post_gamma_green)
        cs.two_pass.call_on_flag(self.on_cs_two_pass)

        cs.device.enable()
        cs.device.set_choices(DFLive.get_available_devices(),
                              none_choice_name='@misc.menu_select')
        cs.device.select(state.device)
Пример #7
0
    def on_start(self, weak_heap: BackendWeakHeap,
                 reemit_frame_signal: BackendSignal, bc_in: BackendConnection,
                 bc_out: BackendConnection):
        self.weak_heap = weak_heap
        self.reemit_frame_signal = reemit_frame_signal
        self.bc_in = bc_in
        self.bc_out = bc_out
        self.pending_bcd = None
        lib_os.set_timer_resolution(1)

        state, cs = self.get_state(), self.get_control_sheet()
        cs.align_mode.call_on_selected(self.on_cs_align_mode)
        cs.face_coverage.call_on_number(self.on_cs_face_coverage)
        cs.resolution.call_on_number(self.on_cs_resolution)
        cs.exclude_moving_parts.call_on_flag(self.on_cs_exclude_moving_parts)
        cs.head_mode.call_on_flag(self.on_cs_head_mode)
        cs.freeze_z_rotation.call_on_flag(self.on_cs_freeze_z_rotation)

        cs.x_offset.call_on_number(self.on_cs_x_offset)
        cs.y_offset.call_on_number(self.on_cs_y_offset)

        cs.align_mode.enable()
        cs.align_mode.set_choices(AlignMode, AlignModeNames)
        cs.align_mode.select(state.align_mode if state.
                             align_mode is not None else AlignMode.FROM_POINTS)

        cs.face_coverage.enable()
        cs.face_coverage.set_config(
            lib_csw.Number.Config(min=0.1,
                                  max=4.0,
                                  step=0.1,
                                  decimals=1,
                                  allow_instant_update=True))
        cs.face_coverage.set_number(
            state.face_coverage if state.face_coverage is not None else 2.2)

        cs.resolution.enable()
        cs.resolution.set_config(
            lib_csw.Number.Config(min=16,
                                  max=1024,
                                  step=16,
                                  decimals=0,
                                  allow_instant_update=True))
        cs.resolution.set_number(
            state.resolution if state.resolution is not None else 224)

        cs.exclude_moving_parts.enable()
        cs.exclude_moving_parts.set_flag(
            state.exclude_moving_parts if state.
            exclude_moving_parts is not None else True)

        cs.head_mode.enable()
        cs.head_mode.set_flag(
            state.head_mode if state.head_mode is not None else False)

        cs.freeze_z_rotation.enable()
        cs.freeze_z_rotation.set_flag(state.freeze_z_rotation if state.
                                      freeze_z_rotation is not None else False)

        cs.x_offset.enable()
        cs.x_offset.set_config(
            lib_csw.Number.Config(min=-1,
                                  max=1,
                                  step=0.01,
                                  decimals=2,
                                  allow_instant_update=True))
        cs.x_offset.set_number(
            state.x_offset if state.x_offset is not None else 0)

        cs.y_offset.enable()
        cs.y_offset.set_config(
            lib_csw.Number.Config(min=-1,
                                  max=1,
                                  step=0.01,
                                  decimals=2,
                                  allow_instant_update=True))
        cs.y_offset.set_number(
            state.y_offset if state.y_offset is not None else 0)
Пример #8
0
    def on_start(self, weak_heap : BackendWeakHeap, reemit_frame_signal : BackendSignal,
                       bc_in : BackendConnection,
                       save_default_path : Path):
        self.weak_heap = weak_heap
        self.reemit_frame_signal = reemit_frame_signal
        self.bc_in = bc_in

        self.fps_counter = lib_time.FPSCounter()

        self.buffered_frames = lib_logic.DelayedBuffers()
        self.is_show_window = False

        self.prev_frame_num = -1

        self._wnd_name = 'DeepFaceLive output'
        self._wnd_showing = False

        self._streamer = FFMPEGStreamer()

        lib_os.set_timer_resolution(1)

        state, cs = self.get_state(), self.get_control_sheet()

        cs.source_type.call_on_selected(self.on_cs_source_type)
        cs.show_hide_window.call_on_signal(self.on_cs_show_hide_window_signal)
        cs.aligned_face_id.call_on_number(self.on_cs_aligned_face_id)
        cs.target_delay.call_on_number(self.on_cs_target_delay)
        cs.save_sequence_path.call_on_paths(self.on_cs_save_sequence_path)
        cs.save_fill_frame_gap.call_on_flag(self.on_cs_save_fill_frame_gap)
        cs.is_streaming.call_on_flag(self.on_cs_is_streaming)
        cs.stream_addr.call_on_text(self.on_cs_stream_addr)
        cs.stream_port.call_on_number(self.on_cs_stream_port)

        cs.source_type.enable()
        cs.source_type.set_choices(SourceType, ViewModeNames, none_choice_name='@misc.menu_select')
        cs.source_type.select(state.source_type)

        cs.target_delay.enable()
        cs.target_delay.set_config(lib_csw.Number.Config(min=0, max=5000, step=100, decimals=0, allow_instant_update=True))
        cs.target_delay.set_number(state.target_delay if state.target_delay is not None else 500)

        cs.avg_fps.enable()
        cs.avg_fps.set_config(lib_csw.Number.Config(min=0, max=240, decimals=1, read_only=True))
        cs.avg_fps.set_number(0)

        cs.show_hide_window.enable()
        self.hide_window()

        if state.is_showing_window is None:
            state.is_showing_window = False

        if state.is_showing_window:
            state.is_showing_window = not state.is_showing_window
            cs.show_hide_window.signal()

        cs.save_sequence_path.enable()
        cs.save_sequence_path.set_config( lib_csw.Paths.Config.Directory('Choose output sequence directory', directory_path=save_default_path) )
        cs.save_sequence_path.set_paths(state.sequence_path)

        cs.save_fill_frame_gap.enable()
        cs.save_fill_frame_gap.set_flag(state.save_fill_frame_gap if state.save_fill_frame_gap is not None else True )

        cs.is_streaming.enable()
        cs.is_streaming.set_flag(state.is_streaming if state.is_streaming is not None else False )

        cs.stream_addr.enable()
        cs.stream_addr.set_text(state.stream_addr if state.stream_addr is not None else '127.0.0.1')

        cs.stream_port.enable()
        cs.stream_port.set_config(lib_csw.Number.Config(min=1, max=9999, decimals=0, allow_instant_update=True))
        cs.stream_port.set_number(state.stream_port if state.stream_port is not None else 1234)
Пример #9
0
    def on_start(self, weak_heap: BackendWeakHeap, bc_out: BackendConnection):
        self.weak_heap = weak_heap
        self.bc_out = bc_out
        self.bcd_uid = 0
        self.pending_bcd = None
        self.vcap = None
        self.last_timestamp = 0
        lib_os.set_timer_resolution(4)

        state, cs = self.get_state(), self.get_control_sheet()

        cs.driver.call_on_selected(self.on_cs_driver_selected)
        cs.device_idx.call_on_selected(self.on_cs_device_idx_selected)
        cs.resolution.call_on_selected(self.on_cs_resolution_selected)
        cs.fps.call_on_number(self.on_cs_fps)
        cs.rotation.call_on_selected(self.on_cs_rotation_selected)
        cs.flip_horizontal.call_on_flag(self.on_cs_flip_horizontal)
        cs.open_settings.call_on_signal(self.on_cs_open_settings)
        cs.load_settings.call_on_signal(self.on_cs_load_settings)
        cs.save_settings.call_on_signal(self.on_cs_save_settings)

        cs.driver.enable()
        cs.driver.set_choices(_DriverType,
                              _DriverType_names,
                              none_choice_name='@misc.menu_select')
        cs.driver.select(state.driver if state.driver is not None else
                         _DriverType.DSHOW if platform.system() ==
                         'Windows' else _DriverType.COMPATIBLE)

        if platform.system() == 'Windows':
            from xlib.api.win32 import ole32
            from xlib.api.win32 import dshow
            ole32.CoInitializeEx(0, 0)
            choices = [
                f'{idx} : {name}' for idx, name in enumerate(
                    dshow.get_video_input_devices_names())
            ]
            choices += [f'{idx}' for idx in range(len(choices), 16)]
            ole32.CoUninitialize()
        else:
            choices = [f'{idx}' for idx in range(16)]

        cs.device_idx.enable()
        cs.device_idx.set_choices(choices,
                                  none_choice_name='@misc.menu_select')
        cs.device_idx.select(state.device_idx)

        cs.resolution.enable()
        cs.resolution.set_choices(_ResolutionType,
                                  _ResolutionType_names,
                                  none_choice_name=None)
        cs.resolution.select(state.resolution if state.resolution is not None
                             else _ResolutionType.RES_640x480)

        if state.device_idx is not None and \
           state.driver is not None:

            cv_api = {
                _DriverType.COMPATIBLE: cv2.CAP_ANY,
                _DriverType.DSHOW: cv2.CAP_DSHOW,
                _DriverType.MSMF: cv2.CAP_MSMF,
                _DriverType.GSTREAMER: cv2.CAP_GSTREAMER,
            }[state.driver]

            vcap = cv2.VideoCapture(state.device_idx, cv_api)
            if vcap.isOpened():
                self.vcap = vcap
                w, h = _ResolutionType_wh[state.resolution]

                vcap.set(cv2.CAP_PROP_FRAME_WIDTH, w)
                vcap.set(cv2.CAP_PROP_FRAME_HEIGHT, h)

            if vcap.isOpened():
                cs.fps.enable()
                cs.fps.set_config(
                    lib_csw.Number.Config(min=0,
                                          max=240,
                                          step=1.0,
                                          decimals=2,
                                          zero_is_auto=True,
                                          allow_instant_update=False))
                cs.fps.set_number(state.fps if state.fps is not None else 0)

                cs.rotation.enable()
                cs.rotation.set_choices(_RotationType,
                                        _RotationType_names,
                                        none_choice_name=None)
                cs.rotation.select(state.rotation if state.rotation is not None
                                   else _RotationType.ROTATION_0)

                cs.flip_horizontal.enable()
                cs.flip_horizontal.set_flag(
                    state.flip_horizontal if state.
                    flip_horizontal is not None else False)

                if platform.system() == 'Windows':
                    cs.open_settings.enable()

                cs.load_settings.enable()
                cs.save_settings.enable()
            else:
                cs.device_idx.unselect()