from iiif_components import IIIFManifest
from stitching import scan

import cv2 as cv

class IIIFImageStitcher(IIIFManifest):
    def stitch_images(self, indices: list = [], sequence_number: int = 0,
                      quality: int = 100):
        # return all images if empty list
        if len(indices) == 0:
            indices = range(len(self.data['sequences'][sequence_number][
                                    'canvases']))
        imgs = [image.load_image(size=f"pct:{quality}") for image in self.get_images(
            indices)]
        img_names = [image.id for image in self.get_images(indices)]

        return scan.full_stitching_pipeline(imgs, img_names)