# Research on a Measurement Method for the Ocean Wave Field Based on Stereo Vision
## 2 Materials and Methods
### Stereo Matching
#### 2.2.2 Gridding SiftGPU Feature Extraction and Matching  
First, we used several pairs of wave images to perform the image matching through the use of traditional SIFT, determine the common area of the left and right images, and determine the left image edge points \((u_{\text{lmin}},v_{\text{lmin}})\) and right image edge points \((u_{\text{lmax}},v_{\text{max}})\). Here, the common area of the left image is \((u_{\text{lmin}}-u_{\text{lmax}},v_{\text{lmin}}-v_{\text{lmax}})\), while that of right image is \((0-u_{\text{mmax}},0-v_{\text{max}})\), and the non-overlapping area is cropped.  
Subsequently, we divided the common area of the left and right images into matching blocks. At this stage, a specific matching block size was selected according to the actual resolution of the image. It was assumed that the pixel value of a block in the left image was the same as the pixel value in the matching block in the right image. Meanwhile, the size of the areas corresponding to the same matching block are not equal and the pixel coordinates do not have a simple one-to-one correspondence. The calculation method is given in Figure 1:  
Considering the camera distortion [30], there are:  
\[\begin{cases}x_{\text{il}}=x_{\text{0l}}+u_{\text{il}}+k_{1}(x_{\text{0l}}+u_{ \text{il}})r_{\text{ij}}^{2}\\ y_{\text{il}}=y_{\text{0l}}+v_{\text{il}}+k_{1}(y_{\text{0l}}+v_{\text{il}})r_{ \text{il}}^{2}\end{cases} \tag{3}\]  
In above formula, \((u_{\text{il}},v_{\text{il}})\) are the pixel coordinates of the left image, \((x_{\text{0l}},y_{\text{0l}})\) are the center coordinates of the left image, \(k\) is the distortion parameter of the left and right cameras, and \(r\) is the distance between the pixel coordinates and center coordinates, \(r_{\text{il}}=\sqrt{(x+u)^{2}+(y+v)^{2}}\).  
Figure 1: Gridding image and identification of corresponding block.  
As shown in Figure 2, when it is assumed that the vector coordinates of OA are \(\overset{\rightharpoonup}{r}=(x_{\text{ij}},y_{\text{ij}},-\text{f})\) and that \(\overset{\rightharpoonup}{o}\) is the vector coordinates of OO', then the normal vector of the plane is expressed as follows:  
\[\overset{\rightharpoonup}{n}=\overset{\rightharpoonup}{r}\times\overset{ \rightharpoonup}{o} \tag{4}\]  
Then the normal vector n in the right camera coordinate system is expressed as follows:  
\[\text{N}_{\text{r}}=\text{R}^{-1}\text{N} \tag{5}\]  
In above formula, R is the rotation matrix of the left camera and N represents the matrix corresponding to normal n. Therefore, the right camera pixel coordinates are:  
\[\overset{\rightharpoonup}{n}_{\text{r}}(x_{\text{ir}}\overset{\rightharpoonup }{i}+y_{\text{ir}}\overset{\rightharpoonup}{j}-\overset{\rightharpoonup}{f} \overset{\rightharpoonup}{k})=0 \tag{6}\]  
where f is the focus of the camera, N is the vector corresponding to matrix n, and \((x_{\text{ir}},y_{\text{ir}},-\text{f})\) are the coordinates of the right camera.  
Considering the camera distortion, there are:  
\[\begin{cases}x_{\text{ir}}=x_{0\text{r}}+u_{\text{ir}}+k_{1}(x_{0\text{r}}+u_ {\text{ir}})r_{\text{ir}}^{2}\\ y_{\text{ir}}=y_{0\text{r}}+v_{\text{ir}}+k_{1}(y_{0\text{r}}+v_{\text{ir}})r_{ \text{ir}}^{2}\end{cases} \tag{7}\]  
where k is the distortion parameter of the right camera, r is the distance between the pixel coordinates and the center coordinates, and \((x_{0\text{r}},y_{0\text{r}})\) are the center coordinates of the right image.  
In this way, the pixel coordinates of the left and right matching grids were obtained and the position of the left and right corresponding windows was confirmed.  
After determining the corresponding matching blocks in the left and right images, we then performed multi-threaded siftGPU accelerated matching on the matching grids in order to achieve fast and accurate matching.