10. Finding Corners
Finding Corners
In this exercise, you'll use the OpenCV functions
findChessboardCorners()
and
drawChessboardCorners()
to automatically find and draw corners in an image of a chessboard pattern.
To learn more about both of those functions, you can have a look at the OpenCV documentation here: cv2.findChessboardCorners() and cv2.drawChessboardCorners() .
Applying these two functions to a sample image, you'll get a result like this:
In the following exercise, your job is simple. Count the number of corners in any given row and enter that value in
nx
. Similarly, count the number of corners in a given column and store that in
ny
. Keep in mind that "corners" are only points where two black and two white squares intersect, in other words, only count inside corners, not outside corners.
If you'd like to test the above image (before drawing the corners) on your own machine, download it here .
Finding Corners
Start Quiz:
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# prepare object points
nx = 0#TODO: enter the number of inside corners in x
ny = 0#TODO: enter the number of inside corners in y
# Make a list of calibration images
fname = 'calibration_test.png'
img = cv2.imread(fname)
# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Find the chessboard corners
ret, corners = cv2.findChessboardCorners(gray, (nx, ny), None)
# If found, draw corners
if ret == True:
# Draw and display the corners
cv2.drawChessboardCorners(img, (nx, ny), corners, ret)
plt.imshow(img)