소스 정보
- 저장소
- MIUAV/vibe-coding-ros2
- 최근 소스 활동
- 2026년 4월 3일 16:37
- 감지된 SKILL.md 언어
- 중국어
- 스타
- 26
- 포크
- 2
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill depth-estimation명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SOC 직업 분류 기준
SKILL.md 표시 중
| name | depth-estimation |
| description | OpenCV4 深度估计技能 - 单目深度估计、立体深度估计、ToF、LiDAR 融合、结构光 |
| user-invocable | true |
| argument-hint | 深度估计 OR 深度学习 OR 单目 OR 立体匹配 OR ToF OR LiDAR OR 3D点云 |
深度估计完整指南
当需要以下帮助时使用此技能:
import cv2
import numpy as np
# 加载 MiDaS 模型
model = cv2.dnn.readNet('MiDaS/model.onnx')
# 预处理
def preprocess_midas(img):
original = img.copy()
input_size = (384, 384)
img = cv2.resize(img, input_size)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) / 255.0
img = (img - np.array([0.485, 0.456, 0.406])) / np.array([0.229, 0.224, 0.225])
img = img.transpose(2, 0, 1)
return img[np.newaxis, :, :, :].astype(np.float32), original
# 推理
def estimate_depth(model, img):
input_tensor, original = preprocess_midas(img)
model.setInput(input_tensor)
depth = model.forward()
depth = cv2.resize(depth[0, 0], (original.shape[1], original.shape[0]))
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0
return depth.astype(np.uint8)
# 伪彩色显示
depth_colored = cv2.applyColorMap(cv2.convertScaleAbs(depth, alpha=0.03), cv2.COLORMAP_JET)
import cv2
import numpy as np
# 加载标定参数
data = np.load('stereo_calibration.npz')
mtx_l = data['mtx_l']
mtx_r = data['mtx_r']
R = data['R']
T = data['T']
dist_l = data['dist_l']
dist_r = data['dist_r']
# 立体校正
R1, R2, P1, P2, Q, _, _ = cv2.stereoRectify(
mtx_l, dist_l, mtx_r, dist_r,
img_size, R, T)
# 计算映射
map1_l, map2_l = cv2.initUndistortRectifyMap(mtx_l, dist_l, R1, P1, img_size, cv2.CV_32FC2)
map1_r, map2_r = cv2.initUndistortRectifyMap(mtx_r, dist_r, R2, P2, img_size, cv2.CV_32FC2)
# 校正图像
rect_l = cv2.remap(img_l, map1_l, map2_l, cv2.INTER_LINEAR)
rect_r = cv2.remap(img_r, map1_r, map2_r, cv2.INTER_LINEAR)
# SGBM 立体匹配
stereo = cv2.StereoSGBM_create(
minDisparity=0,
numDisparities=64,
blockSize=9,
uniquenessRatio=10,
speckleWindowSize=100,
speckleRange=32,
disp12MaxDiff=1
)
disparity = stereo.compute(rect_l, rect_r)
# 视差转深度
focal_length = mtx_l[0, 0]
baseline = abs(T[0, 0])
depth = (focal_length * baseline) / (disparity + 1e-6)
import cv2
import numpy as np
from open3d import *
# 从深度图和内参生成点云
def depth_to_pointcloud(depth, intrinsic):
h, w = depth.shape
fx, fy = intrinsic[0, 0], intrinsic[1, 1]
cx, cy = intrinsic[0, 2], intrinsic[1, 2]
points = []
colors = []
for y in range(h):
for x in range(w):
z = depth[y, x] / 1000.0 # mm to m
if z <= 0:
continue
X = (x - cx) * z / fx
Y = (y - cy) * z / fy
points.append([X, y, z])
colors.append([1, 1, 1])
pcd = PointCloud()
pcd.points = Vector3dVector(np.array(points))
pcd.colors = Vector3dVector(np.array(colors) / 255.0)
return pcd
# 使用 OpenCV 的 reprojectImageTo3D
points_3d = cv2.reprojectImageTo3D(disparity, Q)
mask = disparity > disparity.min()
points = points_3d[mask]
import pyrealsense2 as rs
# 初始化 pipeline
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
profile = pipeline.start(config)
# 获取内参
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
intrinsic = depth_frame.profile.as_video_stream_profile().intrinsics
# 深度处理
depth = np.asanyarray(depth_frame.get_data())
color = np.asanyarray(color_frame.get_data())
# 深度滤波
depth_filtered = cv2.bilateralFilter(depth, 5, 30, 30)
# 深度转伪彩色
depth_colored = cv2.applyColorMap(cv2.convertScaleAbs(depth, alpha=0.03), cv2.COLORMAP_JET)
# 稀疏深度补全(使用 RGB 引导)
def fill_depth_holes(depth, rgb):
# 安装 opencv-contrib
# depth = cv2.xphoto.inpaint(depth, mask, cv2.xphoto.INPAINT_SHADOWS)
pass
# 导向滤波深度优化
def guided_depth_filter(depth, rgb, epsilon=0.01):
# 引导滤波
guided_filter = cv2.ximgproc.createGuidedFilter(rgb, 9, epsilon)
depth_filtered = guided_filter.filter(depth.astype(np.float32))
return depth_filtered
#include <opencv2/opencv.hpp>
#include <opencv2/ximgproc.hpp>
// MiDaS 单目深度估计
cv::Mat estimateDepthMidas(cv::dnn::Net& net, const cv::Mat& img) {
cv::Mat input;
cv::dnn::blobFromImage(img, input, 1/255.0, cv::Size(384, 384));
net.setInput(input);
cv::Mat depth = net.forward();
cv::resize(depth, depth, img.size());
cv::normalize(depth, depth, 0, 255, cv::NORM_MINMAX);
return depth;
}
// 双目深度估计
cv::Mat computeDepthStereo(cv::Mat& rect_l, cv::Mat& rect_r,
cv::Mat& mtx_l, cv::Mat& T) {
cv::Ptr<cv::StereoSGBM> stereo = cv::StereoSGBM::create(
0, 64, 9, 8*9*9, 32*9*9, 1, 63, 10, 100, 32);
cv::Mat disparity;
stereo->compute(rect_l, rect_r, disparity);
// 视差转深度
cv::Mat depth;
float f = mtx_l.at<float>(0, 0);
b = (T.<>(, ));
cv::(disparity, depth, f * b / (disparity + ));
depth;
}
单目 vs 双目:
立体匹配优化:
深度滤波:
点云处理:
VoxelGrid 滤波StatisticalOutlierRemovalprojectPoints