{'fraction_non_alphanumeric': 0.04760244790456271, 'fraction_numerical': 0.01018669145557363, 'mean_word_length': 3.7736895627253397, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
General techniques for approximate incidences and their application to the camera posing problem

We consider the classical camera pose estimation problem that arises in many computer vision applications, in which we are given n 2D-3D correspondences between points in the scene and points in the camera image (some of which are incorrect associations), and where we aim to determine the camera pose (the position and orientation of the camera in the scene) from this data. We demonstrate that this posing problem can be reduced to the problem of computing {\epsilon}-approximate incidences between two-dimensional surfaces (derived from the input correspondences) and points (on a grid) in a four-dimensional pose space. Similar reductions can be applied to other camera pose problems, as well as to similar problems in related application areas. We describe and analyze three techniques for solving the resulting {\epsilon}-approximate incidences problem in the context of our camera posing application. The first is a straightforward assignment of surfaces to the cells of a grid (of side-length {\epsilon}) that they intersect. The second is a variant of a primal-dual technique, recently introduced by a subset of the authors [2] for different (and simpler) applications. The third is a non-trivial generalization of a data structure Fonseca and Mount [3], originally designed for the case of hyperplanes. We present and analyze this technique in full generality, and then apply it to the camera posing problem at hand. We compare our methods experimentally on real and synthetic data. Our experiments show that for the typical values of n and {\epsilon}, the primal-dual method is the fastest, also in practice.


Introduction
Camera pose estimation is a fundamental problem in computer vision, which aims at determining the pose and orientation of a camera solely from an image. This localization problem appears in many interesting real-world applications, such as for the navigation of self-driving cars [5], in incremental environment mapping such as Structure-from-Motion (SfM) [1,11,13], or for augmented reality [8,9,14], where a significant component are algorithms that aim to estimate an accurate camera pose in the world from image data. Given a three-dimensional point-cloud model of a scene, the classical, but also stateof-the-art approach to absolute camera pose estimation consists of a two-step procedure. First, one matches a large number of features in the two-dimensional camera image with corresponding features in the three-dimensional scene. Then one uses these putative correspondences to determine the pose and orientation of the camera. Typically, the matches obtained in the first step contain many incorrect associations, forcing the second step to use filtering techniques to reject incorrect matches. Subsequently, the absolute 6 degreesof-freedom (DoF) camera pose is estimated, for example, with a perspective n-point pose solver [6] within a RANSAC scheme [4].
In this work we concentrate on the second step of the camera pose problem. That is, we consider the task of estimating the camera pose and orientation from a (potentially large) set of n already calculated image-to-scene correspondences.
Further, we assume that we are given a common direction between the world and camera frames. For example, inertial sensors, available on any smart-phone nowadays, allow to estimate the vertical gravity direction in the three-dimensional camera coordinate system. This alignment of the vertical direction fixes two degrees of freedom for the rotation between the frames and we are left to estimate four degrees of freedom out of the general six. To obtain four equations (in the four remaining degrees of freedom), this setup requires two pairs of image-to-scene correspondences 3 for a minimal solver. Hence a corresponding naive RANSAC-based scheme requires O(n 2 ) filtering steps, where in each iterations a pose hypothesis based on a different pair of correspondences is computed and verified against all other correspondences.
Recently, Zeisl et al. [17] proposed a Hough-voting inspired outlier filtering and camera posing approach, which computes the camera pose up to an accuracy of ε > 0 from a set of 2D-3D correspondences, in O(n/ε 2 ) time, under the same alignment assumptions of the vertical direction. In this paper we propose new algorithms that work considerably faster in practice, but under milder assumptions. Our method is based on a reduction of the problem to a problem of counting ε-approximate incidences between points and surfaces, where a point p is ε-approximately incident (or just ε-incident) to a surface σ if the (suitably defined) distance between p and σ is at most ε. This notion has recently been introduced by a subset of the authors in [2], and applied in a variety of instances, involving somewhat simpler scenarios than the one considered here. Our approach enables us to compute a camera pose when the number of correspondences n is large, and many of which are expected to be outliers. In contrast, a direct application of RANSAC-based methods on such inputs is very slow, since the fraction of inliers is small. In the limit, trying all pairs of matches involves Ω(n 2 ) RANSAC iterations. Moreover, our methods enhance the quality of the posing considerably [17], since each generated candidate pose is close to (i.e., consistent with) with many of the correspondences.
Our results. We formalize the four degree-of-freedom camera pose problem as an approximate incidences problem in Section 2. Each 2D-3D correspondence is represented as a two-dimensional surface in the 4-dimensional pose-space, which is the locus of all possible positions and orientations of the camera that fit the correspondence exactly. Ideally, we would like to find a point (a pose) that lies on as many surfaces as possible, but since we expect the data to be noisy, and the exact problem is inefficient to solve anyway, we settle for an approximate version, in which we seek a point with a large number of approximate incidences with the surfaces.
Formally, we solve the following problem. We have an error parameter ε > 0, we lay down a grid on [0, 1] d of side length ε, and compute, for each vertex v of the grid, a count I(v) of surfaces that are approximately incident to v, so that (i) every surface that is ε-incident to v is counted in I(v), and (ii) every surface that is counted in I(v) is αε-incident to v, for some small constant α > 1 (but not all αε-incident surfaces are necessarily counted). We output the grid vertex v with the largest count I(v) (or a list of vertices with the highest counts, if so desired).
As we will comment later, (a) restricting the algorithm to grid vertices only does not miss a good pose v: a vertex of the grid cell containing v serves as a good substitute for v, and (b) we have no real control on the value of I(v), which might be much larger than the number of surfaces that are ε-incident to v, but all the surfaces that we count are 'good'-they are reasonably close to v. In the computer vision application, and in many related applications, neither of these issues is significant.
We give three algorithms for this camera-pose approximate-incidences problem. The first algorithm simply computes the grid cells that each surface intersects, and considers the number of intersecting surfaces per cell as its approximate ε-incidences count. This method takes time O n ε 2 for all vertices of our ε-size grid. We then describe a faster algorithm using geometric duality, in Section 3. It uses a coarser grid in the primal space and switches to a dual 5-dimensional space (a 5-tuple is needed to specify a 2D-3D correspondence and its surface, now dualized to a point). In the dual space each query (i.e., a vertex of the grid) becomes a 3-dimensional surface, and each original 2-dimensional surface in the primal 4-dimensional space becomes a point. This algorithm takes O n 3/5 ε 14/5 + n + 1 ε 4 time, and is asymptotically faster than the simple algorithm for n > 1/ε 2 . Finally, we give a general method for constructing an approximate incidences data structure for general k-dimensional algebraic surfaces (that satisfy certain mild conditions) in R d , in Section 4. It extends the technique of Fonseca and Mount [3], designed for the case of hyperplanes, and takes O(n + poly(1/ε)) time, where the degree of the polynomial in 1/ε depends on the number of parameters needed to specify a surface, the dimension of the surfaces, and the dimension of the ambient space. We first present and analyze this technique in full generality, and then apply it to the surfaces obtained for our camera posing problem. In this case, the data structure requires O(n + 1/ε 6 ) storage and is constructed in roughly the same time. This is asymptotically faster than our primal-dual scheme when n ≥ 1/ε 16/3 (for n ≥ 1/ε 7 the O(n) term dominates and these two methods are asymptotically the same). Due to its generality, the latter technique is easily adapted to other surfaces and thus is of general interest and potential. In contrast, the primal-dual method requires nontrivial adaptation as it switches from one approximate-incidences problem to another and the dual space and its distance function depend on the type of the input surfaces.
We implemented our algorithms and compared their performance on real and synthetic data. Our experimentation shows that, for commonly used values of n and ε in practical scenarios (n ∈ [8K, 32K], ε ∈ [0.02, 0.03]), the primal-dual scheme is considerably faster than the other algorithms, and should thus be the method of choice. Due to lack of space, the experimentation details are omitted in this version, with the exception of a few highlights. They can be found in the appendix.

2
From camera positioning to approximate incidences Suppose we are given a pre-computed three-dimensional scene and a two-dimensional picture of it. Our goal is to deduce from this image the location and orientation of the camera in the scene. In general, the camera, as a rigid body in 3-space, has six degrees of freedom, three of translation and three of rotation (commonly referred to as the yaw, pitch and roll). We simplify the problem by making the realistic assumption, that the vertical direction of the scene is known in the camera coordinate frame (e.g., estimated by en inertial sensor on smart phones). This allows us to rotate the camera coordinate frame such that its z-axis is parallel to the world z-axis, thereby fixing the pitch and roll of the camera and leaving only four degrees of freedom (x, y, z, θ), where c = (x, y, z) is the location of the camera center, say, and θ is its yaw, i.e. horizontal the orientation of the optical axis around the vertical direction. See Figure 1.  Figure 1 With the knowledge of a common vertical direction between the camera and world frame the general 6DoF camera posing problem reduces to estimating 4 parameters. This is the setup we consider in our work.
By preprocessing the scene, we record the spatial coordinates w = (w 1 , w 2 , w 3 ) of a discrete (large) set of salient points. We assume that some (ideally a large number) of the distinguished points are identified in the camera image, resulting in a set of image-toscene correspondences. Each correspondence w = {w 1 , w 2 , w 3 , ξ, η} is parameterized by five parameters, the spatial position w and the position v = (ξ, η) in the camera plane of view of the same salient point. Our goal is to find a camera pose (x, y, z, θ) so that as many correspondences as possible are (approximately) consistent with it, i.e., the ray from the camera center c to w goes approximately through (ξ, η) in the image plane, when the yaw of the camera is θ.

Camera posing as an ε-incidences problem
Each correspondence and its 5-tuple w define a two-dimensional surface σ w in parametric 4space, which is the locus of all poses (x, y, z, θ) of the camera at which it sees w at coordinates (ξ, η) in its image. For n correspondences, we have a set of n such surfaces. We prove that each point in the parametric 4-space of camera poses that is close to a surface σ w , in a suitable metric defined in that 4-space, represents a camera pose where w is projected to a point in the camera viewing plane that is close to (ξ, η), and vice versa (see Section 2.2 for the actual expressions for these projections). Therefore, a point in 4-space that is close to a large number of surfaces represents a camera pose with many approximately consistent correspondences, which is a strong indication of being close to the correct pose.
Extending the notation used in the earlier work [2], we say that a point q is ε-incident to a surface σ if dist(q, σ) ≤ ε. Our algorithms approximate, for each vertex of a grid G ε of side length ε, the number of ε-incident surfaces and suggest the vertex with the largest count as the best candidate for the camera pose. This work extends the approximate incidences methodology in [2] to the (considerably more involved) case at hand.

The surfaces σ w
Let w = (w 1 , w 2 , w 3 ) be a salient point in R 3 , and assume that the camera is positioned at (c, θ) = (x, y, z, θ). We represent the orientation of the vector w − c, within the world frame, by its spherical coordinates (ϕ, ψ), except that, unlike the standard convention, we take ψ to be the angle with the xy-plane (rather than with the z-axis): In the two-dimensional frame of the camera the (ξ, η)-coordinates model the view of w, which differs from above polar representation of the vector w − c only by the polar orientation θ of the viewing plane itself. Writing κ for tan θ, we have We note that using tan θ does not distinguish between θ and θ + π, but we will restrict θ to lie in [−π/4, π/4] or in similar narrower ranges, thereby resolving this issue. We use R 4 with coordinates (x, y, z, κ) as our primal space, where each point models a possible pose of the camera. Each correspondence w is parameterized by the triple (w, ξ, η), and defines a two-dimensional algebraic surface σ w of degree at most 4, whose equations (in x, y, z, κ) are given in (1). It is the locus of all camera poses v = (x, y, z, κ) at which it sees w at image coordinates (ξ, η). We can rewrite these equations into the following parametric representation of σ w , expressing z and κ as functions of x and y: For a camera pose v = (x, y, z, κ), and a point w = (w 1 , w 2 , w 3 ), we write In this notation we can write the Equations (1) characterizing σ w (when regarded as equations in v) as ξ = F (v; w) and η = G(v; w).

Measuring proximity
Given a guessed pose v = (x, y, z, κ) of the camera, we want to measure how well it fits the scene that the camera sees. For this, given a correspondence w = (w, ξ, η), we define the frame distance fd between v and w as the L ∞ -distance between (ξ, η) and (ξ v , η v ), where, as in Eq.
Note that (ξ v , η v ) are the coordinates at which the camera would see w if it were placed at position v, so the frame distance is the L ∞ -distance between these coordinates and the actual coordinates (ξ, η) at which the camera sees w; this serves as a natural measure of how close v is to the actual pose of the camera. We are given a viewed scene of n distinguished points (correspondences) w = (w, ξ, η). Let S denote the set of n surfaces σ w , representing these correspondences. We assume that the salient features w and the camera are all located within some bounded region, say [0, 1] 3 . The replacement of θ by κ = tan θ makes its range unbounded, so we break the problem into four subproblems, in each of which θ is confined to some sector. In the first subproblem we assume that −π/4 ≤ θ ≤ π/4, so −1 ≤ κ ≤ 1. The other three subproblems involve the ranges [π/4, 3π/4], [3π/4, 5π/4], and [5π/4, 7π/4]. We only consider here the first subproblem; the treatment of the others is fully analogous. In each such range, replacing θ by tan θ does not incur the ambiguity of identifying θ with θ + π.
Given an error parameter ε > 0, we seek an approximate pose v of the camera, at which many correspondences w are within frame distance at most ε from v, as given in (4).
The following two lemmas relate our frame distance to the Euclidean distance. Their (rather technical) proofs are given in the appendix.
Informally, Condition (i) requires that the absolute value of the ξ = tan(ϕ−θ) coordinate of the position of w in the viewing plane, with the camera positioned at v, is not too large (i.e., that |(ϕ − θ)| is not too close to π/2). We can ensure this property by restricting the camera image to some suitably bounded ξ-range.
Similarly, Condition (ii) requires that the xy-projection of the vector w − c is not too small. It can be violated in two scenarios. Either we look at a data point that is too close to c, or we see it looking too much 'upwards' or 'downwards'. We can ensure that the latter situation does not arise, by restricting the camera image, as in the preceding paragraph, to some suitably bounded η-range too. That done, we ensure that the former situation does not arise by requiring that the physical distance between c and w be at least some multiple of a.
The next lemma establishes the converse connection.
Informally, the condition |(w 1 − x) + ξ(w 2 − y)| ≥ a > 0 means that the orientation of the camera, when it is positioned at (x, y) and sees w at coordinate ξ of the viewing plane is not too close to ±π/2. This is a somewhat artificial constraint that is satisfied by our restriction on the allowed yaws of the camera (the range of κ).
A Simple algorithm. Using Lemma 2.2 and Lemma 2.1 we can derive a simple naive solution which does not require any of the sophisticated machinery developed in this work.
We construct a grid G over where a is the constant of Lemma 2.2. We use this non-square grid G since we want to find ε-approximate incidences in terms of frame distance. For each cell τ of G we compute the number of surfaces σ w that intersect τ . This gives an approximate incidences count for the center of τ . Further details and a precise statement can be found in the appendix.

Primal-dual algorithm for geometric proximity
Following the general approach in [2], we use a suitable duality, with some care. We write ε = 2γδ 1 δ 2 , for suitable parameters γ, and ε/(2γ) ≤ δ 1 , δ 2 ≤ 1, whose concrete values are fixed later, and apply the decomposition scheme developed in [2] tailored to the case at hand. Specifically, we consider the coarser grid G δ1 in the primal space, of cell dimensions For each cell τ of G δ1 , let S τ denote the set of surfaces that cross either τ or one of the eight cells adjacent to τ in the (z, κ)-directions. 4 The duality is illustrated in Figure 2. We discretize the set of all possible positions of the camera by the vertices of the finer grid G ε , defined as G δ1 , with ε replacing δ 1 , that tiles up Q. The number of these candidate positions is m := O(1/ε 4 ). For each vertex q ∈ G ε , we want to approximate the number of surfaces that are ε-incident to q, and output the vertex with the largest count as the best candidate for the position of the camera. Let V τ be the subset of G ε contained in τ . We ensure that the boxes of G δ1 are pairwise disjoint by making them half open, in the sense that if (x 0 , y 0 , z 0 , κ 0 ) is the vertex of a box that has the smallest coordinates, then the box is defined by This makes the sets V τ pairwise disjoint as well. Put m τ = |V τ | and n τ = |S τ |. We have 4 for each τ . Since the surfaces σ w are two-dimensional algebraic surfaces of constant degree, each of them crosses O(1/δ 2 1 ) cells of G δ1 , so we have τ n τ = O(n/δ 2 1 ). We now pass to the dual five-dimensional space. Each point in that space represents a correspondence w = (w 1 , w 2 , w 3 , ξ, η). We use the first three components (w 1 , w 2 , w 3 ) as the first three coordinates, but modify the ξ-and η-coordinates in a manner that depends on the primal cell τ . Let , with F and G as given in (3). We have Corollary 3.1. If σ w crosses τ then |ξ τ |, |η τ | ≤ γδ 1 , for some absolute constant γ, provided that the following two properties hold, for some absolute constant a > 0 (the constant γ depends on a).
Proof. If σ w ∈ S τ then it contains a point v such that |v − c τ | ≤ c δ 1 , for a suitable absolute constant c (that depends on c). We now apply Lemma 2.1, recalling (4).
We take the γ provided by Corollary 3.1 as the γ in the definition of δ 1 and δ 2 . We map By Corollary 3.1, the points w τ , for the surfaces σ w that cross τ , lie in the region Exactly as in the primal setup, we make each of these boxes half-open, thereby making the sets of dual vertices in the smaller boxes pairwise disjoint. We assign to each of these dual cells τ * the set S * τ * of dual points that lie in τ * , and the set V * τ * of the dual surfaces that cross either τ * or one of the eight cells adjacent to τ * in the (ξ τ , η τ )-directions. Put n τ * = |S * τ * | and m τ * = |V * τ * |. Since the dual cells are pairwise disjoint, we have τ * n τ * = n τ . Since the dual surfaces are three-dimensional algebraic surfaces of constant degree, each of them crosses O(1/δ 3 2 ) grid cells, so τ * m τ * = O m τ /δ 3 2 . We compute, for each dual surface σ * v , the sum τ * |S * τ * |, over the dual cells τ * that are either crossed by σ * v or that one of their adjacent cells in the (ξ τ , η τ )-directions is crossed by σ * v . We output the vertex v of G ε with the largest resulting count, over all primal cells τ .
The following theorem establishes the correctness of our technique. Its proof is given in Appendix B.

Theorem 3.2.
Suppose that for every cell τ ∈ G δ1 and for every point v = (x, y, z, κ) ∈ V τ and every w = ((w 1 , w 2 , w 3 ), ξ, η) such that σ w intersects either τ or one of its adjacent cells in the (ξ τ , η τ )-directions, we have that, for some absolute constant a > 0, every pair (v, w) that we count lies at frame distance ≤ αε, for some constant α > 0 depending on a.

Running time analysis
The cost of the algorithm is clearly proportional to τ τ * (m τ * + n τ * ) , over all primal cells τ and the dual cells τ * associated with each cell τ . We have Optimizing the choice of δ 1 and δ 2 , we choose δ 1 = ε 3 n m 1/5 and δ 2 = ε 2 m n 1/5 . These choices make sense as long as each of δ 1 , δ 2 lies between ε/(2γ) and 1. That is, ε 2γ ≤ where c and c are absolute constants (that depend on γ).
If n < c ε 2 m, we use only the primal setup, taking δ 1 = ε (for the primal subdivision).

The cost is then
. In conclusion, we have the following result.

Theorem 3.3.
Given n data points that are seen (and identified) in a two-dimensional image taken by a vertically positioned camera, and an error parameter ε > 0, where the viewed points satisfy the assumptions made in Theorem 3.2, we can compute, in O n 3/5 ε 14/5 + n + 1 ε 4 time, a vertex v of G ε that maximizes the approximate count of ε-incident correspondences, where "approximate" means that every correspondence w whose surface σ w is at frame distance at most ε from v is counted and every correspondence that we count lies at frame distance at most αε from v, for some fixed constant α.
Restricting ourselves only to grid vertices does not really miss any solution. We only lose a bit in the quality of approximation, replacing ε by a slightly large constant multiple thereof, when we move from the best solution to a vertex of its grid cell.

Geometric proximity via canonical surfaces
In this section we present a general technique to preprocess a set of algebraic surfaces into a data structure that can answer approximate incidences queries. In this technique we round the n original surfaces into a set of canonical surfaces, whose size depends only on ε, such that each original surface has a canonical surface that is "close" to it. Then we build an octree-based data structure for approximate incidences queries with respect to the canonical surfaces. However, to reduce the number of intersections between the cells of the octree and the surfaces, we further reduce the number of surfaces as we go from one level of the octree to the next, by rounding them in a coarser manner into a smaller set of surfaces. This technique has been introduced by Fonseca and Mount [3] for the case of hyperplanes. We describe as a warmup step, in Section C of the appendix, our interpretation of their technique applied to hyperplanes. We then extend here the technique to general surfaces, and apply it to the specific instance of 2-surfaces in 4-space that arise in the camera pose problem.
We have a set S of n k-dimensional surfaces in R d that cross the unit cube [0, 1] d , and a given error parameter ε. We assume that each surface σ ∈ S is given in parametric form, where the first k coordinates are the parameters, so its equations are Moreover, we assume that each σ ∈ S is defined in terms of essential parameters t = (t 1 , . . . , t ), and d − k additional free additive parameters f = (f k+1 , . . . , f d ), one free parameter for each dependent coordinate. Concretely, we assume that the equations defining the surface σ ∈ S, parameterized by t and f (we then denote σ as σ t,f ), are For each equation of the surface that does not have a free parameter in the original expression, we introduce an artificial free parameter, and initialize its value to 0. (We need this separation into essential and free parameters for technical reasons that will become clear later.) We assume that t (resp., f ) varies over [0, 1] (resp., [0, 1] d−k ).
Remark. The distinction between free and essential parameters seems to be artificial, but yet free parameters do arise in certain basic cases, such as the case of hyperplanes discussed in Section C of the appendix. In the case of our 2-surfaces in 4-space, the parameter w 3 is free, and we introduce a second artificial free parameter into the equation for κ. The number of essential parameters is = 4 (they are w 1 ,w 2 ,ξ, and η).
We assume that the functions F j are all continuous and differentiable, in all of their dependent variables x, t and f (this is a trivial assumption for f ), and that they satisfy the following two conditions.
for any x ∈ [0, 1] k and any t ∈ [0, 1] , where c 1 is some absolute constant. Here ∇ x (resp., ∇ t ) means the gradient with respect to only the variables x (resp., t).
for any x ∈ [0, 1] k and any t, t ∈ [0, 1] , where c 2 is some absolute constant. This assumption is implied by the assumption that all the eigenvalues of the mixed part of the Hessian matrix ∇ t ∇ x F j (x; t) have absolute value bounded by c 2 .

Canonizing the input surfaces
We first replace each surface σ t,f ∈ S by a canonical "nearby" surface σ s,g . Let ε = ε c2 log(1/ε) where c 2 is the constant from Condition (ii). We get s from t (resp., g from f ) by rounding each coordinate in the essential parametric domain L (resp., in the parametric domain Φ) to a multiple of ε /( + 1). Note that each of the artificial free parameters (those that did not exist in the original equations) has the initial value 0 for all surfaces, and remains 0 in the rounded surfaces. We get O (1/ε ) canonical rounded surfaces, where ≥ is the number of original parameters, that is, the number of essential parameters plus the number of non-artificial free parameters; in the worst case we have = + d − k.
For a surface σ t,f and its rounded version σ s,g we have, for each j, where t is some intermediate value, which is irrelevant due to Condition (i).
We will use the 2 -norm of the difference vector ( as the measure of proximity between the surfaces σ t,f and σ s,g at x, and denote it as dist(σ t,f , σ s,g ; x). The maximum dist(σ t,f , σ s,g ) := max x∈[0,1] k dist(σ t,f , σ s,g ; x) measures the global proximity of the two surfaces. (Note that it is an upper bound on the Hausdorff distance between the two surfaces.) We thus have dist(σ t,f , σ s,g ) ≤ (c 1 + 1)ε when σ s,g is the canonical surface approximating σ t,f . We define the weight of each canonical surface to be the number of original surfaces that got rounded to it, and we refer to the set of all canonical surfaces by S c .

Approximately counting ε-incidences
We describe an algorithm for approximating the ε-incidences counts of the surfaces in S and the vertices of a grid G of side length 4ε.
We construct an octree decomposition of τ 0 := [0, 1] d , all the way to subcubes of side length 4ε such that each vertex of G is the center of a leaf-cube. We propagate the surfaces of S c down this octree, further rounding each of them within each subcube that it crosses.
The root of the octree corresponds to τ 0 , and we set S τ0 = S c . At level j ≥ 1 of the recursion, we have subcubes τ of τ 0 of side length δ = 1/2 j . For each such τ , we setS τ to be the subset of the surfaces in S p(τ ) (that have been produced at the parent cube p(τ ) of τ ) that intersect τ . We now show how to further round the surfaces ofS τ , so as to get a coarser set S τ of surfaces that we associate with τ , and that we process recursively within τ . At any node τ at level j of our rounding process, each surface σ of S τ is of the form . . . , x k ), and t = (t 1 , . . . , t ).
(a) For each j = k + 1, . . . , d the function H j is a translation of F j . That is H j (x; t) = F j (x; t) + c for some constant c. Thus the gradients of H j also satisfy Conditions (i) and (ii).
(b) t is some vector of essential parameters, and each coordinate of t is an integer multiple of ε ( +1)δ , where δ = 1/2 j . (c) f = (f k+1 , . . . , f d ) is a vector of free parameters, each is a multiple of ε /( + 1).
Note that the surfaces in S τ0 = S c , namely the set of initial canonical surfaces constructed in Section 4.1, are of this form (for j = 0 and H j = F j ). We get S τ fromS τ ⊆ S p(τ ) by the following steps. The first step just changes the presentation of τ andS τ , and the following steps do the actual rounding to obtain S τ .

1.
Let (ξ 1 , . . . , ξ k , ξ k+1 , . . . , ξ d ) be the point in τ of smallest coordinates and set ξ = (ξ 1 , . . . , ξ k ). We rewrite the equations of each surface ofS τ as follows: Note that in this reformulation we have not changed the essential parameters, but we did change the free parameters from f j to f j , where f j depends on f j , t, ξ, and ξ j . Note also that G j (ξ; t) = ξ j for j = k + 1, . . . , d.

2.
We replace the essential parameters t of a surface σ t,f by s, which we obtain by rounding each coordinate of t to the nearest integer multiple of ε ( +1)δ . So the rounded surface has the equations x j = G j (x; s) + f j , for j = k + 1, . . . , d. Note that we also have that G j (ξ; s) = ξ j , for j = k + 1, . . . , d.

3.
For each surface, we round each free parameter f j , j = k+1, . . . , d, to an integral multiple of ε +1 , and denote the rounded vector by g. Our final equations for each rounded surface that we put in S τ are x j = G j (x; s) + g j for j = k + 1, . . . , d.
By construction, when t 1 and f 1 and t 2 and f 2 get rounded to the same vectors s and g then the corresponding two surfaces inS τ get rounded to the same surface in S τ . The weight of each surface in S τ is the sum of the weights of the surfaces in S p(τ ) that got rounded to it, which, by induction, is the number of original surfaces that are recursively rounded to it. In the next step of the recursion the H j 's of the parametrization of the surfaces in S τ are the functions G j defined above.
The total weight of the surface in S τ for a leaf cell τ is the approximate ε-incidences count that we associate with the center of τ .

Error analysis
We now bound the error incurred by our discretization. We start with the following lemma, whose proof is given in Appendix .
where c 2 is the constant of Condition (ii), and ξ = (ξ 1 , . . . , ξ k ) consists of the first k coordinates of the point in τ of smallest coordinates.

for any t, s ∈ [0, 1] , and for each
where c 2 is the constant of Condition (ii).
We now bound the number of surfaces in S τ . Since s ∈ [0, 1] and each of its coordinates is a multiple of ε ( +1)δ , we have at most ( δ ε ) different values for s. To bound the number of possible values of g, we prove the following lemma (see the appendix for the proof).
It follows that each level of the recursive octree decomposition generates re-discretized surfaces, where the first factor in the left-hand side expression is the number of cubes generated at this recursive level, and the second factor is the one in (7).
Summing over the recursive levels j = 0, . . . , log 1 ε , where the cube size δ is 1/2 j at level j, we get a total size of O . We get different estimates for the sum according to the sign of − k. If > k the sum is O (1).
. Accordingly, the overall size of the structure, taking also into account the cost of the first phase, is The following theorem summarizes the result of this section. Its proof follows in a straightforward way from the preceding discussion from Lemma 4.2, analogously to the proof of Lemma 4.3 in the appendix.  and t = (t 1 , . . . , t ). Let G be the (4ε)-grid within [0, 1] d . The algorithm described above reports for each vertex v of G an approximate ε-incidences count that includes all surfaces at distance at most ε from v and may include some surfaces at distance at most

. The running time of this algorithm is proportional to the total number of rounded surfaces that it generates, which is given by Equation (8), plus an additive O(n) term for the initial canonization of the surfaces.
We can modify our data structure so that it can answer approximate or exact ε-incidence queries as we describe in Section C of the appendix for the case of hyperplanes.

Experimental Results
The goal of the experimental results is to show the practical relation between the naive, the primal-dual and the general canonical surfaces algorithms. It is not our intention to obtain the fastest possible code, but to obtain a platform for fair comparison between the techniques. We have performed a preliminary experimental comparison using synthetic as well as real-world data. We focus on values of n, ε that are practical in real applications. Typically, we have 100K-200K 3D points bounded by a rectangle of size 100-150 meters and the uncertainty is around 3m (so the relative error is ε = 0.03). The three methods that we evaluate are: The naive method, with asymptotic run-time O( n ε 2 ). The primal-dual method (cf. Section 3), with asymptotic run-time O(n + n 3/5 ε 14/5 + 1 ε 4 ). The canonical surfaces method (cf. Section 4), with asymptotic run-timeÕ(n + 1 ε 6 ) (ignoring poly logarithmic factors).
In all experiments we normalize the data, so that the camera position (x, y, z) and the 3D points lie in the unit box [0, 1] 3 , and the forth parameter (κ) representing the camera orientation lies in [−1, 1].

Random synthetic data
Starting from a fixed known camera pose, we generate a set of n uniformly sampled 3D points which are projected onto the camera image plane using Eq. (1). To model outliers in the association process we use random projections for 90% of the 3D points, resulting in an inlier ratio of 10%. We add Gaussian noise of zero mean and σ = 0.02 to the coordinates of each 3D point. This provides us with 2D-3D correspondences that are used for estimating the camera pose. We apply the three algorithms above and measure the run-times, where each algorithm is tested for its ability to reach approximately the (known) solution. We remark that the actual implementation may be slowed down by the (constant) cost of some of its primitive operations, but it can also gain efficiency from certain practical heuristic improvements. For example, in contrast to the worst case analysis, we could stop the recursion in the algorithm of Section 4, at any step of the octree expansion, whenever the maximum incidence count obtained so far is larger than the number of surfaces crossing a cell of the octree. The same applies for the primal-dual technique in the dual stage. On the other hand, finding whether or not a surface crosses a box in pose space, takes at least the time to test for intersections of the surface with 32 edges of the box, and this constant affects greatly the run-time. The O(1/ε 6 ) bound in the canonical surfaces algorithm is huge and has no effect in practice for this problem. For this reason, the overall number of surfaces that we have to consider in the recursion can be very large. The canonical surfaces algorithm in our setting does not change much with ε because we are far from the second term effect. We show in Figure 3, a comparison of the three algorithms. The computed camera poses corresponding to Figure 3, obtained by the three algorithm for various problem sizes, are displayed in Table 1, compared to the known pose. The goal here is not to obtain the most accurate algorithm but to show that they are comparable in accuracy in this setting so the runtime comparison is fair.  Table 1 Poses computed by the three algorithms for ε = 0.03 and various problem sizes (N:naive, PD:primal-dual, C:canonical surfaces).

Real-world data
We evaluated the performance of the algorithms also on real-world datasets for which the true camera pose is known. The input is a set of correspondences, each represented by a 5- tuple (w 1 , w 2 , w 3 , ξ, η), where (w 1 , w 2 , w 3 ) are the 3D coordinates of a salient feature in the scene and (ξ, η) is its corresponding projection in the camera frame. We computed the camera pose from these matches using both primal-dual and naive algorithms and compared the poses to the true one. An example of the data we have used is shown in Figure 4.

Figure 4 Real-world data input and pose
We evaluated the runtime for different problem sizes and checked the correctness of the camera pose approximation when the size increased. To get different input sizes, we added random correspondences to a base set of actual correspondences. The number of random correspondences determines the input size but also the fraction of good correspondences (percentage of inliers) which goes down with increased input size (the number of inliers in real world cases is typically 10%). We show the same plots as before in Figure 5 and Table  2.  Table 2 Poses computed by the primal-dual algorithms for real-world data (we do not know the actual orientation here).

6
Future work

A Omitted proofs
In all experiments we normalize the data, so that the camera position (x, y, z) and the 3D points lie in the unit box [0, 1] 3 , and the forth parameter (κ) representing the camera orientation lies in [−1, 1]. Let ξ v := F (v; w), We apply the three algorithms above and measure the run-times, where each algorithm is tested for its ability to reach approximately the (known) solution. We remark that the actual implementation may be slowed down by the (constant) cost of some of its primitive operations, but it can also gain efficiency from certain practical heuristic improvements. For example, in contrast to the worst case analysis, we could stop the recursion in the algorithm of Section 4, at any step of the octree expansion, whenever the maximum incidence count obtained so far is larger than the number of surfaces crossing a cell of the octree. The same applies for the primal-dual technique in the dual stage. On the other hand, finding whether or not a surface crosses a box in pose space, takes at least the time to test for intersections of the surface with 32 edges of the box, and this constant affects greatly the run-time. The O(1/ε 6 ) bound in the canonical surfaces algorithm is huge and has no effect in practice for this problem. For this reason, the overall number of surfaces that we have to consider in the recursion can be very large. The canonical surfaces algorithm in our setting does not change much with ε because we are far from the second term effect. We show in Figure 3, a comparison of the three algorithms.
Regarding F and G as functions of v, we compute their gradients as follows. and Conditions (i) and (ii) in the lemma, plus the facts that we restrict both (w 1 , w 2 , w 3 ) and (x, y, z) to lie in the bounded domain [0, 1] 3 , and that |κ| is also at most 1, are then easily seen to imply that the v-gradients |∇F |, |∇G| are at most β, for some constant β that depends on a, and so |ξ v − ξ| ≤ β|v − v | ≤ βε and |η v − η| ≤ β|v − v | ≤ βε, and the lemma follows.

Proof of Lemma 2.2: Let
Since the Equations (2) are the inverse system of those of (1), we can rewrite (9) as Hence It follows right away that |z − z | ≤ √ 2ε (recall that all the points lie in the unit cube). For the other difference, writing (with the other parameters being fixed), we get As is easily verified, we have Since |(w 1 − x) + ξ(w 2 − y)| ≥ a > 0, and |ξ v − ξ| ≤ ε, the denominator of H (t) is bounded away from zero (assuming that ε is sufficiently small), and |H (t)| ≤ c for t ∈ [ξ, ξ v ], where c is some fixed positive constant. This implies that |κ − κ | ≤ cε, and the lemma follows.

Proof of Theorem 3.2. Part (a):
Let (v, w) be a pair at frame distance ≤ ε. By Lemma 2.2 and the definition of G δ1 , there exists a cell τ ∈ G δ1 such that v ∈ τ and w ∈ S τ . By definition, the surface σ * v;τ contains the point where ξ v and η v are given by (9). Since fd(v, w) ≤ ε, the points (w 1 , Together, these two properties imply that (v, w) is counted by the algorithm. Moreover, since we kept both primal and dual boxes pairwise disjoint, each such pair is counted exactly once. Part (b): Let (v, w) be an ε-incident pair that we encounter, where v and w are encoded as above. That is, σ w crosses the primal cell τ of G δ1 that contains v, or a neighboring cell in the (z, κ)-directions, and σ * v;τ crosses the dual cell τ * that contains w τ , or a neighboring cell in the (ξ τ , η τ )-directions. This means that τ (or a neighboring cell) contains a point c = (x , y , z , κ ) ∈ σ w , and τ * (or a neighboring cell) contains a point w τ = (w 1 , w 2 , w 3 , ξ τ , η τ ) ∈ σ * v;τ . The former containment means that and that To interpret the latter containment, we write, using the definition of ξ τ , η τ , and the fact that w τ ∈ σ * v;τ , where w = (w 1 , w 2 , w 3 ), and where c τ = (x τ , y τ , z τ , κ τ ) is the centerpoint of τ , and By definition (of F , G, and the frame distance), we have which we can bound by writing We are given that so it remains to bound the other term in each of the two right-hand sides. Consider for example the expression Write c τ = v + t and w = w + s, for suitable vectors t, s ∈ R 3 . We expand the expression up to second order, by writing where ∇ w (resp., ∇ v ) denotes the gradient with respect to the variables w (resp., v), and where H w (resp., H v , H v;w ) denotes the Hessian submatrix of second derivatives in which both derivatives are with respect to w (resp., both are with respect to v, one derivative is with respect to v and the other is with respect to w). Substituting in (10), we get that, up to second order, where H v;w (v; w) ∞ is the maximum of the absolute values of all the "mixed" second derivatives. (Note that the mixed part of the Hessian of the Hessian arises also in the analysis of the algorithm in Section 4.) Arguing as in the preceding analysis and using the assumptions in the theorem, one can show that all these derivatives are bounded by some absolute constants, concluding that which implies that Applying an analogous analysis to G, we also have Together, these bounds complete the proof of part (b) of the theorem.
Proof of Lemma 4.1: Fix j, consider the function and recall our assumption that G j (ξ; t) = G j (ξ; s) = ξ j . Then we can also write the lefthand side of (5) as K j (x) − K j (ξ). By the intermediate value theorem, it can be written as for some intermediate value x (that depends on s and t). By definition, we have, whose norm is bounded by c 2 |s − t| by Condition (ii). Using the Cauchy-Schwarz inequality, we can thus conclude that as asserted.
where the first inequality follows by the triangle inequality, the second follows since ξ j − (f j + G j (x; t)) ≤ δ, the third by the intermediate value theorem and the Cauchy-Schwarz inequality, and the fourth by Condition (i).

B A simple algorithm
We present a simple naive solution which does not require any of the sophisticated machinery developed in this work. It actually turns out to be the most efficient solution when n is small.
We construct a grid G over 2ε × 2cε, where c is the constant of Lemma 2.2. (We use this non-square grid G since we want to find ε-approximate incidences in terms of frame distance.) For each cell τ of G we compute the number of surfaces σ w that intersect τ .
Consider now a shifted version G of G in which the vertices of G are the centers of the cells of G. To report how many surfaces are within frame distance ε from a vertex q ∈ G , we return the count of the cell of G whose center is q. By Lemma 2.2 and Lemma 2.1, this includes all surfaces at frame distance ε from q, but may also count surfaces at frame distance at most √ 10 + 4c 2 βε from q, where β is the constant in Lemma 2.1. (The distance from q to the farthest corner of its cell is 1 2 + 1 2 + (2c) 2 + (2 √ 2) 2 ε = √ 10 + 4c 2 βε.) It takes O( n ε 2 ) time to construct this data structure. Indeed, cell boundaries reside on O( 1 ε ) hyperplanes, so we compute the intersection curve of each surface with each of these hyperplanes, in a total of O( n ε ) time. Then, for each such curve we find the cell boundaries that it intersects within its three-dimensional hyperplane in O( 1 ε ) time. We summarize this result in the following theorem.
Theorem B.1. The algorithm described above approximates the the number of surfaces that are at distance ε to each vertex In fact we can find for each vertex q of G , the exact number of ε-incident surfaces (i.e. surfaces at distance at most ε from q). For this we keep with each cell τ of G, the list of the surfaces that intersect τ . Then for each vertex q ∈ G we traverse the surfaces stored in its cell and check which of them is within frame distance ε from q. The asymptotic running time is still O( n ε 2 ). If we want to get an incidences counts of vertices of a finer grid that G, we use a union of several shifted grids as above. This also allows to construct a data structure that can return an ε-incidences count of any query point.
For the camera pose problem we use the vertex of G ε of largest ε-incidences count as the position of the camera.

C Geometric proximity via canonical surfaces: The case of hyperplanes
We have a set H of n hyperplanes in R d that cross the unit cube τ 0 = [0, 1] d , and a given error parameter ε. Each hyperplane h ∈ H is given by an equation of the form We assume, for simplicity, that |a i | ≤ 1 for each h ∈ H and for each i = 1, . . . , d − 1. Moreover, since h crosses τ 0 , we have |b| ≤ d, as is easily checked. (This can always be enforced by rewriting the equation turning the x i with the coefficient a i of largest absolute value into the independent coordinate.) For our rounding scheme we define ε = ε/ log(1/ε). We discretize each hyperplane h ∈ H as follows. Let the equation of h be x d = d−1 i=1 a i x i + b. We replace each a i by the integer multiple of ε /d that is nearest to it, and do the same for b. Denoting these 'snapped' values as a i and b , respectively, we replace h by the hyperplane h , given by For any x = (x 1 , . . . , x d−1 ) ∈ [0, 1] d−1 , the x d -vertical distance between h and h at x is We define the weight of each canonical hyperplane to be the number of original hyperplanes that got rounded to it, and we refer to the set of all canonical hyperplanes by H c . We describe a recursive procedure that approximates the number of ε-incident hyperplanes of H to each vertex of a (4ε)-grid G that tiles up [0, 1] d . Specifically, for each vertex v of G we report a count that includes all hyperplanes in H that are at Euclidean distance at most ε from v but it may also count hyperplanes of H that are at distance up to (2 √ d + 1)ε from v.
Our procedure constructs an octree decomposition of τ 0 , all the way to subcubes of side length 4ε. (We assume that 4ε is a negative power of 2 to avoid rounding issues.) We shift the grid G such that its vertices are centers of these leaf-subcubes. At level j of the recursive construction, we have subcubes τ of side length δ = 1/2 j . For each such τ we construct a set H τ of more coarsely rounded hyperplanes. The weight of each hyperplane h in H τ is the sum of the weights of the hyperplanes in the parent cube p(τ ) of τ that got rounded to h, which, by induction, is the number of original hyperplanes that are rounded to it (by repeated rounding along the path in the recursion tree leading to τ ).
At the root, where j = 0, we set H τ = H c (where each h ∈ H τ has the initial weight of the number of original hyperplanes rounded to it, as described above). At any other cell τ we obtain H τ by applying a rounding step to the setH τ of the hyperplanes of H p(τ ) that intersect τ .
The coarser discretization of the hyperplanes ofH τ that produces the set H τ proceeds as follows. Let (ξ 1 , . . . , ξ d ) denote the coordinates of the corner of τ with smallest coordinates, Let h be a hyperplane of H τ , and rewrite its equation as This rewriting only changes the value of b but does not affect the a i 's. Since h crosses τ , we have |b| ≤ dδ (and |a i | ≤ 1 for each i). We now re-discretize each coefficient a i (resp., b) to the integer multiple of ε dδ (resp., ε d ) that is nearest to it. Denoting these snapped values as a i and b , respectively, we replace h by the hyperplane h given by This re-discretization of the coefficients a i is a coarsening of the discretization of the hyperplanes inH τ . The set H τ contains all the new, more coarsely rounded hyperplanes that we obtain from the hyperplanes inH τ in this manner. Note that several hyperplanes inH τ may be rounded to the same hyperplane in H τ . We set the weight of each hyperplane in H τ to be the sum of the weights of the hyperplanes inH τ that got rounded to it. (Note that although every hyperplane ofH τ crosses τ , such an h may get rounded to a hyperplane that misses τ , in which case it is not represented by any hyperplane in H τ .) Our octree data structure can give an approximate ε-incidences count for any query point q (albeit with somewhat worse constants). For this we construct a constant number of octree structures over 5 d shifted (by intergral multiple of ε) grids of a somewhat larger side-length, say 5ε. The grids are shifted such that each cell c of a finer grid of side length ε is centered in a larger grid cell of one of our grids, say G c . We use G c to answer queries q that lie in c, by returning the sum of the weights of the hyperplanes in h τ where τ is the leaf of G c containing q.
We can also modify this data structure such that it can answer ε-incidences queries exactly. That is, given a query point q, it can count (or report) the number of hyperplanes at distance at most ε from q and only these hyperplanes. To do this we maintain pointers from each hyperplane h in H τ to the hyperplanes in H p(τ ) that got rounded to h. To answer a query q, we find the leaf cell τ containing q and then we traverse back the pointers of the hyperplanes of H τ all the way up the octree to identify the original hyperplanes that were rounded to them. We then traverse this set of original hypeprlanes and count (or report) those that are at distance at most ε from q.