# Deal with .seq format for video sequence
# Author: Kaij
# The .seq file is combined with images,
# so I split the file into several images with the image prefix
# "\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46". import os.path
import fnmatch
import shutil def open_save(file,savepath):
# read .seq file, and save the images into the savepath f = open(file,'rb')
string = str(f.read())
splitstring = "\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46"
# split .seq file into segment with the image prefix
strlist=string.split(splitstring)
f.close()
count = 0
# delete the image folder path if it exists
if os.path.exists(savepath):
shutil.rmtree(savepath)
# create the image folder path
if not os.path.exists(savepath):
os.mkdir(savepath)
# deal with file segment, every segment is an image except the first one
for img in strlist:
filename = str(count)+'.jpg'
filenamewithpath=os.path.join(savepath, filename)
# abandon the first one, which is filled with .seq header
if count > 0:
i=open(filenamewithpath,'wb+')
i.write(splitstring)
i.write(img)
i.close()
count += 1 if __name__=="__main__":
rootdir = "D:\\Data\\feifei"
# walk in the rootdir, take down the .seq filename and filepath
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
# check .seq file with suffix
if fnmatch.fnmatch(filename,'*.seq'):
# take down the filename with path of .seq file
thefilename = os.path.join(parent, filename)
# create the image folder by combining .seq file path with .seq filename
thesavepath = parent+'\\'+filename.split('.')[0]
print "Filename=" + thefilename
print "Savepath=" + thesavepath
open_save(thefilename,thesavepath)

  先贴出代码,最近做实验要用到加州理工的行人数据库,下载一看,是把图像按照二进制数据形式存储为.seq文件,没办法,找到一个哥们写的用python处理seq文件,将数据转换为.jpg图像。代码直接可用,只需要把文件搜索目录“rootdir”改为你自己文件的目录就OK了

最新文章

  1. Task.Factory.StartNew的用法
  2. 【Python】【学习笔记】持续更新
  3. Git入门指南十一:Git branch 分支与合并分支
  4. 本地安装discuz
  5. windows和linux套接字中的select机制浅析
  6. Linux less命令详解
  7. Git Flow Note
  8. Python_ jiba、snownlp中文分词、pypinyin中文转拼音
  9. plsql中的procedure和function编程
  10. virtual和abstract的区别
  11. FJUT 毒瘤3(二分 + 最大匹配)题解
  12. Spring 4 中重定向RedirectAttributes的使用
  13. 1、从C语言到C++
  14. CSS那些事!这个篇幅是我特意开的,不是因为帮助小菜之类的,而是在多人的团队配合中各种命名冲突的规范让人蛋疼
  15. pycharm格式报错: Remove redundant parentheses
  16. Spring AOP源码分析(一)使用示例
  17. posix_memalign详细解释(转)——自定义对齐大小的内存分配函数
  18. EF6 Code First 模式更新数据库架构
  19. 成都Uber优步司机奖励政策(3月16日)
  20. Centos +django+nginx

热门文章

  1. c++ 13
  2. 关于C++中覆盖,重载,隐藏的一点说明
  3. zedboard--Opencv移植和zedboard测试(十一)
  4. 关于padding
  5. Angular学习笔记(2)——TODO小应用
  6. c++之 常量
  7. PPT去掉图片白色背景
  8. J2EE之普通类载入web资源文件的方法
  9. ubuntu下30天自制操作系统还在继续学习中
  10. RMAN简单备份