Esempio n. 1
0
 def _initialize_tkinter(self):
     """ Initialize a standalone tkinter instance. """
     logger.debug("Initializing tkinter")
     for widget in ("TButton", "TCheckbutton", "TRadiobutton"):
         self.unbind_class(widget, "<Key-space>")
     initialize_config(self, None, None)
     initialize_images()
     get_config().set_geometry(940, 600, fullscreen=True)
     self.title("Faceswap.py - Visual Alignments")
     logger.debug("Initialized tkinter")
Esempio n. 2
0
    def __init__(self, input_location):
        logger.debug("Initializing %s: (input_location: %s)",
                     self.__class__.__name__, input_location)
        self._tk_vars = self._get_tk_vars()

        self._is_video = self._check_input(input_location)
        self._frame_count = 0  # set by FrameLoader
        self._frame_display_dims = (int(round(896 * get_config().scaling_factor)),
                                    int(round(504 * get_config().scaling_factor)))
        self._current_frame = dict(image=None,
                                   scale=None,
                                   interpolation=None,
                                   display_dims=None,
                                   filename=None)
        logger.debug("Initialized %s", self.__class__.__name__)
Esempio n. 3
0
 def face_size(self):
     """ int: The currently selected thumbnail size in pixels """
     scaling = get_config().scaling_factor
     size = self._sizes[self._globals.tk_faces_size.get().lower().replace(
         " ", "")]
     scaled = size * scaling
     return int(round(scaled / 2) * 2)
Esempio n. 4
0
    def __init__(self, parent, tk_globals, tk_action_vars, detected_faces,
                 display_frame, event):
        logger.debug(
            "Initializing %s: (parent: %s, tk_globals: %s, tk_action_vars: %s, "
            "detected_faces: %s, display_frame: %s, event: %s)",
            self.__class__.__name__, parent, tk_globals, tk_action_vars,
            detected_faces, display_frame, event)
        super().__init__(
            parent,
            bd=0,
            highlightthickness=0,
            bg=get_config().user_theme["group_panel"]["panel_background"])
        self.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, anchor=tk.E)
        self._sizes = dict(tiny=32,
                           small=64,
                           medium=96,
                           large=128,
                           extralarge=192)

        self._globals = tk_globals
        self._tk_optional_annotations = tk_action_vars
        self._event = event
        self._display_frame = display_frame
        self._grid = Grid(self, detected_faces)
        self._view = Viewport(self, detected_faces.tk_edited)
        self._annotation_colors = dict(mesh=self.get_muted_color("Mesh"),
                                       box=self.control_colors["ExtractBox"])

        ContextMenu(self, detected_faces)
        self._bind_mouse_wheel_scrolling()
        self._set_tk_callbacks(detected_faces)
        logger.debug("Initialized %s", self.__class__.__name__)
Esempio n. 5
0
    def _resize(self, event):
        """ Resizes the landmarks contained within an extract box on a corner anchor drag event.

        Parameters
        ----------
        event: :class:`tkinter.Event`
            The tkinter mouse event.
        """
        face_idx = self._mouse_location[1]
        face_tag = "eb_box_face_{}".format(face_idx)
        position = np.array((event.x, event.y))
        box = np.array(self._canvas.coords(face_tag))
        center = np.array((sum(box[0::2]) / 4, sum(box[1::2]) / 4))
        if not self._check_in_bounds(center, box, position):
            logger.trace("Drag out of bounds. Not updating")
            self._drag_data["current_location"] = position
            return

        start = self._drag_data["current_location"]
        distance = ((np.linalg.norm(center - start) -
                     np.linalg.norm(center - position)) *
                    get_config().scaling_factor)
        size = ((box[2] - box[0])**2 + (box[3] - box[1])**2)**0.5
        scale = 1 - (distance / size)
        logger.trace(
            "face_index: %s, center: %s, start: %s, position: %s, distance: %s, "
            "size: %s, scale: %s", face_idx, center, start, position, distance,
            size, scale)
        if size * scale < 20:
            # Don't over shrink the box
            logger.trace("Box would size to less than 20px. Not updating")
            self._drag_data["current_location"] = position
            return

        self._det_faces.update.landmarks_scale(self._globals.frame_index,
                                               face_idx, scale,
                                               self.scale_from_display(center))
        self._drag_data["current_location"] = position