当前位置:网站首页>Opencv camera calibration (2): fish eye camera calibration
Opencv camera calibration (2): fish eye camera calibration
2022-06-13 01:46:00 【No change of name】
0. explain
Fish eye camera calibration and ordinary camera calibration processes are based on the same ,
The calibration function and parameters will be modified .
1. Code up , Including detailed notes and differences
import cv2
import numpy as np
import glob
def calib(inter_corner_shape, size_per_grid, path):
# Get the number of checkerboard corners
w, h = inter_corner_shape
# The world coordinate dimension is three , Align with corner dimension
# The world coordinate in the calibration of ordinary camera is one dimension less than the corner coordinate , In fish eye camera calibration, less than one dimension will result in an error
cp_int = np.zeros((1, w * h, 3), np.float32)
cp_int[0, :, :2] = np.mgrid[0:w, 0:h].T.reshape(-1, 2).astype(np.float64)
cp_world = cp_int * size_per_grid
# Detect sub-pixel corners
subpix_criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1)
# Calibration method
calibration_flags = cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC + cv2.fisheye.CALIB_CHECK_COND + cv2.fisheye.CALIB_FIX_SKEW
# Image size
img_shape = None
# World coordinates
obj_points = []
# Corner coordinates
img_points = []
# Get photo
images = glob.glob(path + '/*.jpg')
for fname in images:
img = cv2.imread(fname)
# Use the first picture to get the image size
if img_shape == None:
img_shape = img.shape[:2]
else:
assert img_shape == img.shape[:2], "All images must share the same size."
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Corner finding
ret, corners = cv2.findChessboardCorners(gray_img, (w, h),
cv2.CALIB_CB_ADAPTIVE_THRESH + cv2.CALIB_CB_FAST_CHECK + cv2.CALIB_CB_NORMALIZE_IMAGE)
if ret == True:
obj_points.append(cp_world)
# Add sub-pixel corner information
cv2.cornerSubPix(gray_img, corners, (3, 3), (-1, -1), subpix_criteria)
img_points.append(corners)
# Actual number of pictures
imgs = len(obj_points)
# Initializing internal parameters 、 Distortion coefficients and rotation and translation vectors
K = np.zeros((3, 3))
D = np.zeros((4, 1))
rvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(imgs)]
tvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(imgs)]
# Fish eye camera calibration
rms, _, _, _, _ = cv2.fisheye.calibrate(
obj_points, img_points, gray_img.shape[::-1], K, D, rvecs, tvecs, calibration_flags,
(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6))
# It is used to adjust the picture size during picture correction
DIM = img_shape[::-1]
print("Found " + str(imgs) + " valid images for calibration")
print("DIM=" + str(img_shape[::-1]))
print("K=np.array(" + str(K.tolist()) + ")")
print("D=np.array(" + str(D.tolist()) + ")")
return DIM, K, D
# Image de distortion
# DIM Used to resize the image
# Used to adjust the field of view after distortion removal
def superundistort(path, K, D, DIM, scale=0.6, imshow=True):
img = cv2.imread(path)
dim1 = img.shape[:2][::-1] # dim1 is the dimension of input image to un-distort
assert dim1[0] / dim1[1] == DIM[0] / DIM[1], "Image to undistort needs to have same aspect ratio as the ones used in calibration"
if dim1[0] != DIM[0]:
img = cv2.resize(img, DIM, interpolation=cv2.INTER_AREA)
NewK = K.copy()
if scale:
NewK[(0, 1), (0, 1)] = scale * NewK[(0, 1), (0, 1)]
map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), NewK, DIM, cv2.CV_16SC2)
undistorted_img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
if imshow:
cv2.namedWindow("distorted_img", cv2.WINDOW_NORMAL)
cv2.namedWindow("undistorted_img", cv2.WINDOW_NORMAL)
cv2.imshow("distorted_img", img)
cv2.imshow("undistorted_img", undistorted_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
return undistorted_img
if __name__ == '__main__':
inter_corner_shape = (9, 6)
size_per_grid = 0.02
DIM, K, D = calib(inter_corner_shape, size_per_grid, 'data/1')
img = superundistort('data/1/img_1_0074.jpg', K, D, DIM)2. Code link
360sorround/fisheye at main · liuweixue001/360sorround (github.com)
3. Reference link
边栏推荐
- [WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx
- 兴趣相似的受众群体
- Unity JsonUtility 无法序列化List
- Server installation jupyterab and remote login configuration
- Use koa to mock data and set cross domain issues
- Detailed explanation of maxpooling corresponding to conv1d, conv2d and conv3d machines of tensorflow2
- 什么是立体角
- Devaxpress Chinese description -- tdxgallerycontrol object (gallery component)
- Detailed explanation of audience characteristics
- General IP address, account and password of mobile IPv6 optical cat login, and mobile optical cat is in bridging mode
猜你喜欢
![[andoid][step pit]cts 11_ Testbootclasspathandsystemserverclasspath at the beginning of R3_ Analysis of nonduplicateclasses fail](/img/b5/7ea603775dc0448368d209de037a43.png)
[andoid][step pit]cts 11_ Testbootclasspathandsystemserverclasspath at the beginning of R3_ Analysis of nonduplicateclasses fail

5、 Improvement of inventory query function

Devaxpress Chinese description --tdximageslider (picture rotation control)
![[MathType] use MathType to output latex style formula](/img/46/ac2041fbc2eb90474e2e2d7d1b0a40.png)
[MathType] use MathType to output latex style formula

4、 Improvement of warehousing management function

Design of distributed game server

Machine learning basic SVM (support vector machine)

A DPU architecture without CPU: Hyperion

redis

V-inline-date, similar to Ctrip, flying pig, time selection with price
随机推荐
What is the path field—— Competitive advertising
Introduction to common ROS commands
Service creation and operation example of ROS
Phaser3 load
移动IPv6光猫登录的一般ip地址账号与密码,移动光猫变桥接模式
The interviewer only asked me five questions and the interview was over
路径字段是什么? ——竞价广告
[WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx
Restrict cell input type and display format in CXGRID control
【官方文件汇总】国科大学位论文撰写规范
兴趣相似的受众群体
Transaction characteristics and isolation levels
dfs与bfs解决宝岛探险
Delphi implements adding a column of serial number to the CXGRID list
谷歌的智能出价有几种?
QT color extraction
Devaxpress Chinese description --tcximagelist (enhanced image list control)
How many smart bids does Google have?
H5 open the app. If the app is not downloaded, jump to the download page. If the app has been downloaded, wake up the app
Examples of using the chromium base library