Spaces:
Running
Running
seawolf2357
commited on
Commit
•
612cb39
1
Parent(s):
551b380
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import os
|
3 |
+
|
4 |
+
def images_to_video(image_folder, output_video_file, fps=30):
|
5 |
+
# Get all the image files from the provided folder
|
6 |
+
images = [img for img in os.listdir(image_folder) if img.endswith(".png") or img.endswith(".jpg") or img.endswith(".jpeg")]
|
7 |
+
|
8 |
+
# Ensure the images are in the correct order if needed
|
9 |
+
images.sort() # You might want to customize this logic
|
10 |
+
|
11 |
+
# Get the dimensions of the first image
|
12 |
+
frame = cv2.imread(os.path.join(image_folder, images[0]))
|
13 |
+
height, width, layers = frame.shape
|
14 |
+
size = (width, height)
|
15 |
+
|
16 |
+
# Initialize the video writer
|
17 |
+
out = cv2.VideoWriter(output_video_file, cv2.VideoWriter_fourcc(*'mp4v'), fps, size)
|
18 |
+
|
19 |
+
# Loop through all images and add to the video
|
20 |
+
for image in images:
|
21 |
+
frame = cv2.imread(os.path.join(image_folder, image))
|
22 |
+
out.write(frame)
|
23 |
+
|
24 |
+
# Release the video writer
|
25 |
+
out.release()
|
26 |
+
|
27 |
+
# Define the image folder and the output video file
|
28 |
+
image_folder = 'path_to_image_folder' # Replace with the path to your image folder
|
29 |
+
output_video_file = 'output_video.mp4' # Replace with your desired output file name
|
30 |
+
|
31 |
+
# Create the video
|
32 |
+
images_to_video(image_folder, output_video_file)
|