This commit is contained in:
ros 2023-02-28 10:29:14 +01:00
parent 749b6e9182
commit 1645f1969c
4 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
import cv2
retval, corners = cv2.findChessboardCorners(image,patternSize, flags)
import cv2
import numpy as np
# Define the size of the chessboard
chessboard_size = (22, 16)
# Define the object points of the chessboard
object_points = np.zeros((np.prod(chessboard_size), 3), dtype=np.float32)
object_points[:, :2] = np.mgrid[0:chessboard_size[0], 0:chessboard_size[1]].T.reshape(-1, 2)
# Create arrays to store the object points and image points from all the images
object_points_array = []
image_points_array = []
# Load the images
images = []
images.append(cv2.imread("image1.jpg"))
images.append(cv2.imread("image2.jpg"))
# Add more images as needed
# Loop through each image and find the chessboard corners
for image in images:
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Find the chessboard corners
found, corners = cv2.findChessboardCorners(gray, chessboard_size, None)
# If the corners are found, add the object points and image points to the arrays
if found:
object_points_array.append(object_points)
image_points_array.append(corners)
# Calibrate the camera using the object points and image points
ret, camera_matrix, distortion_coefficients, rotation_vectors, translation_vectors = cv2.calibrateCamera(
object_points_array, image_points_array, gray.shape[::-1], None, None)
# Print the camera matrix and distortion coefficients
print("Camera matrix:")
print(camera_matrix)
print("Distortion coefficients:")
print(distortion_coefficients)

View File

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 164 KiB

BIN
left.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

BIN
right.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB