# 行人检测

# 简介

行人检测属于目标检测的一种,专注于在图像或视频中定位并识别人类行走目标。

# 安装

# Maven

在项目的 pom.xml 中添加以下依赖,详细引入方式参考 Maven 引入

如需引入全部功能,请使用 【不推荐 ❌】 all 模块。

<dependency>
    <groupId>cn.smartjavaai</groupId>
    <artifactId>vision</artifactId>
    <version>1.0.24</version>
</dependency>

# 获取行人检测模型

PersonDetModelConfig config = new PersonDetModelConfig();
config.setModelEnum(PersonDetectorModelEnum.YOLOV8_PERSON);
config.setModelPath("/Users/wenjie/Documents/develop/model/person/yolov8n-person.onnx");
PersonDetModel detectorModel = ObjectDetectionModelFactory.getInstance().getModel(config);

# PersonDetModelConfig参数说明

字段名称 字段类型 默认值 说明
modelEnum PersonDetectorModelEnum 行人检测模型枚举
modelPath String 模型路径
topK int 不限制 检测结果数量
threshold double 0.5 置信度阈值,分数低于这个值的结果将被过滤掉。值越高越严格,越低越宽松
device DeviceEnum CPU 指定运行设备,支持 CPU/GPU
gpuId int 0 gpu设备ID 当device为GPU时生效
predictorPoolSize int 默认为cpu核心数 模型预测器线程池大小
customParams Map<String, Object> 个性化配置(按模型类型动态解析)

# 支持行人检测模型

模型名称 引擎 模型开源网站
YOLOV8_PERSON OnnxRuntime Github (opens new window)

# PersonDetModel API 方法说明

# 行人检测

Image图片源请查看文档Image使用说明

R<DetectionResponse> detect(Image image);
DetectedObjects detectCore(Image image);

# DetectionResponse字段说明

  • 返回并非json格式,仅用于字段讲解
{
  "detectionInfoList": [ //检测信息列表
    {
      "detectionRectangle": { //矩形框
        "height": 174, // 矩形高度
        "width": 147, // 矩形宽度
        "x": 275, // 左上角横坐标
        "y": 143 // 左上角纵坐标
      },
      "objectDetInfo": { //行人检测信息
        "className": "person" //类别
      },
      "score": 0.8118719 //检测结果置信度分数
    }
  ]
}

# 检测并绘制结果

该接口支持对图像进行检测,并将检测结果绘制在图像上,同时返回检测结果信息。

  • 保存绘制后的图片到指定路径,检测结果通过 DetectionResponse 返回。
R<DetectionResponse> detectAndDraw(String imagePath, String outputPath);
  • 支持直接输入 Image 对象进行检测,检测结果通过 DetectionResponse 返回。
    可以通过 DetectionResponse 中的 drawnImage 获取绘制后的 Image 对象。
R<DetectionResponse> detectAndDraw(Image image);

# 使用说明
  • imagePath:待检测图像的文件路径。
  • outputPath:绘制检测结果后图像的保存路径。
  • image:待检测的 Image 对象。
  • 返回的 DetectionResponse 包含检测框信息及绘制后的图像(drawnImage),方便后续处理或展示。

# 模型下载

百度网盘:https://pan.baidu.com/s/1zFrlXnp1EvEzbDsUfSXi8A?pwd=1234 提取码: 1234

# 完整示例代码

示例代码 (opens new window)

# 离线使用

离线使用请看文档