主要内容

本页翻译不是最新的。点击此处可查看最新英文版本。

目标检测

使用卷积神经网络(CNN 或 ConvNet)执行分类、目标检测、迁移学习,创建自定义的检测器

目标检测是一种计算机视觉方法,用于定位图像或视频中的目标实例。目标检测算法通常利用机器学习深度学习来生成有意义的结果。当查看图像或观看视频时,人类可以在瞬间识别并定位感兴趣的目标。目标检测旨在使用计算机复现这种智能。目标检测的最佳方法取决于您的应用和所要尝试解决的问题。

深度学习方法需要大量经过标注的训练图像,因此,推荐使用 GPU 来减少训练模型所需的时间。基于深度学习的目标检测方法使用卷积神经网络(即 CNN 或 ConvNet),比如 YOLO,或使用单次检测 (SSD) 方法。您可以训练自定义目标检测器,或通过迁移学习方法来使用预训练的目标检测器,这种方法使您能够从预训练网络开始,然后针对您的应用进行微调。卷积神经网络需要 Deep Learning Toolbox™。具有 CUDA® 功能的 GPU 支持训练和预测。推荐使用 GPU,并且需要有 Parallel Computing Toolbox™。有关详细信息,请参阅Computer Vision Toolbox 预设项MathWorks 产品中的并行计算支持 (Parallel Computing Toolbox)

用于目标检测的机器学习方法包括聚合通道特征 (ACF)、使用有向梯度直方图 (HOG) 特征的支持向量机 (SVM) 分类以及用于人脸或上身检测的 Viola-Jones 算法。您可以选择从预训练的目标检测器开始,也可以根据您的应用创建自定义的目标检测器。

Labeled boats, neural network, and person detector

App

图像标注器为计算机视觉应用标注图像
视频标注器Label video for computer vision applications

函数

全部展开

深度学习检测器

rtmdetObjectDetectorDetect objects using RTMDet object detector (自 R2024b 起)
ssdObjectDetectorDetect objects using SSD deep learning detector
yolov2ObjectDetectorDetect objects using YOLO v2 object detector
yolov3ObjectDetectorDetect objects using YOLO v3 object detector (自 R2021a 起)
yolov4ObjectDetectorDetect objects using YOLO v4 object detector (自 R2022a 起)
yoloxObjectDetectorDetect objects using YOLOX object detector (自 R2023b 起)
peopleDetectorDetect people using pretrained deep learning object detector (自 R2024b 起)
faceDetectorDetect faces using pretrained RetinaFace face detector (自 R2025a 起)

基于特征的检测器

readAprilTagDetect and estimate pose for AprilTag in image
readArucoMarkerDetect and estimate pose for ArUco marker in image (自 R2024a 起)
generateArucoMarkerGenerate ArUco marker images (自 R2024a 起)
readBarcodeDetect and decode 1-D or 2-D barcode in image
acfObjectDetectorDetect objects using aggregate channel features
peopleDetectorACFDetect people using aggregate channel features
vision.CascadeObjectDetectorDetect objects using the Viola-Jones algorithm
vision.ForegroundDetectorForeground detection using Gaussian mixture models
vision.BlobAnalysisProperties of connected regions

使用点特征检测目标

detectBRISKFeaturesDetect BRISK features
detectFASTFeaturesDetect corners using FAST algorithm
detectHarrisFeatures使用哈里斯-斯蒂芬斯算法检测角点
detectKAZEFeaturesDetect KAZE features
detectMinEigenFeaturesDetect corners using minimum eigenvalue algorithm
detectMSERFeaturesDetect MSER features
detectORBFeaturesDetect ORB keypoints
detectSIFTFeaturesDetect scale invariant feature transform (SIFT) features (自 R2021b 起)
detectSURFFeatures检测 SURF 特征
extractFeaturesExtract interest point descriptors
matchFeaturesFind matching features

选择检测到的目标

