手机都能裸跑的好看视频制作,PIL实现随机艺术,根本不需要AI,你学会了吗
实现方法是PIL和cv2,画完直接生成视频。 已经跑通,直接拿走就行,别发其他平台,博客园支援贴,为了正义~ 装完python和库跑就完事了,改改效果还能更好写,说不定能直接画小姐姐!
手机都能裸跑的好看视频制作,PIL实现随机艺术,根本不需要AI,你学会了吗? 聊天唠嗑的请加V:cydeeporigin 非诚勿扰!
1 2 # Import necessary libraries 3 from PIL import Image, ImageDraw, ImageFont 4 import random 5 import os 6 import cv2 7 import numpy as np 8 9 # Set parameters 10 width = 1920 11 height = 1080 12 fps = 30 13 duration = 10 14 num_frames = fps * duration 15 colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (255, 0, 255), (0, 255, 255)] 16 font_size = 50 17 font = ImageFont.truetype("arial.ttf", font_size) 18 19 # Create video writer object 20 fourcc = cv2.VideoWriter_fourcc(*'mp4v') 21 video_writer = cv2.VideoWriter("painting.mp4", fourcc, fps, (width, height)) 22 23 # Generate frames 24 for i in range(num_frames): 25 # Create new image 26 img = Image.new("RGB", (width, height), (255, 255, 255)) 27 draw = ImageDraw.Draw(img) 28 29 # Draw random lines 30 for j in range(random.randint(1, 10)): 31 x1 = random.randint(0, width) 32 y1 = random.randint(0, height) 33 x2 = random.randint(0, width) 34 y2 = random.randint(0, height) 35 color = random.choice(colors) 36 draw.line((x1, y1, x2, y2), fill=color, width=5) 37 38 # Draw random text 39 text = "".join([chr(random.randint(65, 90)) for _ in range(5)]) 40 x = random.randint(0, width - font_size * len(text)) 41 y = random.randint(0, height - font_size) 42 color = random.choice(colors) 43 draw.text((x, y), text, fill=color, font=font) 44 45 # Draw random shapes 46 for j in range(random.randint(1, 5)): 47 x1 = random.randint(0, width) 48 y1 = random.randint(0, height) 49 x2 = random.randint(0, width) 50 y2 = random.randint(0, height) 51 color = random.choice(colors) 52 shape = random.choice(["rectangle", "ellipse"]) 53 if shape == "rectangle": 54 draw.rectangle((x1, y1, x2, y2), fill=color) 55 else: 56 draw.ellipse((x1, y1, x2, y2), fill=color) 57 58 # Save image as frame 59 frame = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR) 60 video_writer.write(frame) 61 62 # Release video writer object 63 video_writer.release()