Initial setup
Three steps have to be done to initialize the system: calibration of the camera, transformation of the perspective, and extraction of the table and background.
In the calibration phase, the system finds the corners of the playing field to initialize the locations of the pots, this is necessary for potting detection. Also, the location of the playing field is necessary to perform camera undistortion.
The system should allow for mounting the camera on any place above the table. This brings difficulties when extracting the table area from the image, because this makes regular cropping fall short. Therefore, transforming the camera perspective and camera undistortion is done to correct the camera view. This relaxes the requirement for mounting the system exactly above the center of the table, allowing camera perspectives at a slight angle.
The last step in the initial setup is background extraction. This is done by blurring the area in the first frame where the balls are. This area is spanned by the green and yellow balls as the vertical boundaries, and the D-area and the black ball spot as the horizontal boundaries. The greyscale background image of the scene generated here is used later for ball detection.

