import cv2
import numpy as np
تحميل الصورة
img = cv2.imread("your_image.jpg")
frames = []
for i in range(30):
frame = img.copy()
dx = int(2 * np.sin(i * 0.3))
M = np.float32([[1, 0, dx], [0, 1, 0]])
shifted = cv2.warpAffine(frame, M, (frame.shape[1], frame.shape[0]))
frames.append(shifted)
تصدير الفيديو
out = cv2.VideoWriter('animated.avi', cv2.VideoWriter_fourcc(*'XVID'), 10, (img.shape[1], img.shape[0]))
for frame in frames:
out.write(frame)
out.release()