拍摄照片
采用张正友标定法,首先,需要打印标定用的棋盘格。棋盘格下载地址
接着,运行程序,调用相机拍摄照片。拍照的程序如下
import cv2
def gstreamer_pipeline(
capture_width=1280,
capture_height=720,
display_width=1280,
display_height=720,
framerate=60,
flip_method=0,
):
return (
"nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
"video/x-raw, format=(string)BGR ! appsink"
% (
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
def show_camera():
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
i = 0
while cap.isOpened():
flag, img = cap.read()
cv2.imshow("CSI Camera", img)
kk = cv2.waitKey(1)
# do other things
if kk == ord('q'): # 按下 q 键,退出
break
elif kk == ord('p'):
cv2.imwrite('./picture/%02d.png'%i,img)
print(i)
i += 1
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
show_camera()
在相机窗口下按键盘上的p进行拍照,拍照后,保存到本目录下的./picture/目录,可以自行修改,按q退出程序。
拍摄不同角度、不同距离的棋盘格照片,20张左右。
使用MATLAB进行标定
打开MATLAB,打开Camera Calibrator
点击Add Images
等待一段时间,MATLAB会自动检测角点
点击Calibrate
点击Export Camera Parameters,在控制台中的工作区中可以看到相应的变量已经导入
查看相机参数,依次是内参矩阵、径向畸变、切向畸变