Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Created December 14, 2017 15:51
Show Gist options
  • Save hackintoshrao/d32b9c43de7b2149facc2263920108d2 to your computer and use it in GitHub Desktop.
Save hackintoshrao/d32b9c43de7b2149facc2263920108d2 to your computer and use it in GitHub Desktop.
Find and draw chess board corners for camera caliberation using Opencv
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import glob
# prepare object points
#Enter the number of inside corners in x
nx = 9
#Enter the number of inside corners in y
ny = 6
# Make a list of calibration images
chess_images = glob.glob('./camera_cal/cal*.jpg')
# Select any index to grab an image from the list
for i in range(len(chess_images)):
# Read in the image
chess_board_image = mpimg.imread(chess_images[i])
# Convert to grayscale
gray = cv2.cvtColor(chess_board_image, cv2.COLOR_RGB2GRAY)
# Find the chessboard corners
ret, corners = cv2.findChessboardCorners(chess_board_image, (nx, ny), None)
# If found, draw corners
if ret == True:
# Draw and display the corners
cv2.drawChessboardCorners(chess_board_image, (nx, ny), corners, ret)
result_name = 'board'+str(i)+'.jpg'
cv2.imwrite(result_name, chess_board_image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment