import os
def seq2jpg(seq_root
):
"""逐级遍历,将所有seq转换成jpg"""
def _seq2jpg(seq_path
):
"""转换单个seq文件"""
with open(seq_path
, 'rb') as f
:
seq
= f
.read
()
header
= b
"\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46"
img_ls
= seq
.split
(header
)[1:]
save_dir
= seq_path
[:-4]
if not os
.path
.exists
(save_dir
):
os
.mkdir
(save_dir
)
for n
, img
in enumerate(img_ls
):
img_path
= os
.path
.join
(save_dir
, '%d.jpg' % n
)
with open(img_path
, 'wb') as f
:
f
.write
(header
+ img
)
for parent
, _
, filenames
in os
.walk
(seq_root
):
for filename
in filenames
:
if filename
[-4:] == '.seq':
seq_path
= os
.path
.join
(parent
, filename
)
_seq2jpg
(seq_path
)
转载请注明原文地址: https://lol.8miu.com/read-19975.html