## 3 Proposed Error Compensation Method  
### Pattern Detection and Pose Estimation  
In this study, the world coordinate system is located on the pattern board, which is the calibrated workspace for the robot. For simple detection and pose estimation of the pattern board, we designed a specific pattern image as seen in Figure 3a. The circles on the pattern board are numbered as seen in Figure 3d, four bigger circles. The pattern board consists of the key feature made of four big circles, which are used to create the workspace coordinate, and the rest of the circles with smaller size are used for the pose estimation. The operation of the pre-compensation system is divided into two stages: the pattern detection and pose estimation. For pattern image detection we moved the robot to the pattern board, then the hole geometry was extracted from the image. In the pose estimation stage, the Perspective-n-Point (PnP) method based on the RANSAC-algorithm was used to estimate the coordinate of the pattern corresponding to the camera system. Figure 2: The overall architecture of proposed error compensation algorithm. In the pattern detection stage, we extracted the holes section from image data via the edge detection algorithm as shown in Figure 3b. We applied a Difference-of-Gaussian (DoG) filter to remove noise and improve the geometry shape of the holes. DoG is accomplished by convolving the image with a Gaussian filter at different scales. As a result, key-points were extracted from multiple scales, based on the maximum/minimum value of DoG:  
\[D(x,y,\sigma)=(G(x,y,k\sigma)-G(x,y,\sigma))*I(x,y)\, \tag{3}\]  
where \(G(x,y,\sigma)=\ \frac{1}{2n\sigma^{2}}e^{-(x^{2}+y^{2})/2\sigma^{2}}\). In order to increase the reliability of pattern detection, the ellipse fitting techniques were additionally applied for circle detection as shown in Figure 3c. The ellipse-fitting algorithm is a common task in machine vision to estimate the centers and radius of the circle. Let denote a set of 2D data points \(P=\ \{\mathbf{x}_{i}\}_{i=1}^{n},\)_where_\(\mathbf{x}_{i}=(x_{i},y_{i})\), a family of curves C(**a**) parameterized by the vector **a**, and the distance metric \(\delta(C(\mathbf{a}),\mathbf{x})\) which measures the distance from a point **x** to the curve \(C(\mathbf{a})\). The problem is to find the value \(\mathbf{a}_{min}\) for which the error function \(\epsilon^{2}(\mathbf{a})=\ \sum_{i=1}^{n}\delta(C(\mathbf{a}),\mathbf{x}_{i})\) attains its global minimum. Hence, the curve best fits the data. In this study, the fitting algorithm based on the \"approximate mean square distance\" metric [19], minimizes the unusual objective function,  
\[\epsilon^{2}(a)=\ \frac{\sum_{i=1}^{n}F(a,\mathbf{x}_{i})^{2}}{\sum_{i=1}^{n}\ \parallel\
abla_{\mathbf{x}}F(a,\mathbf{x}_{i})\parallel^{2}}=\frac{\parallel D\mathbf{a }\parallel^{2}}{\parallel D_{x}\mathbf{a}\parallel^{2}+\parallel D_{y}\mathbf{a} \parallel^{2}}\, \tag{4}\]  
Figure 3: Pattern detection and pose estimation. (**a**) Original image, (**b**) edge detection, (**c**) ellipse fitting, (**d**) pose detection. where the matrices \(D_{x}\) and \(D_{y}\) are the partial derivatives of \(D\) with respect to \(x\) and \(y\). Based on the detection stage, key-points localization is suitably implemented using a pose estimation algorithm. To estimate the pose of the pattern, many approaches have been proposed in the literature. For this work, we applied the RANSAC algorithm to estimate the pose. RANSAC is an iterative method proposed to solve the PnP problem [20]. Since then, it has been applied to many machine vision areas such as PnP, visual SLAM, homographic estimation, fundamental or essential matrix estimation, etc. Let assume we have a set of pairs of matched 2D-3D points (corresponding):\(\big{(}\textbf{x}_{i},\textbf{x}_{i}^{W}\big{)}\), as shown in Figure 3d, four major feature points are used to define the workspace coordinate. The final solution is the transformation matrix \(T_{W}^{C}\) that transforms from the workspace coordinate to camera coordinate.