refine video file
This commit is contained in:
@@ -3,7 +3,7 @@ Grounded SAM 2: Ground and Track Anything with Grounding DINO, Grounding DINO 1.
|
|||||||
|
|
||||||
Grounded SAM 2 does not introduce significant methodological changes compared to [Grounded SAM](https://github.com/IDEA-Research/Grounded-Segment-Anything). Both approaches leverage the capabilities of open-world models to address complex visual tasks. Consequently, we try to **simplify the code implementation** in this repository, aiming to enhance user convenience.
|
Grounded SAM 2 does not introduce significant methodological changes compared to [Grounded SAM](https://github.com/IDEA-Research/Grounded-Segment-Anything). Both approaches leverage the capabilities of open-world models to address complex visual tasks. Consequently, we try to **simplify the code implementation** in this repository, aiming to enhance user convenience.
|
||||||
|
|
||||||
[](https://github.com/user-attachments/assets/83675ffd-86d8-439d-ac95-4dfb339e181a)
|
[](./demo_images/children_tracking_demo.mp4)
|
||||||
|
|
||||||
## Contents
|
## Contents
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
|
BIN
demo_images/children_tracking_demo.mp4
Normal file
BIN
demo_images/children_tracking_demo.mp4
Normal file
Binary file not shown.
Binary file not shown.
@@ -2,34 +2,34 @@ import cv2
|
|||||||
import os
|
import os
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
def create_video_from_images(image_folder, output_video_path, frame_rate=30):
|
def create_video_from_images(image_folder, output_video_path, frame_rate=25):
|
||||||
# 定义允许的图像后缀
|
# define valid extension
|
||||||
valid_extensions = [".jpg", ".jpeg", ".JPG", ".JPEG"]
|
valid_extensions = [".jpg", ".jpeg", ".JPG", ".JPEG"]
|
||||||
|
|
||||||
# 获取图像文件列表
|
# get all image files in the folder
|
||||||
image_files = [f for f in os.listdir(image_folder)
|
image_files = [f for f in os.listdir(image_folder)
|
||||||
if os.path.splitext(f)[1] in valid_extensions]
|
if os.path.splitext(f)[1] in valid_extensions]
|
||||||
image_files.sort() # 排序,确保按正确的顺序读取图像
|
image_files.sort() # sort the files in alphabetical order
|
||||||
print(image_files)
|
print(image_files)
|
||||||
if not image_files:
|
if not image_files:
|
||||||
raise ValueError("No valid image files found in the specified folder.")
|
raise ValueError("No valid image files found in the specified folder.")
|
||||||
|
|
||||||
# 读取第一张图像以获取视频尺寸
|
# load the first image to get the dimensions of the video
|
||||||
first_image_path = os.path.join(image_folder, image_files[0])
|
first_image_path = os.path.join(image_folder, image_files[0])
|
||||||
first_image = cv2.imread(first_image_path)
|
first_image = cv2.imread(first_image_path)
|
||||||
height, width, _ = first_image.shape
|
height, width, _ = first_image.shape
|
||||||
|
|
||||||
# 创建视频写入对象
|
# create a video writer
|
||||||
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # 可以选择其他编码方式,如 'XVID'
|
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # codec for saving the video
|
||||||
video_writer = cv2.VideoWriter(output_video_path, fourcc, frame_rate, (width, height))
|
video_writer = cv2.VideoWriter(output_video_path, fourcc, frame_rate, (width, height))
|
||||||
|
|
||||||
# 逐帧写入视频
|
# write each image to the video
|
||||||
for image_file in tqdm(image_files):
|
for image_file in tqdm(image_files):
|
||||||
image_path = os.path.join(image_folder, image_file)
|
image_path = os.path.join(image_folder, image_file)
|
||||||
image = cv2.imread(image_path)
|
image = cv2.imread(image_path)
|
||||||
video_writer.write(image)
|
video_writer.write(image)
|
||||||
|
|
||||||
# 释放资源
|
# source release
|
||||||
video_writer.release()
|
video_writer.release()
|
||||||
print(f"Video saved at {output_video_path}")
|
print(f"Video saved at {output_video_path}")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user