Hi jakaskerl
Can you please send me the script you are using, because i tried to get/calculate the FOV with OpenCV and I got similar results. The code i used for calibration (aka. get FOV):
def _calibrate(self, framesCount, save = False, path = "None"):
self.debug = True
self.windowSize = (1290, 1080)
self.exit = False
print("Calibrating...")
print(f"Frame count: {framesCount} | Save: {save} | Path: {path}")
if self.debug:
cv2.namedWindow("color", cv2.WINDOW_NORMAL)
cv2.resizeWindow("color", self.windowSize)
frames = []
if path != "None":
if save and not os.path.exists(path):
print(f"Path '{path}' does not exist, creating...")
os.mkdir(path)
elif not os.path.exists(path):
print(f"Path '{path}' does not exist")
return
if path != "None" and not save:
for idx, filename in enumerate(os.listdir(path)):
if idx >= framesCount:
break
if filename.startswith("color") and filename.endswith(".png"):
print(f"File: {filename}")
frame = cv2.imread(os.path.join(path, filename))
# frame = cv2.resize(frame, (4056, 3040))
frames.append(frame)
print()
else:
calibFB = FrameBuffer(size = framesCount)
while not self.exit:
colorBuffer = self.colorQueue.tryGet()
if not colorBuffer:
continue
colorFrame = colorBuffer.getCvFrame()
if calibFB.isReady():
self.exit = True
continue
if self.debug:
cv2.imshow('color', colorFrame)
key = cv2.waitKey(1)
if key == ord(" "):
frameIdx = calibFB.getLength() + 1
print(f"Capturing frame: #{frameIdx}")
if save:
cv2.imwrite(f"{path}/color{frameIdx}.png", colorFrame)
colorFrame = cv2.resize(colorFrame, (4056, 3040))
calibFB.addFrames(colorFrame)
frames = calibFB.getFrames()
patternSize = (6,8)
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
# Creating vector to store vectors of 3D & 3D points for each patternSize image
objpoints = []
imgpoints = []
# Defining the world coordinates for 3D points
objp = np.zeros((1, patternSize[0] * patternSize[1], 3), np.float32)
objp[0,:,:2] = np.mgrid[0:patternSize[0], 0:patternSize[1]].T.reshape(-1, 2)
outFrame = frames[0]
for idx, frame in enumerate(frames):
print(f"\rProcessed: {idx+1}/{len(frames)}", end="")
print("", end="", flush=True)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
found, corners = chessboard(
frame = gray,
patternSize = patternSize
)
if found:
objpoints.append(objp)
# refining pixel coordinates for given 2d points.
corners2 = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
imgpoints.append(corners2)
if self.debug:
outFrame = cv2.drawChessboardCorners(outFrame, patternSize, corners2, found)
cv2.imshow('color', outFrame)
cv2.waitKey(4)
imageShape = gray.shape[::-1]
# https://en.wikipedia.org/wiki/Image_sensor_format (1/2.3")
sensorWdith = 6.17
sensorHeight = 4.55
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, imageShape, None, None)
fovH, fovV, focalLength, principalPoint, aspectRatio = cv2.calibrationMatrixValues(mtx, imageShape, sensorWdith, sensorHeight)
fov_x = np.rad2deg(2 * np.arctan2(imageShape[0], 2 * mtx[0][0]))
fov_y = np.rad2deg(2 * np.arctan2(imageShape[1], 2 * mtx[1][1]))
print()
print(f"Return: {ret}")
print(f"Matrix:\n{mtx}")
print(f"Dist. Coeff.:\n{dist}")
print(f"R vecs:\n{rvecs}")
print(f"T vecs:\n{tvecs}")
print()
print(f"FOV H: {fov_x}")
print(f"FOV V: {fov_y}")
print()
print(f"FOV H: {fovH}")
print(f"FOV V: {fovV}")
print(f"Focal Length: {focalLength}")
print(f"Principal Point: {principalPoint}")
print(f"Aspect Ratio: {aspectRatio}")