当前位置:   article > 正文

realsense相机内参获取_pyrealsense2 获取相机内参数

pyrealsense2 获取相机内参数

软件方法:rs-sensor-control获取

打开 C:\Program Files (x86)\Intel RealSense SDK 2.0\tools

  1. $ ./rs-sensor-control
  2. ======================================================
  3. Found the following devices:
  4. 0 : Intel RealSense D435 #817612070563
  5. Select a device by index: 0
  6. Device information:
  7. Name : Intel RealSense D435
  8. Serial Number : 817612070563
  9. Firmware Version : 05.10.06.00
  10. Recommended Firmware Version : 05.10.03.00
  11. Physical Port : /sys/devices/pci0000:00/0000:00:14.0/usb2/2-8/2-8:1.0/video4linux/video0
  12. Debug Op Code : 15
  13. Advanced Mode : YES
  14. Product Id : 0B07
  15. Camera Locked : N/A
  16. Usb Type Descriptor : 3.2
  17. ======================================================
  18. Device consists of 2 sensors:
  19. 0 : Stereo Module
  20. 1 : RGB Camera
  21. Select a sensor by index: 1
  22. ======================================================
  23. What would you like to do with the sensor?
  24. 0 : Control sensor's options
  25. 1 : Control sensor's streams
  26. 2 : Show stream intrinsics
  27. 3 : Display extrinsics
  28. Select an action:

注意第二项,这个就是内参的内容了。选择 2

  1. ======================================================
  2. Sensor consists of 1 streams:
  3. - Color #0
  4. Sensor provides the following stream profiles:
  5. 0 : Color #0 (Video Stream: RGB8 1920x1080@ 30Hz)
  6. 1 : Color #0 (Video Stream: RAW16 1920x1080@ 30Hz)
  7. 2 : Color #0 (Video Stream: Y16 1920x1080@ 30Hz)
  8. 3 : Color #0 (Video Stream: BGRA8 1920x1080@ 30Hz)
  9. 4 : Color #0 (Video Stream: RGBA8 1920x1080@ 30Hz)
  10. 5 : Color #0 (Video Stream: BGR8 1920x1080@ 30Hz)
  11. 6 : Color #0 (Video Stream: YUYV 1920x1080@ 30Hz)
  12. ... ...
  13. Please select the desired streaming profile:

所有流都在这里了,比如,选择 0

  1. Please select the desired streaming profile: 0
  2. Principal Point : 966.617, 532.934
  3. Focal Length : 1395.12, 1395.28
  4. Distortion Model : Brown Conrady
  5. Distortion Coefficients : [0,0,0,0,0]

相机的内参矩阵是

  1. K = fx s x0
  2. 0 fy y0
  3. 0 0 1

fx,fy 为焦距,一般情况下,二者相等。
x0,y0 为主坐标(相对于成像平面)。
s 为坐标轴倾斜参数,理想情况下为 0。

python pipeline

  1. import pyrealsense2 as rs
  2. pipeline = rs.pipeline()
  3. config = rs.config()
  4. config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
  5. config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)
  6. pipeline.start(config)
  7. time.sleep(1)
  8. frames = pipeline.wait_for_frames()
  9. # time.sleep(3)
  10. depth_frame = frames.get_depth_frame()
  11. color_frame = frames.get_color_frame()
  12. # Convert images to numpy arrays
  13. depth_image = np.asanyarray(depth_frame.get_data())
  14. color_image = np.asanyarray(color_frame.get_data())
  15. # # Apply colormap on depth image (image must be converted to 8-bit per pixel first)
  16. # depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
  17. #
  18. # # Stack both images horizontally
  19. # images = np.hstack((color_image, depth_colormap))
  20. #
  21. # # Show images
  22. # cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
  23. # cv2.imshow('RealSense', images)
  24. # cv2.waitKey(1)
  25. fig, axes = plt.subplots(1, 2)
  26. for ax, im in zip(axes, [color_image, depth_image]):
  27. ax.imshow(im)
  28. ax.axis('off')
  29. plt.show()
  30. pipeline.stop()
  1. import pyrealsense2 as rs
  2. pipeline = rs.pipeline()
  3. config = rs.config()
  4. config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
  5. config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)
  6. cfg = pipeline.start(config)
  7. time.sleep(1)
  8. profile = cfg.get_stream(rs.stream.depth)
  9. intr = profile.as_video_stream_profile().get_intrinsics()
  10. print(intr) # 获取内参 width: 640, height: 480, ppx: 319.115, ppy: 234.382, fx: 597.267, fy: 597.267, model: Brown Conrady, coeffs: [0, 0, 0, 0, 0]
  11. 319.1151428222656
  12. print(intr.ppx) # 获取指定某个内参

注意:通过 python script 获取内参一定要看好自己到底用了哪个 video stream,每个 video stream 的内参都是不一样的

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/59668?site
推荐阅读
相关标签
  

闽ICP备14008679号