光流法

对光流法的理解建立在以下三篇学习笔记上。

光流法
光流法简单介绍
通俗的讲什么是光流法

通俗的讲什么是光流法一文中因如此看两幅“挥动的手”图片。
因为光流法假设两帧之间亮度不便,即是灰度不变,故孟塞尔颜色系统中明度(value)为定值。
色相(hue)表像素运动二维方向。
色度(chroma)表像素运动的速度。
故光流场是图片中每个像素都有一个x方向和y方向的位移,所以在上面那些光流计算结束后得到的光流flow是个和原来图像大小相等的双通道图像。

LK光流法和金字塔LK光流法

The stitching software

The computational imaging algorithms that stitch all the images together are arguably at the heart of the system and represent the most difficult part of the system. Luckily, the past 20 years of computational photography and computer vision research and an additional 60 years of aerial stereo photogrammetry (used to create topological maps) gave us a strong starting point.

Since the stitching process generates a final video image, visual image quality was paramount in our image processing and computational imaging pipeline. A subtle aspect of digital image capture is that care must be taken at each step of computation to ensure pixel quality is maintained. It’s quite easy to mistakenly degrade the image quality at any step in the process, after which that resolution is forever lost. Repeat that several times, and quality is completely compromised.

We process the data in several steps:
1、Convert raw Bayer input images to gamma-corrected RGB.
2、Mutual camera color correction
3、Anti-vignetting
4、Gamma and tone curve
5、Sharpening (deconvolution)
6、Pixel demosaicing

Perform intrinsic image correction to remove the lens distortion and reproject the image into a polar coordinate system.
Bundle adjusted mutual extrinsic camera correction to compensate for slight misalignments in camera orientation.
Perform optical flow between pairs of cameras to compute left-right eye stereo disparity.
Synthesize novel views of virtual cameras for each view direction separately for the left and right eye view based on the optical flow.
Composite final pixels of left and right flows.
The key algorithmic element is the concept of optical flow. Our code builds upon an optical flow algorithm that is mathematically trickier than other stitching solutions but delivers better results. Optical flow allows us to compute left-right eye stereo disparity between the cameras and to synthesize the novel views separately for the left and right eyes. We flow the top and bottom cameras into the side cameras, and similarly we flow pairs of cameras to match objects that appear at different distances. In fact, optical flow remains an open research area since it’s an ill-posed inverse problem. Its ill-posedness stems from ambiguities caused by occlusions — one camera not being able to see what an adjacent camera can see. While this is mitigated by having multiple cameras and time-varying capture, it nevertheless remains a difficulty. Our code uses optical flow to compute left-right eye stereo disparity. We leverage this ability to generate seamless stereoscopic 360 panoramas automatically. Dailies are delivered overnight. This is a dramatic reduction in post-production time.

Optical_FLow

项目/Surround360/surround360_render/source/iptical_flow目录下的这些文件具体实现了光流法。
光流法在FB360的目的是生成360的各个角度的新视角(NovelView)的左右眼图像。
NovelView

OpticalFlowInterface.h

导入了OpenCV2的包,具体算法因在opencv2的手册中获得。(Undo)

定义了抽象方法“computeOpticalFlow”,从中可以获取一下信息

  1. 经过光流计算,使得I1图像拼接部分接近I0。I0/I1是1字节的BGRA格式,有alpha通道。I0/I1是两个相邻camera的image。
  2. 在处理video时,prevI0/I1则记录上一帧I0/I1 camera的image。
  3. 处理video第一帧时,等同于处理photo,忽略prevI0/prevI1。

OpticalFlowVisualization.h

四个方法,对像素运动信息做了处理。

visualizeFlowAsGreyDisparity

用灰度表将光流可视化,是对像素的x轴运动信息的分离。

visualizeFlowAsVectorField

将光流区域的运动方向覆盖到顶端

visualizeFlowColorWheel

利用孟塞尔颜色系统,将运动信息可视化。色调(hue)表方向,色度(magnitude)表运动速度标量,明度是一个的常量。

OpticalFLowFactory

是一个工厂类,目的是运用不同的“FlowAlgorithm”去实例化OpticalFlowInterface.h
得知有两种算法:
pixflow_lowpixflow_search_20

NovelView.h/cpp

此程序把image切片渲染缝合成全景图,并且计算出任意浏览的视角的左右眼图像。设计了一种数据结构(LazyNovelViewBuffer),描述了当前需要的新视角,然后一步求出结果。

