光流的文件一般是以.flo格式文件保存的,有时候需要转换成.png等图片格式,这样显示更加直观。这里简单得记录下自己的操作步骤。测试环境:ubuntu16.04系统,windows系统应该类似,无非就是编译方式不同而已,具体步骤如下:
(1)前往http://vision.middlebury.edu/flow/submit/下载imageLib工具包,选择高亮的flow-code.zip文件如下图:
(2)解压压缩文件,然后编译imageLib工具包,在ubuntu终端下输入:
# 进入到imageLib文件夹所在位置
cd imageLib
make
# 退出到上一层目录
cd ..
./colortest 10 colors.png
# 测试,单个.flo文件转为.png图片,好像不支持.jpg图片格式
./color_flow input.flo output.png
如果不出问题,就会生成相应的光流图片,举例如下,这里要注意路径问题。
(3)將文件夹内所有的.flo文件批量生成对应的.png图片
往往我们需要转换的不仅仅是单个的.flo文件,这里提供一个可批量执行的python脚本文件,注意你的路径就可以了,具体代码如下:
flo2picture.py
# Function: .flo file convert to .png file # By RongSong,2018-04-15 import os path = '/your .flo file directory path/' #.flo Directory(input) png_path = '/your .png file directory path/' #.png Directory(output) length = len(os.listdir(path)) num = 0 while(num<length): ml = './color_flow\t' + path + str(num) + '.flo\t' + png_path + str(num) + '.png' os.system(ml) num += 1