ros_robot.vision package

Submodules

ros_robot.vision.ball_grabbing module

class ros_robot.vision.ball_grabbing.BallGrabbing

基类:object

抓取目标计算

calculate_grasp_point(detection_results: List[DetectionResult3D], camera_info: dict, color_image: ndarray, depth_image: ndarray, camera_angle: float = -30.0, debug: bool = False) List[Target]

计算抓取点

参数:
  • detection_results (List[DetectionResult3D]) -- 检测结果

  • camera_info (dict) -- 相机信息

  • color_image (np.ndarray) -- 颜色图像

  • depth_image (np.ndarray) -- 深度图像

  • camera_angle (float, optional) -- 相机角度. Defaults to -30.0.

  • debug (bool, optional) -- 是否显示调试信息. Defaults to False.

返回:

抓取点列表

返回类型:

List[Target]

coordinate_transformation_3D(center3d: List[float], theta: float) List[float]

3D 坐标系转换

参数:
  • center3d (List[float]) -- 3D坐标

  • theta (float) -- 旋转角度

返回:

旋转后的坐标

返回类型:

List[float]

detect_colored_balls(image: ndarray, debug: bool = False) List[DetectionResult3D]

检测圆球

参数:
  • image (np.ndarray) -- 输入图像

  • debug (bool, optional) -- 是否显示调试信息. Defaults to False.

返回:

检测结果

返回类型:

List[DetectionResult3D]

relative_pos_to_world_pos(odom_pos: Tuple[float, float, float], relative_pos: Tuple[float, float, float]) Tuple[float, float, float]

相对坐标转世界坐标

参数:
  • odom_pos (Tuple[float, float, float]) -- 机器人坐标

  • relative_pos (Tuple[float, float, float]) -- 相对坐标

返回:

世界坐标

返回类型:

Tuple[float, float, float]

class ros_robot.vision.ball_grabbing.Target(name: str, center: ros_robot.vision.user_ball_detector.Point3D)

基类:object

center: Point3D
name: str

ros_robot.vision.camera module

class ros_robot.vision.camera.Camera(robotics)

基类:object

相机类

参数:

robotics (Robotics) -- 机器人实例

read_video_stream()

读取彩色图

参数:

None

返回:

True成功, img:彩色图

返回类型:

ret

start_video_stream(compressed=False)

开启图像订阅

参数:

compressed (bool, optional) -- 是否使用压缩图像. Defaults to False.

返回:

None

stop_video_stream()

关闭图像订阅

参数:

None

返回:

None

ros_robot.vision.camera_d module

class ros_robot.vision.camera_d.Camera(robotics)

基类:object

相机

read_video_stream()

读取图像

参数:

None

返回:

成功标志 img(np.ndarray): 图像

返回类型:

ret(bool)

snap(method=SnapMethod.ALL, sync=False)

拍照

参数:
  • method (SnapMethod) -- 拍照方式 0:ALL, 1:COLOR, 2:DEPTH

  • sync (bool) -- True为同步模式, 拍摄实时最新的图像, srv服务响应时间约等于100ms-200ms; flase为异步模式, 拍摄非最新的图像(底层缓存的图像),为上一帧或当前帧,srv服务响应时间短;

返回:

成功标志 color_image(np.ndarray): 彩色图 depth_image(np.ndarray): 深度图 info(dict): 内参信息

返回类型:

success(bool)

start_video_stream(compressed=False)

开启订阅图像

参数:

compressed (bool) -- True为压缩图像, False为原始图像

返回:

None

stop_video_stream()

停止订阅图像

参数:

None

返回:

None

class ros_robot.vision.camera_d.SnapMethod(value)

基类:Enum

An enumeration.

ALL = 0
COLOR = 1
DEPTH = 2

ros_robot.vision.object_3d_extractor module

class ros_robot.vision.object_3d_extractor.Object3DExtractor(depth_scale=0.001)

基类:object

3D目标提取

参数:

depth_scale -- 深度图缩放因子,通常为0.001(毫米转米)或1.0

extract_object_center_3d(detection_results: List[DetectionResult3D], camera_info: dict, rgb_image: ndarray | None = None, depth_image: ndarray | None = None, use_weighted_center: bool = True, debug: bool = False) List[DetectionResult3D]

批量提取多个目标的3D中心位置

参数:
  • detection_results (List[DetectionResult3D]) -- 检测结果列表

  • camera_info (dict) -- 相机内参信息字典

  • rgb_image (Optional[np.ndarray]) -- RGB图像

  • depth_image (np.ndarray) -- 深度图像

  • use_weighted_center (bool) -- 是否使用加权中心点

  • debug (bool) -- 是否显示调试信息

返回:

更新后的检测结果列表

返回类型:

List[DetectionResult3D]

ros_robot.vision.object_3d_extractor.main()

ros_robot.vision.user_ball_detector module

class ros_robot.vision.user_ball_detector.BallDetector

基类:object

球检测

detect_balls(image: ndarray, debug: bool = False) List[DetectionResult3D]

识别(红、黄、蓝、绿)的高尔夫球

参数:
  • image (np.ndarray) -- 输入图像

  • debug (bool, optional) -- 是否显示调试结果. Defaults to False.

返回:

检测结果列表

返回类型:

List[DetectionResult3D]

class ros_robot.vision.user_ball_detector.DetectionResult3D(label: str, score: float, class_id: int, bbox: Tuple[int, int, int, int], center_2d: Tuple[float, float] = (0.0, 0.0), center_3d: Point3D = Point3D(x=0, y=0, z=0), area: float = 0.0, point_density: float = 0.0)

基类:object

单个检测结果的数据结构

area: float = 0.0
bbox: Tuple[int, int, int, int]
center_2d: Tuple[float, float] = (0.0, 0.0)
center_3d: Point3D = Point3D(x=0, y=0, z=0)
class_id: int
get_center() Tuple[float, float]

获取边界框中心点坐标

get_width_height() Tuple[int, int]

获取边界框宽度和高度

label: str
point_density: float = 0.0
score: float
class ros_robot.vision.user_ball_detector.Point3D(x: float, y: float, z: float)

基类:object

三维点的数据结构

classmethod from_numpy(arr: ndarray) Point3D

从numpy数组创建Point3D对象

to_numpy() ndarray

返回numpy数组

x: float
y: float
z: float

Module contents