Gazebo仿真Kinect相机内参获取,以及fx fy cx cy 的理解

sensor_msgs/CameraInfo Message
File: sensor_msgs/CameraInfo.msg
Raw Message Definition
# This message defines meta information for a camera. It should be in a
# camera namespace on topic "camera_info" and accompanied by up to five
# image topics named:
#
#   image_raw - raw data from the camera driver, possibly Bayer encoded
#   image            - monochrome, distorted
#   image_color      - color, distorted
#   image_rect       - monochrome, rectified
#   image_rect_color - color, rectified
#
# The image_pipeline contains packages (image_proc, stereo_image_proc)
# for producing the four processed image topics from image_raw and
# camera_info. The meaning of the camera parameters are described in
# detail at http://www.ros.org/wiki/image_pipeline/CameraInfo.
#
# The image_geometry package provides a user-friendly interface to
# common operations using this meta information. If you want to, e.g.,
# project a 3d point into image coordinates, we strongly recommend
# using image_geometry.
#
# If the camera is uncalibrated, the matrices D, K, R, P should be left
# zeroed out. In particular, clients may assume that K[0] == 0.0
# indicates an uncalibrated camera.

#######################################################################
#                     Image acquisition info                          #
#######################################################################

# Time of image acquisition, camera coordinate frame ID
Header header    # Header timestamp should be acquisition time of image
                 # Header frame_id should be optical frame of camera
                 # origin of frame should be optical center of camera
                 # +x should point to the right in the image
                 # +y should point down in the image
                 # +z should point into the plane of the image


#######################################################################
#                      Calibration Parameters                         #
#######################################################################
# These are fixed during camera calibration. Their values will be the #
# same in all messages until the camera is recalibrated. Note that    #
# self-calibrating systems may "recalibrate" frequently.              #
#                                                                     #
# The internal parameters can be used to warp a raw (distorted) image #
# to:                                                                 #
#   1. An undistorted image (requires D and K)                        #
#   2. A rectified image (requires D, K, R)                           #
# The projection matrix P projects 3D points into the rectified image.#
#######################################################################

# The image dimensions with which the camera was calibrated. Normally
# this will be the full camera resolution in pixels.
uint32 height
uint32 width

# The distortion model used. Supported models are listed in
# sensor_msgs/distortion_models.h. For most cameras, "plumb_bob" - a
# simple model of radial and tangential distortion - is sufficient.
string distortion_model

# The distortion parameters, size depending on the distortion model.
# For "plumb_bob", the 5 parameters are: (k1, k2, t1, t2, k3).
float64[] D

# Intrinsic camera matrix for the raw (distorted) images.
#     [fx  0 cx]
# K = [ 0 fy cy]
#     [ 0  0  1]
# Projects 3D points in the camera coordinate frame to 2D pixel
# coordinates using the focal lengths (fx, fy) and principal point
# (cx, cy).
float64[9]  K # 3x3 row-major matrix

# Rectification matrix (stereo cameras only)
# A rotation matrix aligning the camera coordinate system to the ideal
# stereo image plane so that epipolar lines in both stereo images are
# parallel.
float64[9]  R # 3x3 row-major matrix

# Projection/camera matrix
#     [fx'  0  cx' Tx]
# P = [ 0  fy' cy' Ty]
#     [ 0   0   1   0]
# By convention, this matrix specifies the intrinsic (camera) matrix
#  of the processed (rectified) image. That is, the left 3x3 portion
#  is the normal camera intrinsic matrix for the rectified image.
# It projects 3D points in the camera coordinate frame to 2D pixel
#  coordinates using the focal lengths (fx', fy') and principal point
#  (cx', cy') - these may differ from the values in K.
# For monocular cameras, Tx = Ty = 0. Normally, monocular cameras will
#  also have R = the identity and P[1:3,1:3] = K.
# For a stereo pair, the fourth column [Tx Ty 0]' is related to the
#  position of the optical center of the second camera in the first
#  camera's frame. We assume Tz = 0 so both cameras are in the same
#  stereo image plane. The first camera always has Tx = Ty = 0. For
#  the right (second) camera of a horizontal stereo pair, Ty = 0 and
#  Tx = -fx' * B, where B is the baseline between the cameras.
# Given a 3D point [X Y Z]', the projection (x, y) of the point onto
#  the rectified image is given by:
#  [u v w]' = P * [X Y Z 1]'
#         x = u / w
#         y = v / w
#  This holds for both images of a stereo pair.
float64[12] P # 3x4 row-major matrix


