Original drawing

After correction

I created a new one jz Put the pictures that need to be taken by the camera in the folder , as follows : common 12 Zhang

# coding:utf-8 import cv2 import numpy as np import glob # Find the corner of the chessboard # threshold criteria
= (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001) # Checkerboard template specification
from 0 Start calculation w = 9 h = 6 # Checkerboard grid points in the world coordinate system , for example (0,0,0), (1,0,0), (2,0,0)
....(8,5,0), Remove Z coordinate , Write it as a two-dimensional matrix objp = np.zeros((w * h, 3), np.float32) objp[:, :2] =
np.mgrid[0:w, 0:h].T.reshape(-1, 2) # Save the world coordinate and image coordinate pair of checkerboard corner points objpoints = [] #
3D points in the world coordinate system imgpoints = [] # Two dimensional points in the image plane # Match specific files in the read folder images = glob.glob(
'jz/*.jpg') for fname in images: img = cv2.imread(fname) gray = cv2.cvtColor(img
, cv2.COLOR_BGR2GRAY) # Find the corner of the chessboard ret, corners = cv2.findChessboardCorners(gray, (
w, h), None) # Show corners on image cv2.drawChessboardCorners(img, (w, h), corners, ret)
cv2.imshow('findCorners', img) cv2.waitKey(500) cv2.destroyAllWindows() #
If enough points are found , Store it if ret == True: cv2.cornerSubPix(gray, corners, (11, 11), (-1, -
1), criteria) objpoints.append(objp) imgpoints.append(corners) # calibration ret, mtx,
dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],
None, None) # When applying , Write down the following two print(mtx) print(dist) # De distortion img2 = cv2.imread(
'77.jpg') h, w = img2.shape[:2] newcameramtx, roi = cv2.
getOptimalNewCameraMatrix(mtx, dist, (w, h), 0, (w, h)) # Free scale parameter dst = cv2.
undistort(img2, mtx, dist, None, newcameramtx) # According to the front ROI Region crop picture # x,y,w,h = roi
# dst = dst[y:y+h, x:x+w] cv2.imwrite('1.jpg', dst) cv2.imshow('findCorners',
dst) cv2.waitKey(0) cv2.destroyAllWindows()

Technology