Tutorial: Calibrated Rectification Using OpenCV ( Bouguet ’s Algorithm)
Algorithm FINDINTERSECTIONS( S ) Input: A set S of n line segments
-
Upload
colette-hammond -
Category
Documents
-
view
21 -
download
1
description
Transcript of Algorithm FINDINTERSECTIONS( S ) Input: A set S of n line segments
Algorithm FINDINTERSECTIONS(S)
Input: A set S of n line segments
Output: The set of intersection points (so that for eachintersection point we also return the segments that contain it)
Initialize an empty event queue Q
Insert the segment endpoints into Q (when an upper endpoint is inserted, the corresponding segment should be stored with it)
Initialize an empty status structure T
While Q is not empty Do
Determine the next event point p in Q and delete it.
HANDLEEVENTPOINT(p)
End While
HANDLEEVENTPOINT(p)
U(p)= the set of segments whose upper endpoint is p
(note: segments from U(p) are not in T)
Find all segments stored in T that contain p; they are adjacent in T
L(p) = the subset of segments found whose lower endpoint is p
C(p) = the subset of segments found that contain p in their interior
If L(p) ∪U(p)∪C(p) ∪contains more than one segment then
Report p as an intersection, together with L(p), U(p), and C(p)
End If
Delete the segments in L(p) ∪ C(p) from T
Insert the segments in U(p) ∪ C(p) into T
The order of the segments in T should correspond to the order in which they are intersected by a sweep line just below (deleting and re-inserting the segments of C(p) reverses their order)
If U(p) ∪C(p) is empty then
Let SL and SR be the left and right neighbors of p in T
FINDNEWEVENT( SL , SR , p )
Else
Let S’ be the leftmost segment of U(p)∪C(p) in T
Let SL be the left neighbor of s in T
FINDNEWEVENT(SL, S’, p)
Let S’’ ‘be the rightmost segment of U(p)∪C(p) in T
Let SR be the right neighbor of S’’ in T
FINDNEWEVENT(S’’ , SR , p)
FINDNEWEVENT(SL , SR, p)
If
SL and SR intersect below the sweep line, or on it and to the right of the current event point p, and the intersection is not yet present as an event in Q
Then
Insert the intersection point as an event into Q
Let q be the maximal number of event points in Q
Let I be the number of intersection points
Note that q ≤ number of intersection points + number of endpoints ≤ n2 (if n > 1)
Algorithm FINDINTERSECTIONS(S)
Input: A set S of line segments
Output: The set of intersection points (so that for eachintersection point we also return the segments that contain it)
Initialize an empty event queue Q
Insert the segment endpoints into Q (when an upper endpoint is inserted, the corresponding segment should be stored with it)
Initialize an empty status structure T
While Q is not empty Do
Determine the next event point p in Q and delete it.
HANDLEEVENTPOINT(p)
End While
O(n log n)
m(p) O( log n)
HANDLEEVENTPOINT(p)
U(p)= the set of segments whose upper endpoint is p
Find all segments stored in T that contain p; they are adjacent in T
L(p) = the subset of segments found whose lower endpoint is p
C(p) = the subset of segments found that contain p in their interior
If L(p) ∪U(p) ∪ C(p) ∪contains more than one segment then
Report p as an intersection, together with L(p), U(p), and C(p)
End If
Delete the segments in L(p) ∪ C(p) from T
Insert the segments in U(p) ∪ C(p) into T
The order of the segments in T should correspond to the order in which they are intersected by a sweep line just below (deleting and re-inserting the segments of C(p) reverses their order)
(|L(p)|+|C(p)|)O( log n)
(|U(p)|+|C(p)|)O( log n)
(|L(p)|+|U(p)|+|C(p)|)O( log n) = m(p) O( log n)
(|L(p)|+|U(p)|+|C(p)|)O( log n) = m(p) O( log n)
If U(p) ∪C(p) is empty then
Let SL and SR be the left and right neighbors of p in T
FINDNEWEVENT( SL , SR , p )
Else
Let S’ be the leftmost segment of U(p)∪C(p) in T
Let SL be the left neighbor of s in T
FINDNEWEVENT(SL, S’, p)
Let S’ be the rightmost segment of U(p)∪C(p) in T
Let SR be the right neighbor of S’ in T
FINDNEWEVENT(s, sr, p) O(log n)
O(log n)
O(log n)
FINDNEWEVENT(SL , SR, p)
If
SL and SR intersect below the sweep line, or on it and to the right of the current event point p, and the intersection is not yet present as an event in Q
Then
Insert the intersection point as an event into Q
O(log q) ≤ O(log n2) ≤ O(2 log n) = O(log n)