wsc_robotic.vision package

Submodules

wsc_robotic.vision.camera module

class wsc_robotic.vision.camera.Camera(robotics)

基类:object

相机

read_video_stream()

读取订阅的彩色图像

参数:

None

返回:

True成功, False失败 img(np.ndarray):图像

返回类型:

ret(bool)

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

拍照接口Srv方式

参数:
  • method (SnapMethod) -- ALL拍所有,COLOR彩色图,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)

订阅彩色图像Topic

参数:

compressed (bool) -- true为订阅压缩图像, 订阅速度更快, 订阅图像质量更差; false为订阅原始图像, 订阅速度更慢, 订阅图像质量更好; 默认为false

返回:

None

stop_video_stream()

停止订阅彩色图像Topic

参数:

None

返回:

None

class wsc_robotic.vision.camera.SnapMethod(value)

基类:Enum

An enumeration.

ALL = 0
COLOR = 1
DEPTH = 2

wsc_robotic.vision.mnn_detector module

class wsc_robotic.vision.mnn_detector.MNNDetector(robotics)

基类:object

MNN检测器

detect()

检测

参数:

None

返回:

检测成功返回True, 否则返回False results (dict): 检测结果

返回类型:

ret (bool)

get_result_image()

获取检测结果图片

参数:

None

返回:

获取成功返回True, 否则返回False img (np.ndarray): 检测结果图片

返回类型:

ret (bool)

is_opened()

检测器是否已经打开(加载完模型)

参数:

None

返回:

检测器是否已经打开(加载完模型)

返回类型:

bool

start(mode_path='', label_path='', nms_thres=0.7)

启动检测器

参数:
  • mode_path (str) -- 模型路径

  • label_path (str) -- 标签路径

  • nms_thres (float) -- nms阈值

返回:

启动成功返回True, 否则返回False

返回类型:

bool

stop()

关闭检测器

参数:

None

返回:

关闭成功返回True, 否则返回False

返回类型:

bool

wsc_robotic.vision.object_3d_extractor module

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

基类:object

3D目标提取

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 (np.ndarray) -- RGB图像

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

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

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

返回:

更新后的检测结果列表

返回类型:

updated_results(List[DetectionResult3D])

wsc_robotic.vision.object_3d_extractor.main()

wsc_robotic.vision.user_mnn_detector module

class wsc_robotic.vision.user_mnn_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]

获取边界框中心点坐标

参数:

None

返回:

中心点坐标

返回类型:

Tuple[float, float]

get_width_height() Tuple[int, int]

获取边界框宽度和高度

参数:

None

返回:

宽度和高度

返回类型:

Tuple[int, int]

label: str
point_density: float = 0.0
score: float
class wsc_robotic.vision.user_mnn_detector.ModelConfig(MODEL_PATH: str = '', LABEL_PATH: str = '', MODEL_VERSION: wsc_robotic.vision.user_mnn_detector.ModelVersion = <ModelVersion.YOLO11: 'yolo11'>, NMS_THRES: float = 0.45, MODEL_SIZE: int = 320, PRECISION: str = 'normal', BACKEND: str = 'CPU', THREAD: int = 1)

基类:object

BACKEND: str = 'CPU'
LABEL_PATH: str = ''
MODEL_PATH: str = ''
MODEL_SIZE: int = 320
MODEL_VERSION: ModelVersion = 'yolo11'
NMS_THRES: float = 0.45
PRECISION: str = 'normal'
THREAD: int = 1
class wsc_robotic.vision.user_mnn_detector.ModelVersion(value)

基类:Enum

模型版本

YOLO11 = 'yolo11'
YOLO26 = 'yolo26'
class wsc_robotic.vision.user_mnn_detector.Point3D(x: float, y: float, z: float)

基类:object

三维点的数据结构

classmethod from_numpy(arr: ndarray) Point3D

从numpy数组创建Point3D对象

x: float
y: float
z: float
class wsc_robotic.vision.user_mnn_detector.UserMnnDetector

基类:object

用户自定义MNN模型推理类

inference_yolo11(input_var: ndarray, original_image: ndarray) List[DetectionResult3D]

进行模型推理并返回检测结果

参数:
  • input_var (np.ndarray) -- 输入数据,形状为[1, 3, 320, 320]

  • original_image (np.ndarray) -- 原始图像数据,用于绘制检测结果

返回:

检测结果列表

返回类型:

List[DetectionResult3D]

inference_yolo26(input_var: ndarray, original_image: ndarray) List[DetectionResult3D]

进行模型推理并返回检测结果yolo26

参数:
  • input_var (np.ndarray) -- 输入数据,形状为[1, 3, 320, 320]

  • original_image (np.ndarray) -- 原始图像数据,用于绘制检测结果

返回:

检测结果列表

返回类型:

List[DetectionResult3D]

load_from_txt(file_path: str | None = None) List[str]

从txt文件中加载标签列表

参数:

file_path (str) -- 标签文件路径

返回:

标签列表

返回类型:

List[str]

load_model(model_config: ModelConfig) None

加载模型

参数:

model_config (ModelConfig) -- 模型配置参数

返回:

None

mnn_detect(image_path: str) List[DetectionResult3D]

传入图像路径进行检测

参数:

image_path (str) -- 输入图像路径

返回:

检测结果列表

返回类型:

List[DetectionResult3D]

mnn_detect_img(img: ndarray) List[DetectionResult3D]

传入图像数组进行检测

参数:

img (np.ndarray) -- 输入图像数组,格式为BGR

返回:

检测结果列表

返回类型:

List[DetectionResult3D]

preprocess_yolo11(original_image: ndarray) Tuple[ndarray, ndarray]

预处理输入图像

参数:

original_image (np.ndarray) -- 原始图像数据

返回:

预处理后的图像数据和原始图像数据

返回类型:

Tuple[np.ndarray, np.ndarray]

preprocess_yolo26(original_image: ndarray) Tuple[ndarray, ndarray]

预处理输入图像yolo26

参数:

original_image (np.ndarray) -- 原始图像数据

返回:

预处理后的图像数据和原始图像数据

返回类型:

Tuple[np.ndarray, np.ndarray]

Module contents