Predicting pool ball trajectories Faiz Punjani1, Ishan Shah2, Mehul Gada3, Ruhina Karani4 1 UG Student, Computer Department, D.J. Sanghvi College of Engineering, Mumbai, India UG Student, Computer Department, D.J. Sanghvi College of Engineering, Mumbai, India 3 UG Student, Computer Department, D.J. Sanghvi College of Engineering, Mumbai, India. 4 Assistant Professor, Computer Department, D.J. Sanghvi College of Engineering, Mumbai, India. 2 1faizpunjani@gmail.com 2ishanvshah@outlook.com 3mehulgada08@gmail.com 4ruhina.karani@djsce.ac.in Abstract— Pool ball trajectory predictor is designed to assist unskilled or amateur pool, or snooker or billiards players in predicting trajectories. This augmented reality tool utilizes a camera , placed above the table , which acquires and processes the game at the interleaved time interval after playing each round. The system recognizes the pool table border, the white ball’s position and the cue direction in order to compute the predictable trajectory of the cue ball and the ball directly in its trajectory. The result is then forwarded to a projector, placed above the table. The projector then projects onto the snooker playable field. Various edge detection algorithms and motion detection techniques are reviewed in the paper. An entire flow of the process is explained with the techniques used at each step. Keywords— edge detection, motion detection, pool game I. INTRODUCTION A pool game is a very challenging endeavor for an amateur player. An ardent effort is required to excel in the game of pool. The game has basic a classic mechanism. A conceptual tool is introduced to assist amateur pool players. The pool trajectory predictor will predict the trajectories just before a player hits the white ball with the cue at a particular angle. The computed trajectory will be displayed on the table by a projector. In this paper, the complete process of this project is explained. Edge detection is required to extract the pool table boundaries, which are to be used for calculating the reflection of the trajectories [1].Various edge detection algorithms are introduced in brief. The on the fly computation is made only after motion is not detected. A detailed comparison for motion detection algorithms is made. The various computations include trajectory detection, ball interactions and projection of these computed trajectories [2]. II. LITERATURE REVIEW A. Edge Detection For finding the boundaries of objects within images edge detection techniques are used. These techniques identify points at which the image brightness changes acutely or, more formally, has discontinuities. The points at which image brightness changes acutely are typically organized into a set of curved line segments termed edges. Significant local changes of intensity in an image are characterized by edges. Edges typically occur on the boundary between two differentregions in an image. The goal of edge detection is to show a line drawing of a scene from an image of that scene. Edges of an image can be used to extract important attribute (like corners, lines, curves). These attributes are used by higher-level computer vision algorithms (e.g., recognition) [1]. The four steps of edge detection (1) Smoothing: Without ruining the true edges, suppress as much noise as possible. (2) Enhancement: The quality of the edges in the image are enhanced by applying a filter. (3) Detection: determine which edge pixels should be retained and which should be discarded as noise (usually, thresholding provides the criterion used for detection). (4) Localization: The exact location of an edge is determined (sub-pixel resolution might be required for some applications, that is, estimate the location of an edge to better than the spacing between pixels). Edge thinning and linking are usually required in this step There are many ways to perform edge detection. However, the most may be grouped into two categories, gradient and Laplacian [3]. (1) The gradient method detects the edges by looking for the maximum and minimum in the first derivative of the image. (2) The Laplacian method searches for zero crossings in the second derivative of the image to find edges. A gradient based edge detector method includes Roberts, B. Motion Detection technique Prewitt and Sobel operator [5]. There are three techniques that can be used for motion 1. Robert Edge Detection: detection. These three are explained as follows: In Robert Edge detection, a gradient of the image is obtained. i. Basic Blank Background technique This image is approximated through discrete differentiation. A 2 X 2 matrix called Robert mask is obtained. The entire image First, set the first frame as the background frame. Second, is convolved using horizontal and vertical Robert masks to compare the current frame with the background frame. Third, detect edges in x and y direction respectively. move the background frame to the current frame on the specified amount. Then, move the background frame slightly in gx = (z4 - z1) for horizontal derivative approximate the direction of the present frame - changing colors of pixels in gy = (z3 - z2) for vertical derivative approximate the background frame by one level per frame. Detect regions where the two frames differ, using difference or threshold 2. Prewitt Edge Detection: filters. Then, image is displayed with white pixels on place This algorithm uses a discrete differentiation operator called where the difference is present on the specified threshold value. Prewitt mask. Two 3 X 3 masks are used by this operator which Count the pixels and if the number of pixels are greater than a calculate values for horizontal and vertical directions. predefined value then the motion is detected [4]. gx = (z3 + z6 + z9) - (z1 + z4 + z7) for horizontal derivative approximate ii. Previous – Current comparison technique gy = (z7 + z8 + z9) - (z1 + z2 + z3) for vertical derivative approximate First, detect regions where the two frames differ, using difference or threshold filters. Image is displayed with white 3. Canny Edge Detection: pixels on place where the difference is present on the specified In Canny algorithm, the image is made smooth using two- threshold value. Then count the pixels and if the number of dimensional Gaussian function. It uses a mask of 2 X 2 matrix pixes are greater than a predefined value then the motion is to calculate magnitude and direction of image gradient detected [4]. Ex[i,j]=(I[i+1,j]-I[i,j]+I[i+1,j+1]-I[i,j+1])/2 Ey[i,j]=(I[i,j+1]-I[i,j]+I[i+1,j+1]-I[i+1,j])/2 iii. Using Pixellate filter technique Image gradient magnitude is calculated as: ||M(i, j)|| = √E𝑥 [i, j]2 + E𝑦 [i, j]2 To position the edges, perform non maximum suppression which makes the edges one-pixel width. Compare gradient magnitude of the pixels, if they’re above high-threshold, they’re marked as edge-points. Points below low-average are marked non-edge points and rest are marked as candidate-edge points. If candidate edge points meet with edge points, they’re connected and made edge-points as well [8]. First, set the first frame as the background frame. Second, apply Pixellate filter to both the frames. Third, compare the current frame with the background frame. Then, move the background frame towards the current frame. Detect regions where the two frames differ, using difference or threshold filters. Then, image with white pixels on place where the difference is present on the specified threshold value. Then, count the pixels and if the number of pixels are greater than a predefined value then the motion is detected [7]. 4. Hough Transform: In edge detection technique the edge is rarely characterized by the resulting pixels completely because of noise, breaks in the edge from uneven illumination and other effects that introduce false intensity discontinuities. Thus edge detection technique algorithms are typically followed by linking procedures to assemble edge pixels into useful edges. Hough transforms are one of the methods used for this type of problem. Steps for this: 1. Peak detection-Peak detection is the first step for line detection and linking. The first step is to find the location of all nonzero pixels for each peak in the image that contribute to that peak. 2. Line detection and linking-Once a set of peaks has been identified in the Hough transform, it is to be determined if there is association of line segments with those peaks, as well as their start and end [6] [9]. A comparison is made as follows in the Table 2.1 Table 2.1: Motion Detection Techniques Basic Blank Background technique Comparison between the current frame and the first frame with empty background. Advantages: Simple to implement Useful in video compression when you need to estimate changes and to write only the changes, not the whole frame. Previous – current comparison technique Comparison between the current frame and the previous frame. Using Pixellate filter technique Advantages It's possible to compare the current frame not with the previous one but with the first frame in the video sequence. So, if there were no objects in the initial frame, comparison of the current frame with the first one will give us the whole moving object independently of its motion speed. Advantages: Performance optimization possible Disadvantages: Since most cameras produce a noisy image, motion is detected in such places, where there is no motion at all. To remove random noisy pixels, an Erosion filter can be used. If the object is moving smoothly, small changes are received from frame to frame. So, it's impossible to get the whole moving object. Things become worse, when the object is moving so slowly, when the algorithms will not give any result at all. Disadvantages: If there’s an object in the first frame and then it’s gone, motion will be detected. To avoid this, initial frame should be renewed. Disadvantages: Boundaries are not accurate. Comparison between pixelated current frame and the background frame III. PROPOSED SYSTEM This augmented reality tool comprises of a camera and a projector. The camera provides an input and the projector outputs the predicted trajectories onto the surface of the pool table. The proposed system goes through a series of steps before processing each image. After processing the image, the computed trajectories are projected. A detailed algorithm of the system is as follows. 1. Capture the image of the empty background (pool table without balls). 2. Reduce noise from the image. 3. Apply edge detection algorithm. 4. Apply movement detection algorithm to check if any of the balls are in movement. 5. Detect the cue ball using image transformations by selecting the ball with the brightest area. 6. Project a circle around the white ball. 7. Detect the cue by comparing with a reference frame. 8. Detection of balls: Compare the current average frame with the initial average frame. Each blob detected is a ball, if and only if the following parameters are met: a) Ratio between the blob’s height and width is approximately one. b) Blob’s area and circle’s area should be equal. c) Ratio between circle (πr2) and square’s area (2r)2 be equal to π/4. 9. Represent Cue stick by calculating line equation using two points in the queue. 10. Calculate point of intersection of the cue and the contour 𝑃𝑥,± = (√−𝑏 2 −2𝑏(𝑚𝑥0 −𝑦0 )+𝑚2 (𝑟 2 −𝑥02 )+2𝑚𝑥0 𝑦0 −𝑦02 +𝑟 2 )−𝑏𝑚2 𝑦0 +𝑥0 ± 𝑃𝑦,± = 𝑚2 +1 (√−𝑏 2 −2𝑏(𝑚𝑥0 −𝑦0 )+𝑚2 (𝑟 2 −𝑥02 )+2𝑚𝑥0 𝑦0 −𝑦02 +𝑟 2 )𝑚+𝑏+𝑚(𝑚𝑦0 +𝑥0 ) ± 𝑚2 +1 11. Calculate Ball collisions using vectors at tangent points of that ball. 12. Convert the ball’s points and calculated trajectory to the table co-ordinates using transformation matrix and project them on the table. IV. CONCLUSION AND FUTURE SCOPE In this paper, a system is presented that predicts and displays trajectories of a cue ball on a pool table. A projector is mounted and a camera on top of the pool table. The camera is used to detect the objects and motion of the balls while the projector displays the trajectories on the table itself. This system involves two stages, (a) the setup which is done when the system is mounted. In this all the necessary parameters are adjusted. The second stage is (b) the running stage. Here no parameters are changed and the system works by using the table as an interface. The projector should be calibrated using the projector menu to make sure that it covers the entire playable area. The projection should not affect the detection of balls and motion. No trajectories are projected while the balls are in motion or when a move is made, when the movement stops the trajectories are projected again. The enhancement of the ball detection algorithm can be done so as to enable it to detect balls close to each other. The cue detection algorithm can be enhanced so as to minimize the angular error of the system while playing the game. A further future goal is to enable the player to save the setup of his move so that he can practice it in future. V. REFERENCES [1] Jain, Ramesh, Rangachar Kasturi, and Brian G. Schunck. Machine vision. Vol. 5. New York: McGraw-Hill, 1995. [2] Tabachnikov, Serge. Geometry and billiards. Vol. 30. American Mathematical Soc., 2005. [3] Martin, Jerome, and James L. Crowley. "Comparison of correlation techniques."International Conference on Intelligent Autonmous Systems, Karlsruhe (Germany). 1995. [4] Piccardi, Massimo. "Background subtraction techniques: a review." Systems, man and cybernetics, 2004 IEEE international conference on. Vol. 4. IEEE, 2004. [5] Chaple, Girish N., R. D. Daruwala, and Manoj S. Gofane. "Comparisions of Robert, Prewitt, Sobel operator based edge detection methods for real time uses on FPGA." [6] Singh, Saurabh, and Ashutosh Datar. "EDGE Detection Techniques Using Hough Transform." [7] Yong, Ching Yee, Rubita Sudirman, and Kim Mey Chew. "Motion Detection and Analysis with Four Different Detectors." Computational Intelligence, Modelling and Simulation (CIMSiM), 2011 Third International Conference on. IEEE, 2011. [8] Canny, John. "A computational approach to edge detection." Pattern Analysis and Machine Intelligence, IEEE Transactions on 6 (1986): 679-698. [9] Duda, Richard O., and Peter E. Hart. "Use of the Hough transformation to detect lines and curves in pictures." Communications of the ACM 15.1 (1972): 11-15. [10] Russ, John C., and Roger P. Woods. "The image processing handbook." Journal of Computer Assisted Tomography 19.6 (1995): 979-981.