import cv2 import numpy as np chessboard_size = (7,10) # 棋盘格行列数 objp = np.zeros((np.prod(chessboard_size), 3), np.float32) # 内部点的坐标 objp[:, :2] = np.mgrid[0:chessboard_size[0], 0:chessboard_size[1]].T.reshape(-1, 2) img = cv2.imread('C:/yingxiang/biaoding.png') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, corners = cv2.findChessboardCorners(gray, chessboard_size, None) if ret == True: cv2.drawChessboardCorners(img, chessboard_size, corners, ret) ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera([objp], [corners], gray.shape[::-1], None, None) # 打印相机内部参数和畸变系数 print("相机内部参数:") print(mtx) print("畸变系数:") print(dist) # 打印外部参数 print("旋转向量:") print(rvecs) print("平移向量:") print(tvecs)这段代码怎么改可以打印出内部参数和畸变参数 以及旋转向量和平移向量
时间: 2024-02-26 15:57:54 浏览: 60
这段代码已经可以打印出相机内部参数和畸变系数了,只需要加上打印旋转向量和平移向量的代码即可。修改后的代码如下所示:
```python
import cv2
import numpy as np
chessboard_size = (7,10) # 棋盘格行列数
objp = np.zeros((np.prod(chessboard_size), 3), np.float32) # 内部点的坐标
objp[:, :2] = np.mgrid[0:chessboard_size[0], 0:chessboard_size[1]].T.reshape(-1, 2)
img = cv2.imread('C:/yingxiang/biaoding.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, corners = cv2.findChessboardCorners(gray, chessboard_size, None)
if ret == True:
cv2.drawChessboardCorners(img, chessboard_size, corners, ret)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera([objp], [corners], gray.shape[::-1], None, None)
# 打印相机内部参数和畸变系数
print("相机内部参数:")
print(mtx)
print("畸变系数:")
print(dist)
# 打印外部参数
print("旋转向量:")
print(rvecs)
print("平移向量:")
print(tvecs)
```
注意,需要确保棋盘格被成功检测到,才能正确计算相机的内部参数、畸变系数、旋转向量和平移向量。
阅读全文