Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy
- import glob
- import os
- dir = "." # current directory
- ext = ".jpg" # whatever extension you want
- pathname = os.path.join(dir, "*" + ext)
- images = [cv2.imread(img) for img in glob.glob(pathname)]
- height = sum(image.shape[0] for image in images)
- width = max(image.shape[1] for image in images)
- output = numpy.zeros((height,width,3))
- y = 0
- for image in images:
- h,w,d = image.shape
- output[y:y+h,0:w] = image
- y += h
- cv2.imwrite("test.jpg", output)
- pathname = os.path.join(dir, "*" + ext)
- images = [cv2.imread(img) for img in glob.glob(pathname)]
- names = [img for img in glob.glob(pathname)]
- #Get filenames from paths
- files = [re.sub("/.*/", "", x) for x in names]
- #Get positions
- position = [re.sub(".jpeg", "", x) for x in files]
- #Get hight position and tranform to int
- height = [re.sub("_.*", "", x) for x in position]
- height2 = [int(i) for i in height]
- #Get width position and tranform to int
- width = [re.sub(".*_", "", x) for x in position]
- width2 = [int(i) for i in width]
- #Generate background image
- height_tot = 280*max(height2) #All images are 280*280
- width_tot = 280*max(width2)
- output = numpy.zeros((height_tot,width_tot,3))
- #Locate images
- for name, image in zip(names,images):
- files = re.sub("/.*/", "", name)
- position = re.sub(".jpeg", "", files)
- height = re.sub("_.*", "", position)
- width = re.sub(".*_", "", position)
- output[height:height+280,width:width+280] = image
- cv2.imwrite("test.jpg", output)
- ---------------------------------------------------------------------------
- TypeError Traceback (most recent call last)
- <ipython-input-35-f789f37a8386> in <module>()
- 5 height = re.sub("_.*", "", position)
- 6 width = re.sub(".*_", "", position)
- ----> 7 output[height:height+280,width:width+280] = image
- 8
- 9 cv2.imwrite("test.jpg", output)
- TypeError: must be str, not int
- ---------------------------------------------------------------------------
- TypeError Traceback (most recent call last)
- <ipython-input-40-a7771bda9221> in <module>()
- 5 height = re.sub("_.*", "", position)
- 6 width = re.sub(".*_", "", position)
- ----> 7 output[str(height):str(height+280),str(width):str(width+280)] = image
- 8
- 9 cv2.imwrite("test.jpg", output)
- TypeError: must be str, not int
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement