方法一:用python获取
问ChatGPT4:Please give me the python code which return the intrinsics of D405 realsense camera.
为什么这样问呢?因为看到B站视频有对他的D415相机获取内参的代码:link,所以我就想找到我的相机D405对应的内参的获取方法。
ChatGPT的回答:
To retrieve the intrinsic parameters of an Intel RealSense D405 camera using Python, you will need to utilize the pyrealsense2
library, which is the Python wrapper for the RealSense SDK 2.0. Here’s how you can write a script to obtain the intrinsic parameters of the D405 camera:
- Install the pyrealsense2 library:
If you haven’t already installed thepyrealsense2
library, you can install it using pip:
pip install pyrealsense2
- Python Code to Get Intrinsic Parameters:
Here’s a simple Python script that initializes the camera, starts the pipeline, and retrieves the intrinsic parameters of the color camera of the D405.
import pyrealsense2 as rs
# Create a pipeline
pipeline = rs.pipeline()
# Create a config and configure the pipeline to stream
config = rs.config()
config.enable_device('your_device_serial_number') # Optional: specify the serial number of your D405 camera
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)
# Start the pipeline
pipeline.start(config)
# Get device product line for setting a supporting resolution
profile = pipeline.get_active_profile()
depth_sensor = profile.get_device().first_depth_sensor()
depth_scale = depth_sensor.get_depth_scale()
# Get the depth sensor's depth stream profile and extract intrinsic parameters
depth_stream = profile.get_stream(rs.stream.depth)
intrinsics = depth_stream.as_video_stream_profile().get_intrinsics()
# Print intrinsics
print("Width:", intrinsics.width)
print("Height:", intrinsics.height)
print("PPX:", intrinsics.ppx)
print("PPY:", intrinsics.ppy)
print("FX:", intrinsics.fx)
print("FY:", intrinsics.fy)
print("Distortion Model:", intrinsics.model)
print("Coefficients:", intrinsics.coeffs)
# Stop the pipeline
pipeline.stop()
In this script:
pipeline
andconfig
are used to set up and start the data stream from the RealSense camera.get_intrinsics()
is called on the depth stream profile to fetch the intrinsic parameters like focal length(fx, fy)
, principal point(ppx, ppy)
, and distortion coefficients.
Make sure your camera is connected and correctly configured before running this script. Replace ‘your_device_serial_number
’ with the actual serial number of your D405 camera if needed, especially if you have multiple RealSense cameras connected to your system.
This script focuses on retrieving the intrinsic parameters of the depth stream, but you can similarly access the intrinsic parameters for other streams (like color) by adjusting the rs.stream
type in the config.enable_stream()
and profile.get_stream()
methods.
把我的serial number输入进去之后(SN在相机包装盒上),代码输入结果为:
[Running] python -u "d:\Software\Python\pyCode\realsenseCamera\get_intrinsics.py"
Width: 1280
Height: 720
PPX: 652.3068237304688
PPY: 367.90887451171875
FX: 647.2796020507812
FY: 647.2796020507812
Distortion Model: distortion.brown_conrady
Coefficients: [0.0, 0.0, 0.0, 0.0, 0.0]
[Done] exited with code=0 in 1.291 seconds
对应每个内参的含义解释如下:
[Running] python -u "d:\Software\Python\pyCode\realsenseCamera\get_intrinsics.py"
Width: 1280
Height: 720
# (1280 and 720) 相机传感器的分辨率, 相机捕捉到的像素图像在宽度上(width)为1280像素(pixels),在高度上(height)为720像素。
PPX: 652.3068237304688 # PPX (Principal Point X) 主点 X 值
PPY: 367.90887451171875 # PPY (Principal Point Y) 主点 Y 值
# 主点(652.3068237304688, 367.90887451171875) 是图像中对应于镜头光学中心的坐标。理想情况下,这是图像传感器的中心,但制造缺陷通常会导致轻微的偏移。
FX: 647.2796020507812 # 焦距 X,单位像素
FY: 647.2796020507812 # 焦距 Y,单位像素
# (647.2796020507812 for both FX and FY) 表示相机镜头的焦距。 更高的焦距意味着相机的放大倍数更大。 FX 和 FY 相等表明相机传感器的像素是正方形的,这简化了计算机视觉任务中的某些计算。
Distortion Model: distortion.brown_conrady
# 这里的畸变模型被列为“ Distortion.brown_conrady”。该模型也称为布朗-康拉迪畸变,用于描述和校正相机中的镜头畸变。它是摄影和摄影测量中常用的畸变模型,可解决径向和切向分量。
Coefficients: [0.0, 0.0, 0.0, 0.0, 0.0]
# 这些是与失真模型相关的失真系数([0.0,0.0,0.0,0.0,0.0])。由于它们在你的输出中都是零,这表明基于校准没有可测量的失真,或者校准过程没有检测到任何失真。如果校准是在透镜畸变影响最小的条件下进行的,或者当软件无法充分计算参数时默认为零,则可能发生这种情况。
[Done] exited with code=0 in 1.291 seconds
方法二:用SDK获取
打开SDK里面的viewer工具,然后点击“More”, “Calibration Data”,即可看到内参如下所示:
PS:细心的同学可以发现,上面两种方法得到的内参数值不一样。
问题出在哪里呢?
答案就是:分辨率不一样哈哈哈,方法一的分辨率为1280×720,方法二的分辨率为1920×1080(在Focal Length那一行上面)
只要把方法一和方法二的分辨率调整成一致的,得到的内参就是近似相等的啦~