#######################################################################
#                      Operational Parameters                         #
#######################################################################
# These define the image region actually captured by the camera       #
# driver. Although they affect the geometry of the output image, they #
# may be changed freely without recalibrating the camera.             #
#######################################################################

# Binning refers here to any camera setting which combines rectangular
#  neighborhoods of pixels into larger "super-pixels." It reduces the
#  resolution of the output image to
#  (width / binning_x) x (height / binning_y).
# The default values binning_x = binning_y = 0 is considered the same
#  as binning_x = binning_y = 1 (no subsampling).
uint32 binning_x
uint32 binning_y

# Region of interest (subwindow of full camera resolution), given in
#  full resolution (unbinned) image coordinates. A particular ROI
#  always denotes the same window of pixels on the camera sensor,
#  regardless of binning settings.
# The default setting of roi (all values 0) is considered the same as
#  full resolution (roi.width = width, roi.height = height).
RegionOfInterest roi

Compact Message Definition
std_msgs/Header header
uint32 height
uint32 width
string distortion_model
float64[] D
float64[9] K
float64[9] R
float64[12] P
uint32 binning_x
uint32 binning_y
sensor_msgs/RegionOfInterest roi
autogenerated on Fri, 15 Jan 2021 03:18:41

header:标准消息头
seq:序列ID,连续递增的ID号
stamp:两个时间戳
frame_id:与此数据相关联的帧ID
height:图像尺寸,height代表高度,(heightwidth)相机的分辨率,以像素为单位
width:图像尺寸,width代表宽度,(height
width)相机分辨率,以像素为单位
distortion_model:指定了相机畸变模型,对于大多数相机,"plumb_bob"简单的径向和切向畸变模型就足够了
D:畸变参数,取决于畸变模型,(k1, k2, t1, t2, k3),(我的这个usb相机号称是无畸变相机,但通过标定结果可以看出来还是存在畸变的,是不是被商家坑了,哈哈哈)
K:相机内参矩阵,使用焦距(fx, fy)和主点坐标(cx, cy),单位为像素,内参矩阵可以将相机坐标中的3D点投影到2D像素坐标

R:旋转矩阵,将相机坐标系统对准理想的立体图像平面,使两张立体图像中的极线平行
P:投影矩阵

左边3*3矩阵是相机的内参矩阵,将相机坐标中的3D点投影到2D像素坐标,可能与相机内参K不同。对于单目相机Tx = Ty = 0。对于双目相机,Tx和Ty有所不同。
binning_x:图像下采样参数,水平方向
binning_y:图像下采样参数,竖直方向
(width / binning_x) x (height / binning_y)
下采样:binning_x = binning_y > 1。缩小图像,生成对应图像的缩略图,使得图像符合显示区域的大小。
roi:感兴趣区域定义,即完整图像上的一个矩形子窗口

其中k

     [fx  0 cx]
 K = [ 0 fy cy]
     [ 0  0  1]
rostopic echo /camera/depth/camera_info

以下是关于sensor_msgs/CameraInfo Message 的🌰

https://vimsky.com/examples/detail/python-method-sensor_msgs.msg.CameraInfo.html

# 需要导入模块: from sensor_msgs import msg [as 别名]
# 或者: from sensor_msgs.msg import CameraInfo [as 别名]
def __init__(self, camera_name, base_frame, table_height):
        """
        Initialize the instance

        :param camera_name: The camera name. One of (head_camera, right_hand_camera)
        :param base_frame: The frame for the robot base
        :param table_height: The table height with respect to base_frame
        """
        self.camera_name = camera_name
        self.base_frame = base_frame
        self.table_height = table_height

        self.image_queue = Queue.Queue()
        self.pinhole_camera_model = PinholeCameraModel()
        self.tf_listener = tf.TransformListener()

        camera_info_topic = "/io/internal_camera/{}/camera_info".format(camera_name)
        camera_info = rospy.wait_for_message(camera_info_topic, CameraInfo)

        self.pinhole_camera_model.fromCameraInfo(camera_info)

        cameras = intera_interface.Cameras()
        cameras.set_callback(camera_name, self.__show_image_callback, rectify_image=True) 

内参是一个3×3 的矩阵,

