# Hybrid Spine Simulator Prototype for X-ray Free Pedicle Screws Fixation Training
## 2 Materials and Methods
### Software Architecture
#### 2.2.2 Camera Calibration  
Cameras are modeled with the well-known pinhole camera model. Figure 4 depicts the camera coordinate frame and image coordinate frame of the pinhole camera model in OpenCV and in Unity. An asymmetric checkerboard is used to estimate cameras' intrinsic parameters offline using the Camera Calibrator application of the MATLAB Computer Vision Toolbox(tm) [31] based on the Zhang method [32]. The calibration process involves the detection of the  
Figure 4: Camera coordinate frame and image coordinate frame of the pinhole camera model in OpenCV and in Unity. Both OpenCV and Unity assume that the camera principal axis is aligned with the positive \(Z\)-axis of the camera coordinate system, but the OpenCV coordinate system is right-handed (the \(Y\)-axis is oriented downward) while the Unity coordinate system is left-handed (the \(Y\)-axis is oriented upward). Moreover, in OpenCV, the origin of the image coordinate system is the center of the upper-left image pixel while in Unity the origin of the image coordinate system is at the image center. This picture also shows the coordinate system of the quad primitive used in Unity. checkerboard from at least 10 different viewpoints, and it is repeated until the reprojection error is less than 0.15 pixels. Once the calibration is completed, the results are saved in a text file (.txt format), including:  
* the horizontal and vertical focal length expressed in pixels \(\langle f_{x},f_{y}\rangle\);
* the coordinates of the principal point in pixels \((c_{x},c_{y})\);
* two radial distortion coefficients (\(K_{1}\) and \(K_{2}\)); and
* the input image size in pixels \((N_{x},N_{y})\). The Camera Calibration module of our software acquires these data and makes them available to the ArUco 3D Tracking and the AR Visualization modules. The Virtual X-Ray Visualization and AR Visualization modules require the pose of vertebral models and instruments to be expressed in the same reference system. With this aim, the Camera Calibration module also computes the extrinsic calibration consisting of the roto-translation matrix between the reference systems of \(\text{Cam}_{\text{Lat}}\) and \(\text{Cam}_{\text{Top}}\). This calibration is performed by acquiring the pose of a calibration cube with two ArUco diamond markers (Diamond\({}_{\text{Top}}\) and Diamond\({}_{\text{Lat}}\)) placed, respectively, on two adjacent faces (Figure 2b). ArUco diamond markers are chessboards composed of 3 \(\times\) 3 squares with four ArUco fiducial markers, and they can be used for accurate pose computation in all situations when the marker size is not an issue for the application. Each diamond marker is represented by an identifier and four corners: these latter corners correspond to the four chessboard corners and they are derived from the previous detection of the four ArUco markers. The coordinate system of the diamond pose is in the center of the diamond marker with the \(Z\)-axis pointing outward, as in a simple ArUco marker [33]. For this application, diamonds markers are printed in a size of 9 \(\times\) 9 cm (the four ArUco markers of a diamond marker measure 2 \(\times\) 2 cm each). The calibration process includes the following steps:  
1. The calibration cube is positioned inside the field of view (FOV) of both cameras, and \(\text{Cam}_{\text{Lat}}\) and \(\text{Cam}_{\text{Top}}\) simultaneously acquire the diamond markers. 2. ArUco libraries are used to estimate the pose of each diamond marker in the reference system of the corresponding tracking camera. We refer to the position vector from the \(\text{Cam}_{\text{Top}}\) reference system to the origin of the \(\text{Diamond}_{\text{Top}}\) reference system as \(\overset{\rightarrow}{O}_{\text{Top}}\), while we use \(\overset{\rightarrow}{O}_{\text{Lat}}\) to denote the position vector from the origin of the \(\text{Cam}_{\text{Lat}}\) reference system to the origin of the reference system of the \(\text{Diamond}_{\text{Lat}}\) (see Figure 2b). 3.