Пример #1
0
def draw_line(image: np.ndarray,
              line: Line2,
              color: Tuple[float, float, float],
              thickness: int = 1) -> None:
    image_extents = Rect2(pos=(0, 0), size=image.shape[1::-1])

    start_point = line.eval_at(x=image_extents.x0)
    end_point = line.eval_at(x=image_extents.x1)

    if not image_extents.contains_point(start_point):
        if start_point.y < image_extents.y0:
            y_to_eval = image_extents.y0
        else:
            y_to_eval = image_extents.y1
        start_point = line.eval_at(y=y_to_eval)

    if not image_extents.contains_point(end_point):
        if end_point.y < image_extents.y0:
            y_to_eval = image_extents.y0
        else:
            y_to_eval = image_extents.y1
        end_point = line.eval_at(y=y_to_eval)

    cv2.line(image,
             pt1=tuple(start_point.as_type(int)),
             pt2=tuple(end_point.as_type(int)),
             color=color,
             thickness=thickness)
Пример #2
0
    def _nudge(self, delta: Tuple[float, float]) -> None:
        line = self.bn_line.get()
        if line is None:
            return

        new_line = Line2(p0=line.p0 + delta, p1=line.p1 + delta)

        self.bn_line.set(new_line)
Пример #3
0
    def _update_dragging_indicator(self, current_cursor_pos: Vector2[float]) -> None:
        if not self._model.is_defining:
            self.view.bn_dragging.set(None)
            return

        self.view.bn_dragging.set(Line2(
            pt0=self._model.begin_define_pos,
            pt1=current_cursor_pos,
        ))
Пример #4
0
    def commit_define(self, end_pos: Vector2[float]) -> None:
        assert self.is_defining
        start_pos = self._begin_define_pos
        self._begin_define_pos = None

        if start_pos == end_pos:
            return

        line = Line2(
            p0=start_pos,
            p1=end_pos,
        )

        self.bn_line.set(line)
Пример #5
0
    def _nudgerot(self, delta: float) -> None:
        """Rotate the currently selected line anticlockwise by `delta` radians.
        """
        line = self.bn_line.get()
        if line is None:
            return

        clip = self._bn_clip.get()
        if clip is not None:
            center_x = (clip.x0 + clip.x1) / 2
        else:
            center_x = line.p0.x

        line_angle = math.atan(line.gradient)
        new_line_angle = line_angle - delta

        new_p0 = line.eval_at(x=center_x)
        new_p1 = new_p0 + (math.cos(new_line_angle), math.sin(new_line_angle))

        new_line = Line2(p0=new_p0, p1=new_p1)

        self.bn_line.set(new_line)