Add calibration data
This commit is contained in:
54
data/callibration/callibriate.py
Executable file
54
data/callibration/callibriate.py
Executable file
@@ -0,0 +1,54 @@
|
|||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
import glob
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create callibration .npz from checkerboard images.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
# Parameter
|
||||||
|
CHECKERBOARD = (9, 6) # innere Ecken
|
||||||
|
square_size = 25.0 / 1000.0 # 25 mm → Meter
|
||||||
|
|
||||||
|
# Objektpunkte vorbereiten
|
||||||
|
objp = np.zeros((CHECKERBOARD[0]*CHECKERBOARD[1], 3), np.float32)
|
||||||
|
objp[:, :2] = np.mgrid[0:CHECKERBOARD[0], 0:CHECKERBOARD[1]].T.reshape(-1, 2)
|
||||||
|
objp *= square_size
|
||||||
|
|
||||||
|
objpoints = []
|
||||||
|
imgpoints = []
|
||||||
|
|
||||||
|
images = glob.glob("calib_images/*.jpg")
|
||||||
|
|
||||||
|
for fname in images:
|
||||||
|
img = cv2.imread(fname)
|
||||||
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
|
ret, corners = cv2.findChessboardCorners(
|
||||||
|
gray, CHECKERBOARD,
|
||||||
|
flags=cv2.CALIB_CB_ADAPTIVE_THRESH +
|
||||||
|
cv2.CALIB_CB_NORMALIZE_IMAGE +
|
||||||
|
cv2.CALIB_CB_FAST_CHECK
|
||||||
|
)
|
||||||
|
|
||||||
|
if ret:
|
||||||
|
corners2 = cv2.cornerSubPix(
|
||||||
|
gray, corners, (11,11), (-1,-1),
|
||||||
|
(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6)
|
||||||
|
)
|
||||||
|
objpoints.append(objp)
|
||||||
|
imgpoints.append(corners2)
|
||||||
|
|
||||||
|
# Kalibrieren
|
||||||
|
ret, K, D, rvecs, tvecs = cv2.calibrateCamera(
|
||||||
|
objpoints, imgpoints, gray.shape[::-1], None, None
|
||||||
|
)
|
||||||
|
|
||||||
|
print("RMS reprojection error:", ret)
|
||||||
|
|
||||||
|
# Speichern
|
||||||
|
np.savez("calibration_cam0.npz",
|
||||||
|
camera_matrix=K,
|
||||||
|
dist_coeffs=D)
|
||||||
Reference in New Issue
Block a user