其中cx和cy,它们表示相机光轴在图像坐标系中的偏移量,以像素为单位。但对于焦距fx和fy
在这里插入图片描述

就不是很直观了。为什么一个相机会出现两个焦距呢?在我们习惯使用的相机针孔模型中,一个透镜的焦距通常只有一个。然而我们不能用针孔模型去解释这两个内参中的焦距。但我们可以从透视规律来解释这两个焦距。

由相机拍摄得到的图像是遵从线性透视规律的。也就是说,一个物体的的宽和高会随着这个物体与相机间的距离增加而按比例变小。而对于一张矩形的图片,一个物体的宽和高则会根据物体与相机的距离按不同的比例变小。而这个比例,就是根据相机的焦距得到的。现在我们再利用针孔模型推导出这个比例关系,

在这里插入图片描述

以上是当图像是正方形时的关系,就是当fx=fy时的情况。其中f是相机的焦距,以像素为单位;d为物体到相机的距离,单位为米;x是物体在图像中的宽度,w为物体的实际宽度;y是物体在图像中的高度,而h是物体的实际高度。而对于一张矩形的图像,则有

在这里插入图片描述

  • 14
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: 在gazebo仿真中,我们可以通过以下步骤使用D435相机获取某个点的三维坐标: 1. 首先,确保已经在gazebo仿真环境中正确配置了D435相机模型,并将其添加到场景中。 2. 在仿真环境中创建一个可编程的控制器或插件,以便能够通过代码访问和控制相机。通常,这可以通过插件编程语言(例如C++)或ROS中的节点来实现。 3. 在控制器或插件中,运用D435相机对应的API函数,以启动相机并开始获取图像数据。这需要设置相机的一些参数,如分辨率、帧率等。 4. 接下来,我们要识别以目标点为中心的像素坐标。可以使用OpenCV或其他图像处理库来分析相机图像数据,并通过阈值或特征点检测等算法定位目标点的像素坐标。 5. 一旦得到目标点的像素坐标,我们需要将其转换为相机坐标系下的坐标。可以通过相机内参矩阵和畸变系数,使用OpenCV提供的函数将像素坐标转换为相机坐标。 6. 最后,将相机坐标转换为世界坐标系下的坐标。在gazebo仿真中,通过查找相机模型在场景中的位置和方向,可以使用相应的变换矩阵将相机坐标转换为世界坐标。 综上所述,通过配置相机模型并编写相应的控制器或插件,在gazebo仿真中使用D435相机获取某个点的三维坐标可以通过图像处理和变换矩阵的方法来实现。 ### 回答2: 在gazebo仿真中,可以通过使用d435相机获取某个点的三维坐标。首先,确保已经在gazebo环境中加载并启动了d435相机模型。 接下来,需要编写一个用于获取三维坐标的程序或脚本。以下是一个示例Python脚本,用于在gazebo仿真获取d435相机中某个点的三维坐标: ```python import rospy from sensor_msgs.msg import PointCloud2 from sensor_msgs import point_cloud2 as pc2 def callback(data): # 将PointCLoud2消息转换为点云数据 pc_data = pc2.read_points(data, skip_nans=True) # 定义待获取坐标的像素点位置 pixel_x = 320 pixel_y = 240 # 通过像素点位置获取相机坐标系下的三维点坐标 for i, p in enumerate(pc_data): if i == pixel_y * width + pixel_x: x, y, z = p rospy.loginfo("3D Point Coordinates: x = %f, y = %f, z = %f", x, y, z) break def listener(): rospy.init_node('point_cloud_listener', anonymous=True) rospy.Subscriber('/d435/points', PointCloud2, callback) rospy.spin() if __name__ == '__main__': listener() ``` 在该示例中,首先通过定义待获取坐标的像素点位置,这里我们假设要获取第240行,第320列的像素点的坐标。 接下来,在回调函数中,将PointCLoud2消息转换为点云数据。然后,通过迭代点云数据,找到指定像素点位置对应的三维点坐标。 最后,在获取到三维点坐标后,可以通过rospy.loginfo函数打印出来。 请注意,该示例中的topic名称`/d435/points`是指d435相机发布的点云数据的topic名称,在实际使用中需要根据实际情况进行修改。 通过运行上述代码,就可以在gazebo仿真获取d435相机中指定像素点位置的三维坐标信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值