鱼眼图像转等距投影图像

鱼眼图像转等距投影图像

目的

​ 单张图像的使用方法见下面的博客。

  • 鱼眼图像的说明见这里

  • FFMPEG的使用说明见这里

批处理

  1. Fisheye image sequences to fisheye video. 将单个鱼眼图像序列转成视频,注意图像的个数和视频的帧数保持一致。
1
2
.\ffmpeg.exe -f image2 -r 1 -i kitti360imagespath\image_03\data_rgb/000000000%d.png -vcodec libx265 -pix_fmt yuv420p -b:v 40000k -bufsize 5000k -preset ultrafast -c:a copy -y -r 1 ./fisheye_rgb_sequence_r.mp4
.\ffmpeg.exe -f image2 -r 1 -i kitti360imagespath\image_02\data_rgb/000000000%d.png -vcodec libx265 -pix_fmt yuv420p -b:v 40000k -bufsize 5000k -preset ultrafast -c:a copy -y -r 1 ./fisheye_rgb_sequence_l.mp4
  1. Join to single fisheye video to dual fisheye video. 将两个视频拼接起来。就是两个视频水平放置。
1
.\ffmpeg.exe -i .\fisheye_rgb_sequence_l.mp4 -i .\fisheye_rgb_sequence_r.mp4 -filter_complex hstack -y ./dual_fisheye_image.mp4
  1. Dual fisheye video to equirectangular video. 将双鱼眼视频转换为等距投影视频。这里FOV187.8是微调的,为了得到一个比较好的转换结果。
1
./ffmpeg.exe -y -i .\dual_fisheye_image.mp4 -vf v360=dfisheye:e:yaw=-90:ih_fov=187.8:iv_fov=185 -c:v libx265 -b:v 40000k -bufsize 5000k -preset ultrafast -c:a copy equirectangular_image_sequence.mp4
  1. Fisheye video to fisheye image sequences将等距投影视频转换为图像,并按照原始鱼眼图像的命名方式命名。
1
.\ffmpeg.exe -i .\equirectangular_image_sequence.mp4 -r 1 -q:v 1 -start_number 0 ./%10d.png

这里给一个KITTI-360数据集中鱼眼图像批量转换为等距投影图像的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash

file_list=("2013_05_28_drive_0000_sync"
"2013_05_28_drive_0002_sync"
"2013_05_28_drive_0003_sync"
"2013_05_28_drive_0004_sync"
"2013_05_28_drive_0005_sync"
"2013_05_28_drive_0006_sync"
"2013_05_28_drive_0007_sync"
"2013_05_28_drive_0009_sync"
"2013_05_28_drive_0010_sync")

# create the destiny dir
data_2d_pano=data_2d_pano
mkdir -p $data_2d_pano
cd $data_2d_pano
for sequence in ${file_list[@]}; do
mkdir -p $sequence
cd $sequence
mkdir -p pano
cd pano
mkdir -p data_rgb
cd ../..
done

cd ../data_2d_pano
echo "Current dir:"
pwd

# #ffmpeg operation
for sequence in ${file_list[@]}; do
# create the path and move into
cd $sequence
# 1. fetch images and merge into videos
ffmpeg -f image2 -r 1 -i ../../data_2d_raw/$sequence/image_03/data_rgb/%10d.png -vcodec libx265 -pix_fmt yuv420p -b:v 40000k -bufsize 5000k -preset fast -c:a copy -y -r 1 fisheye_rgb_sequence_r.mp4
ffmpeg -f image2 -r 1 -i ../../data_2d_raw/$sequence/image_02/data_rgb/%10d.png -vcodec libx265 -pix_fmt yuv420p -b:v 40000k -bufsize 5000k -preset fast -c:a copy -y -r 1 fisheye_rgb_sequence_l.mp4
# 2. merge two videos into one video
ffmpeg -i fisheye_rgb_sequence_l.mp4 -i fisheye_rgb_sequence_r.mp4 -filter_complex hstack -y dual_fisheye_image.mp4
# 3. transform to equirectangular video
ffmpeg -y -i dual_fisheye_image.mp4 -vf v360=dfisheye:e:yaw=-90:ih_fov=187.8:iv_fov=185 -c:v libx265 -b:v 40000k -bufsize 5000k -preset ultrafast -c:a copy equirectangular_image_sequence.mp4
# 4. Equirectangular video to separate images
ffmpeg -i equirectangular_image_sequence.mp4 -r 1 -q:v 1 -start_number 0 ./pano/data_rgb/%10d.png
cd ..
done

​ 这里面图像转视频默认图像的名字是按照数字排序的,而且序号是从0开始的,如果不想从0开始,就要在-f image2后面加-start_number 4613。就可以了。其他位置无效。

当然直接使用FFMPEG得到的等距投影图像中间存在明显的拼接缝,因为FFMPEG并没有经过blend操作。可以手动刺点的方式获取两张鱼眼图像上的同名点,来获得更好的拼接结果,但是比较麻烦,而且需要手动刺点,如果想得到比较好的等距投影图像,应该增加这个步骤。比如使用Fusion2sphere的方式得到拼接较好的结果。

Reference

  • https://www.trekview.org/blog/2022/using-ffmpeg-process-gopro-fusion-fisheye/ (Recommanded:+1::+1::+1:)
  • https://github.com/raboof/dualfisheye2equirectangular
  • https://stackoverflow.com/questions/37796911/is-there-a-fisheye-or-dual-fisheye-to-equirectangular-filter-for-ffmpeg
  • https://github.com/trek-view/Fusion2sphere
| visits
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×