内容很多,以注释的形式加到代码内
链接: 密码:xi1z
NovelView
光流拼接法的核心逻辑

PixFlow.h

有一段名为computeOpticalFlow的函数。应该是计算光流法的核心。
在代码中发现以下几个关键词computeOpticalFlowbuildPyramid
我觉得需要学习LK光流法和Pyramidal Implementation of the Lucas Kanade Feature Tracker Description of the algorithm
明显是以灰度来就算光流的金字塔LK算法。
链接: 密码:nuqk

KnowledgeStack

BGRA : 一种像素格式(pixel format)像素色彩按分量的大小和排列。这种格式以每个像素所使用的总位数以及用于存储像素色彩的红、绿、蓝和 alpha 分量(透明度)的位数指定。

颜色通道中R,G,B,A,L 以及 X 的意义是:
R
红色成分,通常范围从0.0(没有红色)到1.0(全部的红色)。
G
绿色成分,通常范围从0.0(没有绿色)到1.0(全部的绿色)。
B
蓝色成分,通常范围从0.0(没有蓝色)到1.0(全部的蓝色)。
A
alpha(不透明度)成分,通常范围从0.0(完全透明)到1.0(不透明)。
L
亮度成分,通常范围从0.0(黑暗)到1.0(全白)。最终这个成分会被分散到RGB每个中完成最终的图像效果。
X
这个是被系统忽略的成分。
对于RGBL通道来说,默认的情况下设置为0。而Alpha通道却不同,在默认的情况下被设定为1,代表不透明。

PNG:Portable Network Graphics (PNG)。

Mat存图像

一般的图像文件格式使用的是 Unsigned 8bits,CvMat矩阵对应的参数类型就是CV_8UC1,CV_8UC2,CV_8UC3。
(最后的1、2、3表示通道数,譬如RGB3通道就用CV_8UC3)
而float 是32位的,对应CvMat数据结构参数就是:CV_32FC1,CV_32FC2,CV_32FC3…
double是64bits,对应CvMat数据结构参数:CV_64FC1,CV_64FC2,CV_64FC3等。
变换这种矩阵单位类型,Mat里有一个函数convertTo可以办到:
C++:void Mat::convertTo(OutputArray m, int rtype, double alpha=1, double beta=0 )
参考源

CV

CV_8U - 8-bit unsigned integers ( 0..255 )
CV_8S - 8-bit signed integers ( -128..127 )
CV_16U - 16-bit unsigned integers ( 0..65535 )
CV_16S - 16-bit signed integers ( -32768..32767 )
CV_32S - 32-bit signed integers ( -2147483648..2147483647 )
CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN )
CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )

HSL和HSV色彩空间

HSL和HSV都是一种将RGB色彩模型中的点在圆柱坐标系中的表示法。这两种表示法试图做到比RGB基于笛卡尔坐标系的几何结构更加直观。
HSL即色相、饱和度、亮度(英语:Hue, Saturation, Lightness),又称HSL。HSV即色相、饱和度、明度(英语:Hue, Saturation, Value),又称HSB,其中B即英语:Brightness。
色相(H)是色彩的基本属性,就是平常所说的颜色名称,如红色、黄色等。
饱和度(S)是指色彩的纯度,越高色彩越纯,低则逐渐变灰,取0-100%的数值。
明度(V),亮度(L),取0-100%。
参考源

IplImage

由于OpenCV主要针对的是计算机视觉方面的处理,因此在函数库中,最重要的结构体是IplImage结构。IplImage结构来源于Intel的另外一个函数库Intel Image Processing Library (IPL),该函数库主要是针对图像处理。
参考源

金字塔LK光流算法

Jean-Yves Bouguet,“Pyramidal Implementation of the Lucas Kanade Feature Tracker Description of the algorithm”,Intel Corporation Microprocessor Research Labs

OpenCV-Mat

Mat这个类有两部分数据。一个是matrix header,这部分的大小是固定的,包含矩阵的大小,存储的方式,矩阵存储的地址等等。另一个部分是一个指向矩阵包含像素值的指针。
参考源

Vec4b

BGRA
参考源

OpenCV函数

split 取矩阵的列
cvtColor 转换图片的色域编码格式
Mat.convertTo 转换Mat到一定的格式(深度)
GaussianBlur 高斯模糊
Sobel 一种算图像边缘的算法,实质是离散的一阶差分参考源

参考源