import cv2 import numpy as np chessboard_size = (9,6) # 棋盘格行列数 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-04 13:02:57 浏览: 74
可以使用NumPy的set_printoptions()函数来设置打印选项,将结果打印成正常数字形式。可以将代码修改如下:
```python
import cv2
import numpy as np
chessboard_size = (9, 6) # 棋盘格行列数
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("相机内部参数:")
np.set_printoptions(precision=4, suppress=True)
print(mtx)
print("畸变系数:")
np.set_printoptions(precision=4, suppress=True)
print(dist)
# 打印外部参数
print("旋转向量:")
np.set_printoptions(precision=4, suppress=True)
print(rvecs)
print("平移向量:")
np.set_printoptions(precision=4, suppress=True)
print(tvecs)
```
这里使用了np.set_printoptions()函数来设置打印选项,将精度设置为4位小数,并将科学计数法关闭。这样打印出来的结果就会是正常数字形式。
阅读全文