惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
B
Blog
V
V2EX
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
博客园 - 聂微东
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
J
Java Code Geeks
H
Help Net Security
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
D
Docker
L
LangChain Blog
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
WordPress大学
WordPress大学
V
Visual Studio Blog

又见苍岚

COLMAP PatchMatch Stereo 算法详解 事件驱动的状态机框架:从理论到工程实践 Git 在国内网络环境下无法 Push 的排查与修复 —— 配置 Clash 代理 分段五次多项式插值原理详解 路径插值方法深度对比研究 Claude Code 使用指南 OpenClaw 记忆管理与技能创建指南 CBS(Conflict-Based Search)算法详解 A* 算法及其变种详解 OpenClaw 配置多 Agents Windows Powershell 无法加载文件,因为在此系统上禁止运行脚本问题的解决方案 MaxClaw 安装流程 大模型 AI 名词介绍 AList 网盘聚合工具简介 Protobuf 简介与测试 Claude Code 简介以及 GLM 4.7 模型接入 Github 歌词下载工具 163MusicLyrics Python __getattr__ 懒加载 Python TypedDict 机器人仿真平台 Gazebo 安装记录 机器人仿真平台 Gazebo 简介 多机器人路径规划问题(Multi-Agent Path Finding, MAPF)简介 Python exifread 读取修改过的 jpeg 信息错误问题修复 3D 坐标系变换的理解 3D 旋转矩阵基本概念 MongoDB Compass 介绍 Python 环境管理工具 uv Flutter 开发指南 Snipaste 安装下载与黑屏问题解决方案 全局路径规划算法记录
OpenCV 畸变矫正映射
Yiwei Zhang · 2022-12-28 · via 又见苍岚

$$ \begin{array}{c} x \leftarrow\left(u-c^{\prime}{ }_{x}\right) / f^{\prime}{ }_{x} \\ y \leftarrow\left(v-c_{y}^{\prime}\right) / f_{y}^{\prime} \\ [X Y W]^{T} \leftarrow R^{-1} *[x y 1]^{T} \\ x^{\prime} \leftarrow X / W \\ y^{\prime} \leftarrow Y / W \\ r^{2} \leftarrow x^{\prime 2}+y^{\prime 2} \\ x^{\prime \prime} \leftarrow x^{\prime} \frac{1+k_{1} r^{2}+k_{2} r^{4}+k r^{6}{ }^{6}}{1+k_{4} r^{2}+k_{5} r^{4}+k_{6 r^{6}}}+2 p_{1} x^{\prime} y^{\prime}+p_{2}\left(r^{2}+2 x^{\prime 2}\right)+s_{1} r^{2}+s_{2} r^{4} \\ y^{\prime \prime} \leftarrow y^{\prime} \frac{1+k_{1} r^{2}+k_{2} r^{4}+k r^{3} r^{6}}{1+k_{4} r^{2}+k k_{5} r^{4}+k r^{6}}+p_{1}\left(r^{2}+2 y^{2}\right)+2 p_{2} x^{\prime} y^{\prime}+s_{3} r^{2}+s_{4} r^{4} \\ s\left[\begin{array}{c}x^{\prime \prime \prime} \\ y^{\prime \prime \prime} \\ 1\end{array}\right]=\left[\begin{array}{ccc}R_{33}\left(\tau_{x}, \tau_{y}\right) & 0 & -R_{13}\left(\left(\tau_{x}, \tau_{y}\right)\right. \\ 0 & R_{33}\left(\tau_{x}, \tau_{y}\right) & -R_{23}\left(\tau_{x}, \tau_{y}\right) \\ 0 & 0 & 1\end{array}\right] R\left(\tau_{x}, \tau_{y}\right)\left[\begin{array}{c}x^{\prime \prime} \\ y^{\prime \prime} \\ 1\end{array}\right] \\ \operatorname{map}_{x}(u, v) \leftarrow x^{\prime \prime \prime} f_{x}+c_{x} \\ \operatorname{map}_{y}(u, v) \leftarrow y^{\prime \prime \prime} f_{y}+c_{y} \\ \end{array} $$

$$ \operatorname{dst}(x, y)=\operatorname{src}\left(\operatorname{map}_{x}(x, y), \operatorname{map}_{y}(x, y)\right) $$

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import cv2 as cv
import mtutils as mt

# termination criteria
criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 30, 0.001)

# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,6,0)
W_num = 7
H_num = 7

objp = np.zeros((W_num*H_num,3), np.float32)
objp[:,:2] = np.mgrid[0:W_num,0:H_num].T.reshape(-1,2)

# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.

img = mt.cv_rgb_imread('undistort.png', 1)

another = img.copy()
# Find the chess board corners
ret, corners = cv.findChessboardCorners(img, (W_num,H_num), None)
# If found, add object points, image points (after refining them)
if ret == True:
objpoints.append(objp)
corners2 = cv.cornerSubPix(img,corners, (11,11), (-1,-1), criteria)
imgpoints.append(corners2)
# Draw and display the corners
cv.drawChessboardCorners(img, (W_num, H_num), corners2, ret)
mt.PIS(img)

ret, mtx, dist, rvecs, tvecs = cv.calibrateCamera(objpoints, imgpoints, img.shape[::-1], None, None)
h, w = img.shape[:2]
newcameramtx, roi = cv.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h))
# 原始 mtx 效果会好一些
# dst = cv.undistort(another, mtx, dist, None, newcameramtx)
dst = cv.undistort(another, mtx, dist, None, mtx)

# 点校正
undis_corners2 = cv.undistortPoints(corners2, mtx, dist, None, mtx)

# build map matrix
# 原始 mtx 效果会好一些
# map1, map2 = cv.initUndistortRectifyMap(mtx, dist, None, newcameramtx, img.shape[::-1], cv.CV_32FC1)
map1, map2 = cv.initUndistortRectifyMap(mtx, dist, None, mtx, img.shape[::-1], cv.CV_32FC1)
frame2 = cv.remap(another2, map1, map2, cv.INTER_LINEAR)

mt.PIS([another, 'origin'], [img, 'marked'], [dst, 'undistort'], row_num=1)
pass