def imread(file): x = int(file[0]) y = int(file[1]) im = cv2.imread(dir + file, cv2.IMREAD_COLOR) h, w = im.shape[:2] rect = Rectangle(Vector(0, 0), 0, 1., h / w) return Image(rect, im)
def __init__(self, context, images): self.context = context self.tiles = np.empty(images.shape, object) for c in np.ndindex(self.tiles.shape): images[c].data = context.pre(images[c].data) from lib.canvas import Image Image(None, context.features(images[c].data)).show() self.tiles[c] = TileStitcher.Tile(images[c]) for c in np.ndindex(self.tiles.shape): self.tiles[c].meet_neighbours(c, self.tiles)
def capture(self, x, y): """capture an image and apply our calibration parameters to (un)distort it""" im = self.backend.get(x, y, *self.shape) if self.calibration is not None: _, mat, coe, *_ = self.calibration im = cv2.undistort(im, mat, coe) return Image( Rectangle(Vector(0, 0), Vector(1, 0).rotate(self.orientation()), *self.shape), im)
#!/usr/bin/env python3 from lib.stitch import TileStitcher, StitchContext from lib.canvas import Image, Rectangle, Vector import numpy as np import cv2 import os dir = "./var/stitch/tile2/" imshow = lambda im: Image(None, im).show() def imread(file): x = int(file[0]) y = int(file[1]) im = cv2.imread(dir + file, cv2.IMREAD_COLOR) h, w = im.shape[:2] rect = Rectangle(Vector(0, 0), 0, 1., h / w) return Image(rect, im) ims = np.empty((2, 1), object) ims[0, 0] = imread("10.jpg") ims[1, 0] = imread("20.jpg") print(ims) ctx = StitchContext() ctx.features.hsv(1) stitcher = TileStitcher(ctx, ims) im = stitcher.assemble() #im = stitch_hsv(ims, 1)
#!/usr/bin/env python3 from lib.stitch import TileStitcher, StitchContext from lib.canvas import Image, Rectangle, Vector import numpy as np import cv2 import os imshow = lambda im: Image(None, im).show() dir = "./var/stitch/tile%s/" % input("Which? ") files = os.listdir(dir) w = max(int(file[0]) for file in files) + 1 h = max(int(file[1]) for file in files) + 1 print(h, w) ims = np.empty((w, h), object) for file in files: x = int(file[0]) y = int(file[1]) im = cv2.imread(dir + file, cv2.IMREAD_COLOR) h, w = im.shape[:2] rect = Rectangle(Vector(0, 0), 0, 1., h / w) ims[x, y] = Image(rect, im) print(ims) ctx = StitchContext() ctx.features.histeq_clr() stitcher = TileStitcher(ctx, ims) im = stitcher.assemble() h, w = im.shape[:2] im2 = cv2.resize(im, (800, int(800 * h / w)))
def get(self, x, y, w, h): """Return a section of the layer; xy are real-world coordinates wh are in pixels and correspond to the 'camera' resolution""" x, y = map(lambda v: int(v*self.factor0), (x, y)) return Image.pil2cv(self.im.read_region((x, y), self.z, (w, h)))
def get(self, x, y, w, h): """Return a section of the layer; xy are real-world coordinates wh are in pixels and correspond to the 'camera' resolution""" x, y = map(lambda v: int(v * self.factor0), (x, y)) return Image.pil2cv(self.im.read_region((x, y), self.z, (w, h)))
def capture(self): im = self.backend.get(0, 0, *self.backend.shape) return Image(self.calibration, im)