diff --git a/9/2.py b/9/2.py new file mode 100644 index 0000000..b63098c --- /dev/null +++ b/9/2.py @@ -0,0 +1,76 @@ +import glob +import os + +import cv2 +import numpy as np + +# Defining the dimensions of checkerboard +CHECKERBOARD = (6, 9) +criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001) + +# Creating vector to store vectors of 3D points for each checkerboard image +objpoints = [] +# Creating vector to store vectors of 2D points for each checkerboard image +imgpoints = [] + + +# Defining the world coordinates for 3D points +objp = np.zeros((CHECKERBOARD[0] * CHECKERBOARD[1], 3), np.float32) +objp[:, :2] = np.mgrid[0 : CHECKERBOARD[0], 0 : CHECKERBOARD[1]].T.reshape(-1, 2) +prev_img_shape = None + +# Extracting path of individual image stored in a given directory +images = glob.glob("9/images/*.jpg") +for fname in images: + img = cv2.imread(fname) + img = cv2.resize(img, (960, 720)) + gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + # Find the chess board corners + ret, corners = cv2.findChessboardCorners( + gray, + CHECKERBOARD, + cv2.CALIB_CB_ADAPTIVE_THRESH + + cv2.CALIB_CB_FAST_CHECK + + cv2.CALIB_CB_NORMALIZE_IMAGE, + ) + + """ + If desired number of corner are detected, + we refine the pixel coordinates and display + them on the images of checker board + """ + + if ret == True: + objpoints.append(objp) + # Refining pixel coordinates for given 2d points. + corners2 = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria) + imgpoints.append(corners2) + + # Draw and display the corners + img = cv2.drawChessboardCorners(img, CHECKERBOARD, corners2, ret) + + cv2.imshow("img", img) + cv2.waitKey(0) + +cv2.destroyAllWindows() + +h, w = img.shape[:2] + +""" +Performing camera calibration by +passing the value of known 3D points (objpoints) +and corresponding pixel coordinates of the +detected corners (imgpoints) +""" +ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera( + objpoints, imgpoints, gray.shape[::-1], None, None +) + +print("Camera matrix : \n") +print(mtx) +print("dist : \n") +print(dist) +print("rvecs : \n") +print(rvecs) +print("tvecs : \n") +print(tvecs) diff --git a/9/images/1730874232856.jpg b/9/images/1730874232856.jpg new file mode 100644 index 0000000..4c83e88 Binary files /dev/null and b/9/images/1730874232856.jpg differ diff --git a/9/images/1730874232877.jpg b/9/images/1730874232877.jpg new file mode 100644 index 0000000..a51fd15 Binary files /dev/null and b/9/images/1730874232877.jpg differ diff --git a/9/images/1730874232891.jpg b/9/images/1730874232891.jpg new file mode 100644 index 0000000..de49d4a Binary files /dev/null and b/9/images/1730874232891.jpg differ diff --git a/9/images/1730874232904.jpg b/9/images/1730874232904.jpg new file mode 100644 index 0000000..70e5e83 Binary files /dev/null and b/9/images/1730874232904.jpg differ diff --git a/9/images/1730874232914.jpg b/9/images/1730874232914.jpg new file mode 100644 index 0000000..6cdec79 Binary files /dev/null and b/9/images/1730874232914.jpg differ diff --git a/9/images/1730874232930.jpg b/9/images/1730874232930.jpg new file mode 100644 index 0000000..267309b Binary files /dev/null and b/9/images/1730874232930.jpg differ diff --git a/9/images/1730874232936.jpg b/9/images/1730874232936.jpg new file mode 100644 index 0000000..b2f8cf1 Binary files /dev/null and b/9/images/1730874232936.jpg differ diff --git a/9/images/1730874232942.jpg b/9/images/1730874232942.jpg new file mode 100644 index 0000000..dc1ffae Binary files /dev/null and b/9/images/1730874232942.jpg differ diff --git a/9/images/1730874836317.jpg b/9/images/1730874836317.jpg new file mode 100644 index 0000000..f03b1b3 Binary files /dev/null and b/9/images/1730874836317.jpg differ diff --git a/9/images/1730875402019.jpg b/9/images/1730875402019.jpg new file mode 100644 index 0000000..30a530a Binary files /dev/null and b/9/images/1730875402019.jpg differ