主要内容

本页采用了机器翻译。点击此处可查看英文原文。

利用 Grounding DINO 实现零样本目标检测

将输入图像读入工作区。

I = imread("visionteam.jpg");

显示输入图像。

figure
imshow(I)

使用 Swin-Base 网络作为骨干网络,构建一个 Grounding DINO 目标检测器。

name = "swin-base";
detector = groundingDinoObjectDetector(name);

指定检测器应使用的类名,作为检测结果的输出标签。

labels = {'Holding paper','Holding jacket'};

指定检测器用于执行目标检测的类描述,作为文本查询。

descriptions = {'Person holding paper','Person holding jacket'};

使用指定的类名和描述来检测图像中的目标。

[bboxes,scores,labels] = detect(detector,I,ClassNames=labels,ClassDescriptions=descriptions);

对图像注解中检测到的标签和分数进行格式化处理。

outputLabels = compose("%s: %.2f",string(labels),scores);

对图像中检测到的目标进行注解。

detections = insertObjectAnnotation(I,"rectangle",bboxes,outputLabels);

显示带有检测结果注解的图像。

imshow(detections)
title("Objects Detected Using Text Queries with Grounding DINO")