## 4 Selecting the Straight Line Segments
### Algorithm for Selecting a Pair of Straight Line Segments  
As similarity measurement is employed to match SIFT feature points [23; 24], the wrong matching points are sometimes chosen, although it is very rare. Even if only one of the endpoints of the pair of straight line segment that were used to compute the depth of object is wrongly matched, the value of depth measurement would be widely inaccurate. Hence, we should select the longest straight line segment whose two endpoints will be matched correctly to the corresponding SIFT feature points in image \(B\). Because images \(A\) and \(B\) are captured when the object distance is \(u\) and \(u+d\), respectively, under the condition of keeping the camera's intrinsic properties unchanged, we can use similarity of polygons consisting of the SIFT matching points on the image \(A\) and image \(B\) to tell whether the matching point is wrong or not. In our experiment the polygon is a triangle. In other words, if the triangle \(\Delta ABC\) that consists of 3 SIFT feature points in image \(A\) is similar to the corresponding one \(\Delta A\)'\(B\)'\(C\)' in image \(B\), then there are no wrong matching points in the three vertices. Otherwise, there is one wrong matching point at least. Figure 4: Experimental results of the relation of the depth measurement average percent error to the length of the straight line segment. The differences between every corresponding angle of the two triangles are employed to decide whether the two triangles are similar, and we call the maximal angle difference is \(Ang_{max}\). If \(Ang_{max}<T_{a}\), then the two triangles are similar. Where the \(T_{a}\) is a threshold. The similarity of the triangle, one of whose sides is the longest line segment, should be determined; only in this way can we avoid the incorrect endpoints and minimize the error of depth measurement at the same time. It is impossible to determine which one or more vertices of triangle is/are the wrong matching point(s) when the triangle \(\Delta ABC\) is not similar to \(\Delta A\)'\(B\)'C'. Therefore, an algorithm for selecting a pair of straight line segments which are used to compute the depth is proposed. The main idea in the algorithm is as follows: we assume that the number of the triangles, one of whose sides is the longest straight line segment \(L\), is \(n_{1}\) in image \(A\). Obviously, there are \(n_{1}\) corresponding triangles in image \(B\), but only \(n_{2}\) pairs of triangles are similar. The \(L\) can be used to compute depth of object if \(n_{2}/n_{1}>T_{s}\), where \(T_{s}\) is a threshold. Otherwise, we should decide whether the next longest straight line segment is the one that we are seeking by the above method. The algorithm of selecting a pair of straight line segments is shown in the Algorithm 1. ```
Input: A sub-region in image \(A\) and its matched one in image \(B\) of the same object; The points set \(Q\) consists of the SIFT feature points of the object in image \(A\), and in image \(B\), the points set \(Q^{\prime}\) consists of the matched points of \(Q\). Output: A pair of straight line segments used to compute depth of object. ```  
Step1: Assume \(i=1\). Step2: Compute to obtain the points set \(P\), and the \(P\) is the convex hull of \(Q\). Step3: Compute to obtain the length of all of the straight line segments which are composed of any 2 points in \(P\), and put them in their length order, from the longest to the shortest. Step4: Count \(n_{1}\) and \(n_{2}\), where \(n_{1}\) is the number of triangles, one of whose side is the \(i\)-th longest line segment in image \(A\), and \(n_{2}\) is the number of the corresponding and similar triangles in image \(B\). Step5: If \(n_{2}/n_{1}>T_{s}\), go to step6; else, \(i=i+1\), and go to Step4. Step6: The \(i\)-th longest straight line segment in image \(A\) and the corresponding one in image \(B\) are the pair of straight line segments, which will be used to compute the depth of object. ```  
**Algorithm 1** The algorithm for selecting a pair of straight line segments.