# Research on the Precision Measurement Method of Flat Screen Gap Based on Mobile Vision
## 3 Precise Measurement of Screen Gap Based on Outer Edge Detection of the Flat R Region
### Adaptive Hough Line Detection Based on Dichotomy  
The Hough transform is chosen for line detection because it has the best identification ability and accuracy in an interference environment. The detection process is iterated by the dichotomy method because it has stable convergence and a quick turnaround time. The accumulator threshold corresponding to the longest line is iteratively searched based on the characteristic that the line at the outer edge of the R region is the longest. This enables the adaptive and high-precision line detection of the outer edge of the R region by steadily obtaining the optimal accumulator threshold. The description of Algorithm 2 is as follows:  
```
Input: An image matrix \(\mathbf{I}\), Hough transform discretization angle \(\theta_{\text{h}}\) = 0.01\({}^{\circ}\) Output: Information on a straight line (r, \(\theta\))
```  
**Algorithm 2** Adaptive Hough line detection based on dichotomy  
The specific process of the algorithm is as follows:  
Figure 7: Position of maximum standard deviation.  
1. Canny operator is used to accurately extract the edge pixels from the outer edge after binary segmentation.
2. The initial dichotomy interval is set as \([v_{l},v_{r}]\), the length of convergence interval as \(\varepsilon\), the distance and angle after Hough transform discretization as \(r_{h}\) and \(\theta_{h}\), respectively, and the angle range of line detection as \([\beta_{l},\beta_{r}]\). The value of the accumulator threshold \(v\) is set to \(v_{l}\) and the iteration flag \(F\) is set to be true. According to the iteration flag \(F\), it is a cyclic process to determine whether to perform a binary search. A loop procedure that uses the iteration flag F to determine whether to conduct a dichotomous search is employed.
3. When \(v_{r}-v_{l}>\varepsilon\) is true, the accumulator threshold \(v\) should be set to \((v_{r}+v_{l})/2\); when \(v_{r}-v_{l}<=\varepsilon\) is true, the accumulator threshold \(v\) should be set to \(v_{l}\), and \(F\) should be set to false. According to the accumulator threshold, the Hough transform is used to detect the edge, and the distance and angle of \(H\) lines are obtained.
4. Determine the number of lines: when \(H>1\) is true, let the left end point of the second partition \(v_{l}=v\); when \(H==0\) is true, let the right end point of the second partition \(v_{r}=v\); and when \(H==1\) is true, the cycle should finish.
5. The final straight line detection findings are obtained at the cycle's conclusion. If there are multiple approximately equal solutions (\(r\), \(\theta\)) in the detection, the multiple results would be averaged to generate the unique (\(r\), \(\theta\)).  
The properties of the ideal line serve as a representation of the outer edge of the R region when the aforementioned iterative search procedure is complete, and the midpoint of the optimal line is regarded as the midpoint of the outer edge. The midpoint coordinates of the line in the local image of the R region can be obtained according to the algebraic relationship. The coordinates of the midpoint as the final result of the edge detection outside the R region will be saved in the disk file as the input value for the full-size measurement.