How to do it...

  1. Import the modules:
import cv2import matplotlib.pyplot as plt
  1. Load the test image with a chessboard:
image_chess = cv2.imread('../data/chessboard.png')
  1. Detect the chessboard pattern:
found, corners = cv2.findChessboardCorners(image_chess, (6, 9))assert found == True, "can't find chessboard pattern"
  1. Draw the detected pattern:
dbg_image_chess = image_chess.copy()cv2.drawChessboardCorners(dbg_image_chess, (6, 9), corners, found);
  1. Load the test image with a circle grid pattern:
image_circles = cv2.imread('../data/circlesgrid.png')
  1. Detect the circle grid pattern:
found, corners = cv2.findCirclesGrid(image_circles, (6, 6), cv2.CALIB_CB_SYMMETRIC_GRID)assert found == True, "can't find circles grid pattern"
  1. Draw the detected ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.