How Can I Combine A Multiple Videos Into One Single Video And Set The Position Of Them Using Python
Solution 1:
You can try to merge all images together by copying them into one black frame. Here is an example with the same image in all 4 places:
import cv2
import numpy as np
#loads images and gets data
img = cv2.imread("img.png")
h,w,_ = img.shape
# creates the resulting image with double the size and 3 channels
output = np.zeros((h * 2, w * 2, 3), dtype="uint8")
# copies the image to the top leftoutput[0:h, 0:w] = img # copies the image to the top rightoutput[0:h, w:w * 2] = img # copies the image to the bottom leftoutput[h:h * 2, w:w * 2] = img # copies the image to the bottom rightoutput[h:h * 2, 0:w] = img
You can always change the img to something different. Also you can concatenate them like this:
top = np.hstack((img, img))
bottom = np.hstack((img, img))
result = np.vstack((top, bottom))
And the result will be the same.
Here as sample of the resulting img with this code:
However your image is a little bit different, you will need a rotation and is not exactly concatenation, but the copying one. An example of this follows:
# creates the resulting image with double the size and 3 channels
output = np.zeros((w+h+h , w + h + h, 3), dtype="uint8")
# top imgoutput[0:h, h:h+w] = img # left img (rotated 90°)output[h:h+w, 0:h] = np.rot90(img,1) # right img (rotated 270°)output[h:h + w, h + w:h +w +h] = np.rot90(img,3) # bottom img (rotated 180°)output[h+w:h+w+h, h:h+w] = np.rot90(img,2)
and the result is like this:
If you use your image with the black background you will get more or less what you have there. You would need to play maybe with the copying parameters, but basically you do something like:
imgToCopyTo[y1:y2, x1:x2] = imgToCopyFrom
Where y1 and x1 is your top left coordinates where you want to start the copy and y2 and x2 are your bottom right coordinates of where you want to copy to. Also y2-y1 should have the height of the imgToCopyFrom x2-x1 the width (it can be bigger than the width or height but not smaller).
Post a Comment for "How Can I Combine A Multiple Videos Into One Single Video And Set The Position Of Them Using Python"