def apply_patch(
        self,
        x: np.ndarray,
        patch_external: np.ndarray | None = None,
        foreground: np.ndarray | None = None,
        patch_points: np.ndarray | None = None,
    ) -> np.ndarray:
        """
        A function to apply the learned adversarial texture to videos.

        :param x: Videos of shape NFHWC to apply adversarial texture.
        :param patch_external: External patch to apply to videos `x`.
        :param foreground: Foreground masks of shape NFHWC of boolean values with False/0.0 representing foreground,
                           preventing updates to the texture, and True/1.0 for background, allowing updates to the
                           texture.
        :param patch_points: Array of shape (nb_frames, 4, 2) containing four pairs of integers (height, width)
                             corresponding to the coordinates of the four corners top-left, top-right, bottom-right,
                             bottom-left of the transformed image in the coordinate-system of the original image.
        :return: The videos with adversarial textures.
        """
        import torch

        patch_tensor = (
            torch.Tensor(patch_external).to(self.estimator.device) if patch_external is not None else self._patch
        )
        x_tensor = torch.Tensor(x).to(self.estimator.device)
        if foreground is None:
            foreground_tensor = None
        else:
            foreground_tensor = torch.Tensor(foreground).to(self.estimator.device)

        return (
            self._apply_texture(
                videos=x_tensor, patch=patch_tensor, foreground=foreground_tensor, patch_points=patch_points
            )
            .detach()
            .cpu()
            .numpy()
        )

        A function to apply the learned adversarial texture to videos.

        :param x: Videos of shape NFHWC to apply adversarial texture.
        :param patch_external: External patch to apply to videos `x`.
        :param foreground: Foreground masks of shape NFHWC of boolean values with False/0.0 representing foreground,
                           preventing updates to the texture, and True/1.0 for background, allowing updates to the
                           texture.
        :param patch_points: Array of shape (nb_frames, 4, 2) containing four pairs of integers (height, width)
                             corresponding to the coordinates of the four corners top-left, top-right, bottom-right,
                             bottom-left of the transformed image in the coordinate-system of the original image.
        :return: The videos with adversarial textures.
        
art/attacks/evasion/adversarial_texture/adversarial_texture_pytorch.py