selectStrongestBboxSelect strongest bounding boxes from overlapping clusters using nonmaximal suppression (NMS)
selectStrongestBboxMulticlassSelect strongest multiclass bounding boxes from overlapping clusters using nonmaximal suppression (NMS)

加载训练数据

boxLabelDatastoreDatastore for bounding box label data
groundTruthGround truth label data
imageDatastore图像数据的数据存储
objectDetectorTrainingDataCreate training data for an object detector
combine合并来自多个数据存储的数据

训练基于特征的目标检测器

trainACFObjectDetectorTrain ACF object detector
trainCascadeObjectDetectorTrain cascade object detector model
trainImageCategoryClassifierTrain an image category classifier

训练基于深度学习的目标检测器

trainSSDObjectDetectorTrain SSD deep learning object detector
trainYOLOv2ObjectDetectorTrain YOLO v2 object detector
trainYOLOv3ObjectDetectorTrain YOLO v3 object detector (自 R2024a 起)
trainYOLOv4ObjectDetectorTrain YOLO v4 object detector (自 R2022a 起)
trainYOLOXObjectDetectorTrain YOLOX object detector (自 R2023b 起)

增强和预处理用于深度学习的训练数据

balanceBoxLabelsBalance bounding box labels for object detection
bboxcropCrop bounding boxes
bboxeraseRemove bounding boxes (自 R2021a 起)
bboxresizeResize bounding boxes
bboxwarpApply geometric transformation to bounding boxes
bbox2pointsConvert rectangle to corner points list
blockLocationsWithROISelect image block locations that contain bounding box ROIs (自 R2025a 起)
imwarp对图像应用几何变换
imcrop裁剪图像
imresize调整图像大小
randomAffine2dCreate randomized 2-D affine transformation
centerCropWindow2dCreate rectangular center cropping window
randomWindow2dRandomly select rectangular region in image (自 R2021a 起)
integralImageCalculate 2-D integral image

R-CNN(基于卷积神经网络的区域)

roiAlignLayerNon-quantized ROI pooling layer for Mask-CNN
roiMaxPooling2dLayerNeural network layer used to output fixed-size feature maps for rectangular ROIs
roialignNon-quantized ROI pooling of dlarray data (自 R2021b 起)

YOLO v2(you only look once 版本 2)

yolov2TransformLayerCreate transform layer for YOLO v2 object detection network
spaceToDepthLayerSpace to depth layer

焦点损失

focalCrossEntropyCompute focal cross-entropy loss

SSD(单次检测器)

ssdMergeLayerCreate SSD merge layer for object detection

锚框

estimateAnchorBoxesEstimate anchor boxes for deep learning object detectors
cuboid2imgProject cuboids from 3-D world coordinates to 2-D image coordinates (自 R2022b 起)
insertObjectAnnotationAnnotate truecolor or grayscale image or video
insertObjectMask Insert masks in image or video stream
insertShapeInsert shapes in image or video
showShapeDisplay shapes on image, video, or point cloud
evaluateObjectDetectionEvaluate object detection data set against ground truth (自 R2023b 起)
objectDetectionMetricsObject detection quality metrics (自 R2023b 起)
mAPObjectDetectionMetricMean average precision (mAP) metric for object detection (自 R2024a 起)
bboxOverlapRatioCompute bounding box overlap ratio
bboxPrecisionRecallCompute bounding box precision and recall against ground truth

模块

Deep Learning Object Detector使用经过训练的深度学习目标检测器检测目标 (自 R2021b 起)

主题

快速入门

用于目标检测和实例分割的训练数据

深度学习快速入门

  • 在 MATLAB 中进行深度学习 (Deep Learning Toolbox)
    通过使用卷积神经网络进行分类和回归来探索 MATLAB® 的深度学习能力,包括预训练网络和迁移学习,以及在 GPU、CPU、集群和云上进行训练。
  • 预训练的深度神经网络 (Deep Learning Toolbox)
    了解如何下载和使用预训练的卷积神经网络进行分类、迁移学习和特征提取。

精选示例