61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Wed Oct 30 13:18:59 2024
|
|
|
|
@author: ym
|
|
"""
|
|
|
|
import os
|
|
import glob
|
|
|
|
IMGFORMATS = '.bmp', '.jpeg', '.jpg', 'png', 'tif', 'tiff', 'webp', 'pfm'
|
|
VIDFORMATS = '.avi', '.gif', '.m4v', '.mkv', '.mov', '.mp4', '.ts', '.wmv'
|
|
|
|
def get_image_pairs(p):
|
|
files = []
|
|
files.extend(sorted(glob.glob(os.path.join(p, '*.jpg'))))
|
|
# images = [x for x in files if x.split('.')[-1].lower() in IMG_FORMATS]
|
|
|
|
tamps_0, tamps_1 = [], []
|
|
files_0, files_1 = [], []
|
|
for file in files:
|
|
basename = os.path.basename(file)
|
|
if basename.find('frameId')<0: continue
|
|
|
|
|
|
f, ext = os.path.splitext(basename)
|
|
camer, tamp, _, frameId = f.split('_')
|
|
|
|
if camer == '0':
|
|
tamps_0.append(int(tamp))
|
|
files_0.append(file)
|
|
|
|
if camer == '1':
|
|
tamps_1.append(int(tamp))
|
|
files_1.append(file)
|
|
|
|
idx0 = sorted(range(len(tamps_0)), key=lambda k: tamps_0[k])
|
|
files0 = [files_0[i] for i in idx0]
|
|
|
|
idx1 = sorted(range(len(tamps_1)), key=lambda k: tamps_1[k])
|
|
files1 = [files_1[i] for i in idx1]
|
|
|
|
files = (files0, files1)
|
|
|
|
return files
|
|
|
|
|
|
def get_video_pairs(vpath):
|
|
vdieopath = []
|
|
for filename in os.listdir(vpath):
|
|
file, ext = os.path.splitext(filename)
|
|
if ext in VIDFORMATS:
|
|
vdieopath.append(os.path.join(vpath, filename))
|
|
return vdieopath
|
|
|
|
|
|
|
|
|
|
|
|
|