Spaces:
Running
on
A10G
Running
on
A10G
Update align.py
Browse files
align.py
CHANGED
@@ -4,7 +4,6 @@ from fastdtw import fastdtw
|
|
4 |
import json
|
5 |
import cv2
|
6 |
|
7 |
-
# 读取视频文件
|
8 |
def read_video_frames(video_path):
|
9 |
cap = cv2.VideoCapture(video_path)
|
10 |
frames = []
|
@@ -16,7 +15,6 @@ def read_video_frames(video_path):
|
|
16 |
cap.release()
|
17 |
return frames
|
18 |
|
19 |
-
# 提取关键点
|
20 |
def extract_keypoints(sequence):
|
21 |
keypoints_sequence = []
|
22 |
for frame in sequence:
|
@@ -37,14 +35,10 @@ def calculate_distance_matrix(seq1, seq2):
|
|
37 |
|
38 |
# 计算两个手语序列的最佳对齐路径
|
39 |
def align_sequences(seq1, seq2):
|
40 |
-
# 提取关键点
|
41 |
keypoints_seq1 = extract_keypoints(seq1)
|
42 |
keypoints_seq2 = extract_keypoints(seq2)
|
43 |
|
44 |
-
# 计算距离矩阵
|
45 |
distances = calculate_distance_matrix(keypoints_seq1, keypoints_seq2)
|
46 |
-
|
47 |
-
# 使用 DTW 进行对齐
|
48 |
distance, path = fastdtw(keypoints_seq1, keypoints_seq2, dist=lambda x, y: np.linalg.norm(x - y))
|
49 |
|
50 |
return distance, path
|
@@ -135,11 +129,7 @@ def create_aligned_videos(seq1_frames, seq2_frames, alignment_path, output_combi
|
|
135 |
# 获取对齐的帧
|
136 |
frame1 = seq1_frames[idx1]
|
137 |
frame2 = seq2_frames[idx2]
|
138 |
-
|
139 |
-
# # 如果两帧高度不一致,调整frame2的高度以匹配frame1
|
140 |
-
# if height1 != height2:
|
141 |
-
# frame2 = cv2.resize(frame2, (width2, height1))
|
142 |
-
|
143 |
# 等比例缩放两个视频的帧到统一尺寸
|
144 |
frame1_resized = cv2.resize(frame1, (unified_width, unified_height), interpolation=cv2.INTER_AREA)
|
145 |
frame2_resized = cv2.resize(frame2, (unified_width, unified_height), interpolation=cv2.INTER_AREA)
|
|
|
4 |
import json
|
5 |
import cv2
|
6 |
|
|
|
7 |
def read_video_frames(video_path):
|
8 |
cap = cv2.VideoCapture(video_path)
|
9 |
frames = []
|
|
|
15 |
cap.release()
|
16 |
return frames
|
17 |
|
|
|
18 |
def extract_keypoints(sequence):
|
19 |
keypoints_sequence = []
|
20 |
for frame in sequence:
|
|
|
35 |
|
36 |
# 计算两个手语序列的最佳对齐路径
|
37 |
def align_sequences(seq1, seq2):
|
|
|
38 |
keypoints_seq1 = extract_keypoints(seq1)
|
39 |
keypoints_seq2 = extract_keypoints(seq2)
|
40 |
|
|
|
41 |
distances = calculate_distance_matrix(keypoints_seq1, keypoints_seq2)
|
|
|
|
|
42 |
distance, path = fastdtw(keypoints_seq1, keypoints_seq2, dist=lambda x, y: np.linalg.norm(x - y))
|
43 |
|
44 |
return distance, path
|
|
|
129 |
# 获取对齐的帧
|
130 |
frame1 = seq1_frames[idx1]
|
131 |
frame2 = seq2_frames[idx2]
|
132 |
+
|
|
|
|
|
|
|
|
|
133 |
# 等比例缩放两个视频的帧到统一尺寸
|
134 |
frame1_resized = cv2.resize(frame1, (unified_width, unified_height), interpolation=cv2.INTER_AREA)
|
135 |
frame2_resized = cv2.resize(frame2, (unified_width, unified_height), interpolation=cv2.INTER_AREA)
|