1

I have an image of a pool table with slight perspective distortion:

Pool Table Image

I am trying to un-warp the image (such that the corners of the pool table correspond to the corners of my output image) and then detect the pool balls on the output image. To unwarp the table, I intend to use cv2.PerspectiveTransform() to obtain the transformation matrix that maps the corners of the pool table to the corners of my output image. However, I do not have the locations of the corners of my table; I want to find the corners programmatically.

So far, I have applied a mask (that filters out everything but the pool table). After applying the mask, I've applied a Canny edge detector to find the edges of the pool table only:

Edge of Pool Table

My idea was to use the Hough line transform algorithm to find the lines corresponding to the edges of the pool table (to find the corners of the pool table programmatically), but the Hough line transform algorithm seems to have a hard time detecting the edges well. How can I find the corners of the pool table from here?

EDIT

Is there any way I can just extract the sharp corners of the outline (the eight points corresponding to where the straight edges turn into the pockets)?

  • 2
    You can try to find contours (like ```cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)```) in yout masked image and then using ```cv2.approxPolyDP``` you can conlrol edges of you contour. So then you will get the corners of the table – crackanddie May 04 '22 at 19:53
  • I've just tried such an approach. Unfortunately, the `cv2.approxPolyDP` method does not extrapolate corners well, so the corners are on the sharp corners of the pool pockets (as opposed to empty space, where the true corners are). –  May 06 '22 at 16:17
  • Have you tried Harris corner detection? – Jeru Luke May 07 '22 at 10:44
  • Or you could find the minimum bounding rectangle enclosing the mask image. The corners of the rectangle could well approximate the corners of the pool table – Jeru Luke May 07 '22 at 10:47
  • @JeruLuke Tried Shi-Tomasi corner detection, but it's identifying some of edges of the balls as corners. It's also not consistently identifying the twelve corners of the pool pockets. I've tried using a minimum bounding rectangle but the corners of the minimum bounding rectangle doesn't really approximate the corners of the actual pool table well (I need the corners to be pretty darn accurate). –  May 08 '22 at 23:39

0 Answers0