generating test footage video owrks
This commit is contained in:
parent
7470513019
commit
2d960c91b7
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
generate test footage/images/
|
||||||
|
|
@ -2,6 +2,9 @@
|
||||||
import math
|
import math
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
import random
|
import random
|
||||||
|
import imageio
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def getRandomColorString():
|
def getRandomColorString():
|
||||||
|
|
@ -11,39 +14,55 @@ fps = 30
|
||||||
xmax = 1920
|
xmax = 1920
|
||||||
ymax = 1080
|
ymax = 1080
|
||||||
# in minutes
|
# in minutes
|
||||||
length = 1
|
length = .1
|
||||||
numberOfEvents = 3
|
numberOfEvents = 3
|
||||||
|
dirname = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
imagesPath = os.path.join(dirname, 'images')+"/"
|
||||||
|
outputPath = os.path.join(dirname, 'out.mp4')
|
||||||
|
|
||||||
|
|
||||||
# creating new Image object
|
# creating new Image object
|
||||||
img = Image.new("RGB", (xmax, ymax))
|
def genImages():
|
||||||
|
counter = 0
|
||||||
|
for i in range(numberOfEvents):
|
||||||
|
|
||||||
for i in range(numberOfEvents):
|
objectWidth = (5 + random.randint(0, 5)) * xmax / 100
|
||||||
|
objectHeight = (10 + random.randint(-5, 5)) * ymax / 100
|
||||||
|
|
||||||
objectWidth = (5 + random.randint(0, 5)) * xmax / 100
|
objectX = random.randint(0, xmax)
|
||||||
objectHeight = (10 + random.randint(-5, 5)) * ymax / 100
|
objectY = random.randint(0, ymax)
|
||||||
|
|
||||||
objectX = random.randint(0, xmax)
|
objectSpeedX = random.randint( 1 ,5 )
|
||||||
objectY = random.randint(0, ymax)
|
objectSpeedY = random.randint( 1, 5 )
|
||||||
|
color = getRandomColorString()
|
||||||
|
|
||||||
objectSpeedX = random.randint( -int(objectWidth) - 1, int(objectWidth) + 1)
|
for j in range(int(fps*length*60 / numberOfEvents)):
|
||||||
objectSpeedY = random.randint( -int(objectWidth) - 1, int(objectWidth) + 1)
|
counter+=1
|
||||||
color = getRandomColorString()
|
objectX -= objectSpeedX
|
||||||
|
objectY -= objectSpeedY
|
||||||
|
|
||||||
for j in range(int(fps*length*60 / numberOfEvents)):
|
objectShape = [(objectX, objectY), (objectX + objectWidth, objectY + objectHeight)]
|
||||||
|
|
||||||
objectX -= objectSpeedX
|
|
||||||
objectY -= objectSpeedY
|
|
||||||
|
|
||||||
objectShape = [(objectX, objectY), (objectX + objectWidth, objectY + objectHeight)]
|
|
||||||
|
|
||||||
|
|
||||||
|
img = Image.new("RGB", (xmax, ymax))
|
||||||
|
# create rectangle image
|
||||||
|
img1 = ImageDraw.Draw(img)
|
||||||
|
|
||||||
# create rectangle image
|
img1.rectangle(objectShape, fill = color)
|
||||||
img1 = ImageDraw.Draw(img)
|
img.save( imagesPath + str(counter).zfill(6) + ".png")
|
||||||
|
|
||||||
img1.rectangle(objectShape, fill = color)
|
def makeVideo():
|
||||||
|
fileList = []
|
||||||
|
for file in sorted(os.listdir(imagesPath)):
|
||||||
|
complete_path = imagesPath + file
|
||||||
|
fileList.append(complete_path)
|
||||||
|
|
||||||
img.show()
|
writer = imageio.get_writer(outputPath, fps=fps)
|
||||||
|
|
||||||
|
for im in fileList:
|
||||||
|
writer.append_data(imageio.imread(im))
|
||||||
|
writer.close()
|
||||||
|
|
||||||
|
genImages()
|
||||||
|
makeVideo()
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue