camera-calibration
OpenCV4 相机标定技能 - 单目/双目标定、畸变校正、立体匹配、深度估计、3D 重建
от MIUAV★ 30 звёзд на GitHub
Установить camera-calibration в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
OpenCV4 Camera Calibration Skill
相机标定与立体视觉完整指南
何时使用
当需要以下帮助时使用此技能:
- 单目相机标定(内参)
- 双目相机标定(内外参)
- 畸变校正
- 立体校正(极线校正)
- 立体匹配和深度估计
- 3D 重建
快速参考
标定板生成
import cv2
import numpy as np
import glob
# 生成棋盘格标定板
def generate_chessboard(size=(9, 6), square_size=1.0, save_path='chessboard.png'):
objp = np.zeros((size[0]*size[1], 3), np.float32)
objp[:, :2] = np.mgrid[0:size[0], 0:size[1]].T.reshape(-1, 2) * square_size
fig, ax = plt.subplots(figsize=(8, 6))
ax.set_xlim(0, size[0])
ax.set_ylim(0, size[1])
ax.set_aspect('equal')
ax.set_facecolor('white')
for i in range(size[0] + 1):
ax.axvline(i, color='black', linewidth=1)
for i in range(size[1] + 1):
ax.axhline(i, color='black', linewidth=1)
plt.axis('off')
plt.savefig(save_path, dpi=150, bbox_inches='tight',
facecolor='white', edgecolor='none')
plt.close()
# 或使用 OpenCV 打印标定板
# 国际象棋:9x6 角点,80mm 格子
# 圆形标定板:4x11 圆点阵列
单目相机标定
import cv2
import numpy as np
import glob
# 标定板参数
objp = np.zeros((6*9, 3), np.float32)
objp[:, :2] = np.mgrid[0:9, 0:6].T.reshape(-1, 2)
objp *= 25 # 格子大小 mm
# 存储所有图像的点
objpoints = [] # 3D 点
imgpoints = [] # 2D 点
images = glob.glob('calibration/*.jpg')
img_size = None
for fname in images:
img = cv2.imread(fname)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_size = gray.shape[::-1]
# 查找棋盘格角点
ret, corners = cv2.findChessboardCorners(gray, (9, 6), None)
if ret:
objpoints.append(objp)
# 亚像素精度优化
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
corners2 = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
imgpoints.append(corners2)
# 可视化
cv2.drawChessboardCorners(img, (9, 6), corners2, ret)
cv2.imshow('Corners', img)
cv2.waitKey(500)
cv2.destroyAllWindows()
# 标定
ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(
objpoints, imgpoints, img_size, None, None)
print(f"Camera Matrix:\n{camera_matrix}")
print(f"Distortion Coefficients:\n{dist_coeffs}")
# 保存标定结果
np.savez('calibration.npz',
camera_matrix=camera_matrix,
dist_coeffs=dist_coeffs,
rvecs=rvecs,
tvecs=tvecs)
畸变校正
# 加载标定结果
data = np.load('calibration.npz')
camera_matrix = data['camera_matrix']
dist_coeffs = data['dist_coeffs']
# 读取图像
img = cv2.imread('test.jpg')
h, w = img.shape[:2]
# 方法1:矫正映射
new_camera_matrix, roi = cv2.getOptimalNewCameraMatrix(
camera_matrix, dist_coeffs, (w, h), 1, (w, h))
mapx, mapy = cv2.initUndistortRectifyMap(
camera_matrix, dist_coeffs, None, new_camera_matrix, (w, h), 5)
undistorted = cv2.remap(img, mapx, mapy, cv2.INTER_LINEAR)
# 方法2:一步校正
undistorted = cv2.undistort(img, camera_matrix, dist_coeffs, None, new_camera_matrix)
# 裁剪 ROI 区域
x, y, w, h = roi
undistorted = undistorted[y:y+h, x:x+w]
双目相机标定
import cv2
import numpy as np
import glob
# 左右相机标定板点
objp = np.zeros((6*9, 3), np.float32)
objp[:, :2] = np.mgrid[0:9, 0:6].T.reshape(-1, 2) * 25
objpoints_l, imgpoints_l = [], []
objpoints_r, imgpoints_r = [], []
# 读取左右图像
images_l = sorted(glob.glob('stereo/left/*.jpg'))
images_r = sorted(glob.glob('stereo/right/*.jpg'))
for fname_l, fname_r in zip(images_l, images_r):
img_l = cv2.imread(fname_l)
img_r = cv2.imread(fname_r)
gray_l = cv2.cvtColor(img_l, cv2.COLOR_BGR2GRAY)
gray_r = cv2.cvtColor(img_r, cv2.COLOR_BGR2GRAY)
ret_l, corners_l = cv2.findChessboardCorners(gray_l, (9, 6), None)
ret_r, corners_r = cv2.findChessboardCorners(gray_r, (9, 6), None)
if ret_l and ret_r:
objpoints_l.append(objp)
objpoints_r.append(objp)
# 亚像素优化
corners_l = cv2.cornerSubPix(gray_l, corners_l, (11,11), (-1,-1),
(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001))
corners_r = cv2.cornerSubPix(gray_r, corners_r, (11,11), (-1,-1),
(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001))
imgpoints_l.append(corners_l)
imgpoints_r.append(corners_r)
# 分别标定左右相机
ret_l, mtx_l, dist_l, _, _ = cv2.calibrateCamera(objpoints_l, imgpoints_l, gray_l.shape[::-1], None, None)
ret_r, mtx_r, dist_r, _, _ = cv2.calibrateCamera(objpoints_r, imgpoints_r, gray_r.shape[::-1], None, None)
# 双目标定
ret, mtx_l, dist_l, mtx_r, dist_r, R, T, E, F = cv2.stereoCalibrate(
objpoints_l, imgpoints_l, imgpoints_r,
mtx_l, dist_l, mtx_r, dist_r,
gray_l.shape[::-1],
flags=cv2.CALIB_FIX_INTRINSIC)
print(f"Rotation R:\n{R}")
print(f"Translation T:\n{T}")
立体校正和匹配
# 立体校正
R1, R2, P1, P2, Q, _, _ = cv2.stereoRectify(
mtx_l, dist_l, mtx_r, dist_r,
gray_l.shape[::-1], R, T)
# 计算映射表
map1_l, map2_l = cv2.initUndistortRectifyMap(mtx_l, dist_l, R1, P1, gray_l.shape[::-1], cv2.CV_32FC2)
map1_r
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл camera-calibration?
OpenCV4 相机标定技能 - 单目/双目标定、畸变校正、立体匹配、深度估计、3D 重建
Как установить скилл camera-calibration?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл camera-calibration запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…