Detecting chessboard and circle grid patterns
In this recipe, you will learn how to detect chessboard and circle grid patterns. These patterns are very useful in computer vision, and are often used for estimating camera parameters.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV 3.x Python API package and the matplotlib
package.
How to do it...
- Import the modules:
import cv2 import matplotlib.pyplot as plt
- Load the test image with a chessboard:
image_chess = cv2.imread('../data/chessboard.png')
- Detect the chessboard pattern:
found, corners = cv2.findChessboardCorners(image_chess, (6, 9)) assert found == True, "can't find chessboard pattern"
- Draw the detected pattern:
dbg_image_chess = image_chess.copy() cv2.drawChessboardCorners(dbg_image_chess, (6, 9), corners, found);
- Load the test image with a circle grid pattern:
image_circles = cv2.imread('../data/circlesgrid.png')
- Detect the circle grid pattern:
found, corners = cv2.findCirclesGrid(image_circles, (6, 6), cv2.CALIB_CB_SYMMETRIC_GRID...