AOP SDK 开发指南
DDL

ddl

以下为AOP中类和方法的一些说明

class ddl.builtins.DistributedFile(*args, **kwds)

Bases: Serializable, Generic[FMT]

async classmethod from_fd_async(fd, format=None)

根据文件句柄获取文件类型对象, 文件句柄需要由用户自己关闭

  • Parameters:
    • fd (aiofiles.threadpool.binary.AsyncBufferedReader) – 文件句柄
    • format (Optional [**FILE_FORMAT ] , optional) – 文件格式(如:jpg, png, txt…). Defaults to None.
  • Returns: Image 对象
  • Return type: Self
  • Example:
>>> async with aiofiles.open('img.jpg', 'rb') as aio_fd:
...     img = await Image.from_fd_async(aio_fd)

async classmethod from_path_async(path, format=None)

根据传入的本地文件路径获取文件对象

  • Parameters:
    • path (Union [**str , Path ]) – 文件路径
    • format (Optional [**FILE_FORMAT ] , optional) – 文件格式. Defaults to None.
  • Returns: Image 对象
  • Return type: Self
  • Example:
>>> img = await Image.from_path_async(path, format = 'jpg')

async classmethod from_bytes_async(binary_data, format=None)

根据文件的二进制内容获取文件类型对象

  • Parameters:
    • binary_data (bytes) – 二进制数据
    • format (Optional [**FILE_FORMAT ] , optional) – 文件格式. Defaults to None.
  • Returns: Image 对象
  • Return type: Self
  • Example:
>>> with open('img.jpg', 'rb') as f:
...     b = f.read()
...     img = await Image.from_bytes_async(b, format = 'jpg')

async classmethod from_url_async(url, format=None)

根据公开的网络地址获取文件类型对象

  • Parameters:

    • url (str) – 文件 url 地址
    • format (Optional [**FILE_FORMAT ] , optional) – 文件格式. Defaults to None.
  • Returns: Image 对象

  • Return type: Self

  • Example:

>>> url = "www.example.com/img.jpg"
>>> img = await Image.from_url_async(url, format = 'jpg')

async read_bytes_async()

异步读取文件的二进制内容

  • Returns: 文件二进制内容

  • Return type: bytes

  • Example:

>>> img = await Image.from_path_async(path, format = 'jpg')
>>> b = await img.read_bytes_async()

property format : FMT

文件格式

property size : int

文件尺寸, 单位是字节数 (Bytes)

close()

删除本地缓存的临时文件

class ddl.builtins.Image(*args, **kwds)

Bases: DistributedFile[Literal[‘jpg’, ‘bmp’, ‘png’, ‘webp’, ‘gif’]]

async classmethod from_raw_image_async(fd, width, height, channels, format=None, compress_algorithm=None)

根据文件句柄,存储并获取 builtins.Image 对象,可选压缩图片

  • Parameters:

    • fd (aiofiles.threadpool.binary.AsyncBufferedReader) – 异步文件句柄,使用 aiofiles.open 获取
    • width (int) – 分辨率宽度
    • height (int) – 分辨率高度
    • channels (int) – 图片通道数
    • format (Optional [**RAW_IMAGE_FORMAT ] , optional) – 图片格式. Defaults to None.
    • compress_algorithm (Optional [**COMPRESS_ALGORITHM ] , optional) – 压缩类型(目前仅支持 JPEG 格式压缩),默认是不压缩. Defaults to None.
  • Raises:

    • TypeError – 传入图片格式错误
    • ValueError – 压缩算法类型错误
  • Returns: builtins.Image 对象

  • Return type: Self

  • Example:

>>> async with aiofiles.open('img.raw', 'rb') as aio_fd:
...     img = await Image.from_raw_image_async(aio_fd, 1280, 1920, 3, 'raw', 'JPEG')

async classmethod from_mat_async(mat, compress_algorithm=None, img_encode_format='png')

根据 cv2.Mat 或 numpy.adarray 对象,存储并获取压缩后的 builtins.Image 对象

  • Parameters:

    • mat (Mat | np.ndarray [**np.uint8 , np.dtype [**np.uint8 ] ]) – cv2.Mat 或者 numpy.adarray 对象
    • compress_algorithm (Optional [**COMPRESS_ALGORITHM ]) – 压缩类型,目前仅支持 JPEG 类型
  • Returns: builtins.Image 对象

  • Return type: Self

  • Example:

>>> mat = cv2.imread('img.png')
>>> img = await Image.from_mat_async(mat, 'JPEG') # 使用JPEG压缩
>>> img = await Image.from_mat_async(mat) # 不使用JPEG压缩

async classmethod from_raw_image_path_async(path, width, height, channels, format=None, compress_algorithm=None)

根据文件路径,存储并获取 builtins.Image 对象,可选压缩图片

  • Parameters:
    • path (Union [**str , Path ]) – 文件路径
    • width (int) – 分辨率宽度
    • height (int) – 分辨率高度
    • channels (int) – 图片通道数
    • format (Optional [**RAW_IMAGE_FORMAT ] , optional) – 图片格式. Defaults to None.
    • compress_algorithm (Optional [**COMPRESS_ALGORITHM ] , optional) – 压缩类型(目前仅支持 JPEG 格式压缩),默认是不压缩. Defaults to None.
  • Returns: builtins.Image 对象
  • Return type: Self
  • Example:
>>> img = await Image.from_raw_image_path_async('img.raw', 1280, 1920, 3, 'raw', 'JPEG')

class ddl.builtins.Video(*args, **kwds)

Bases: DistributedFile[Literal[‘mp4’, ‘mov’, ‘mkv’]]

class ddl.builtins.Audio(*args, **kwds)

Bases: DistributedFile[Literal[‘mp3’, ‘wav’, ‘ogg’]]