# 相机标定
## 1、保存相机采集的图像
```
import cv2
cap = cv2.VideoCapture(0)
index = 0
while (1):
ret,frame = cap.read()
cv2.imshow("capture",frame)
# ckey = cv2.waitKey(1)&0xFF
ckey = cv2.waitKey(1)
print(ckey)
if ret and (ckey == ord('s')):
# if ret:
# if ret and 0xFF == ord('q'):
# print(ckey)
index = index + 1
print(index)
cv2.imwrite('C:/Users/kangs/Desktop/calibration/' + str(index) + '.jpg',frame)
if index > 20:
break
cap.release()
cv2.destroyAllWindows()
```
## 2、相机标定
```
# coding: utf-8
# Camera Calibration with OpenCV
# ### Run the code in the cell below to extract object points and image points for camera calibration.
import numpy as np
import cv2
import glob
import matplotlib
from scipy import io
matplotlib.use('qt5agg')
import matplotlib.pyplot as plt
np.set_printoptions(suppress=True)
#