How to do it

You need to complete the following steps:

  1. Import the necessary modules:
import cv2import numpy as np
  1. Capture frames from the camera, detect a chessboard pattern on each frame, and accumulate the frames and corners until we have a big enough number of samples:
cap = cv2.VideoCapture(0)pattern_size = (10, 7)samples = []while True:    ret, frame = cap.read()    if not ret:        break        res, corners = cv2.findChessboardCorners(frame, pattern_size)        img_show = np.copy(frame)    cv2.drawChessboardCorners(img_show, pattern_size, corners, res)    cv2.putText(img_show, 'Samples captured: %d' % len(samples), (0,     40),                 cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2)    cv2.imshow('chessboard', img_show)        wait_time = 0 if res else 30 k = cv2.waitKey(wait_time) ...

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.