主要内容

标记对象的自动属性

此示例显示了如何开发车辆检测和距离估计算法并使用它来自动使用标签地面真相标签应用程序。在此示例中,您将学习如何:

  • 开发一种计算机视觉算法来检测视频中的车辆,并使用单眼摄像头配置估算到检测到的车辆的距离。

  • 使用AutomationsgorithmAPI创建自动化算法。看Create Automation Algorithm for Labeling有关详细信息。创建的自动化算法可以与地面真相标签应用程序一起使用,以自动标记车辆,以及存储估计距离的属性。

地面真相标签应用

良好的地面真相数据对于开发驱动算法和评估其性能至关重要。但是,创建丰富而多样化的带注释的驾驶数据需要大量精力。这地面真相标签应用使得这个过程有效。你可以使用这个app as a fully manual labeling tool to mark vehicle bounding boxes, lane boundaries, and other objects of interest for an automated driving system. You can also manually specify attributes of the labeled objects. However, manual labeling requires a significant amount of time and resources. As an alternative, this app provides a framework for creating algorithms to extend and automate the labeling process. You can use the algorithms you create to quickly label entire data sets, automatically annotate the labels with attributes, and then follow it up with a more efficient, shorter manual verification step. You can also edit the results of the automation step to account for challenging scenarios that the automation algorithm might have missed.

本示例介绍了如何将车辆检测和距离估计自动化算法插入应用程序的自动化工作流程。这个示例重复了ACF车辆检测自动化算法首先检测到车辆,然后自动估计从安装在自我车辆上的相机中检测到的车辆的距离。然后,该算法为每个检测到的车辆创建一个标签,并具有指定与车辆距离的属性。

从单眼相机检测车辆

首先,创建一种车辆检测算法。这使用单眼相机的视觉感知example describes how to create a pretrained vehicle detector and configure it to detect vehicle bounding boxes using the calibrated monocular camera configuration. To detect vehicles, try out the algorithm on a single video frame.

%从视频中读取感兴趣的框架。vidobj = videoreader('05_highway_lanechange_25s.mp4');vidObj.CurrentTime = 0.1; I = readFrame(vidObj);%加载单层对象。数据=负载('FCWDemoMonoCameraSensor.mat',,,,'传感器');传感器= data.sensor;%为车辆的验证探测器加载。检测器= vericleDetectorAcf();普通车的宽度%在1.5至2.5米之间。车辆宽度= [1.5,2.5];%配置检测器以考虑相机的配置%和预期的车辆宽度detector = configureDetectorMonoCamera(detector, sensor, vehicleWidth);%检测车辆并显示边界框。[bboxes,〜] =检测(检测器,i);iout = insertshape(i,'rectangle',bboxes);数字;imshow(iout)标题(“检测到车辆”

图包含一个轴对象。带有标题的车辆的轴对象包含类型图像的对象。

估计检测到的车辆的距离

现在已经检测到车辆,估计了世界坐标中摄像头的检测到的车辆的距离。单场提供成像螺旋method to convert points from image coordinates to vehicle coordinates. This can be used to estimate the distance along the ground from the camera to the detected vehicles. The example specifies the distance as the center point of the detected vehicle, along the ground directly below it.

% Find the midpoint for each bounding box in image coordinates.MIDPTSIMG = [bboxes(:,1)+bboxes(:,3)/2 bboxes(::,2)+bboxes(:,4)./ 2];中间世界= ImageTovehicle(传感器,Midptsimg);x = midptworld(:,1);y = midptworld(:,2);距离= sqrt(x。^2 + y。^2);%显示车辆边界盒,并用距离为米的距离注释它们。distancestr = celltr([num2str(distand)repmat('M',[长度(距离)1])]);iout = insertObjectAnnotation(i,'rectangle',bboxes,distancest);imshow(iout)标题('Distances of Vehicles from Camera'

图包含一个轴对象。轴对象具有车辆距离相机的标题距离,其中包含一个类型图像的对象。

Prepare the Vehicle Detection and Distance Estimation Automation Class

将车辆检测和距离估计自动化类别纳入应用程序的自动化工作流程。看Create Automation Algorithm for Labelingfor more details. Start with the existingACF车辆检测自动化算法使用校准的单眼相机执行车辆检测。然后修改算法以执行属性自动化。在此示例中,将车辆与相机的距离用作检测到的车辆的属性。本节介绍了更改现有的ACF车辆检测自动化算法类的步骤。

Step 1 contains properties that define the name and description of the algorithm, and the directions for using the algorithm.

%---------------------------------------------------------------------------------------------- % Define algorithm Name, Description, and UserDirections. properties(Constant)
%名称:算法名称%字符向量指定算法的名称。名称=“车辆检测和距离估计”;
%描述:为您的算法提供单行描述。描述='使用验证的ACF车辆探测器检测车辆,并计算被检测到的车辆与摄像机的距离。';
% UserDirections: Provide a set of directions that are displayed % when this algorithm is invoked. The directions % are to be provided as a cell array of character % vectors, with each element of the cell array % representing a step in the list of directions. UserDirections = {... 'Define a rectangle ROI Label to label vehicles.',... 'For the label definition created, define an Attribute with name Distance, type Numeric Value and default value 0.', ... 'Run the algorithm',... 'Manually inspect and modify results if needed'}; end

步骤2包含支持车辆检测和距离估计自动化所需的自定义属性金宝app

%---------------------------------------------------------------------------------------------------%车辆探测器属性%--------------------------------------------------------------------------------------------- properties %SelectedLabelName Selected label name % Name选定的标签。算法检测到的车辆将分配此变量名称。SelectedLabelName
%检测器检测器%预验证的媒介物检测器,这是类百分比对象的对象。探测器
%vericlemodelname车辆探测器型号名称%名称的车辆探测器型号。VERICLEMODELNAME ='FULL-VIEW';
用于消除参考边界框周围重叠的边界框%的重叠重叠阈值%阈值的重叠重叠阈值阈值值,在0到1之间。%边界框重叠比率分母“ Ratoiotype”设置为“ ratiotype''设置为“ min”“ min”'min'rproplapthrapthrapthrapthrapthrapthrapthrapthrapthrapthreshord = 0.65;
%ScoreThreshold Classification Score Threshold % Threshold value used to reject detections with low detection % scores. ScoreThreshold = 30;
%configuretector boolean值决定配置检测器%布尔值,该值决定是否使用%monocamera传感器配置检测器。configuredetector = true;
%SensorObj单体传感器%单眼相机传感器对象用于配置检测器。%一个配置的检测器将运行速度更快,并且可能会导致更好的检测。SensorObj = [];
%Sensorsstr MonoCamera传感器变量名称%单眼相机传感器对象变量名称用于配置%检测器。sensorstr ='';
%车辆宽度的车辆宽度%的车辆宽度用于配置检测器,指定为%[minwidth,maxwidth],描述了世界单位中%对象的近似宽度。车辆宽度= [1.5 2.5];
%车辆长度的车辆长度%用于配置检测器的车辆长度,指定为%[最小值,最大长度],描述了世界单位中%对象的近似长度。VERICLELTENG = [];结尾
%---------------------------------------------------------------------------------------------------%属性自动化属性%-------------------------------------------------------------------------------------------------------------属性(常数,访问=私有)
%标志以启用距离属性估计自动化自动化tribute = true;
%支金宝app持的距离属性名称。%标签必须具有指定名称的属性。金宝app支持distanceatTribName ='dange';结尾
属性(访问=私有)
% Actual attribute name for distance DistanceAttributeName;
%标志要检查指定的属性是有效的距离%属性hasvaliddistanceatTribute = false;结尾

步骤3初始化属性。

%-------------------------------------------------------------------------------------------------%初始化传感器,检测器和其他相关属性。功能初始化(algobj,〜)
% Store the name of the selected label definition. Use this % name to label the detected vehicles. algObj.SelectedLabelName = algObj.SelectedLabelDefinitions.Name;
%通过验证模型初始化车辆探测器。algobj.detector = vericleDetectorAcf(algobj.vehiclemodelname);
%初始化参数以计算车辆距离,如果Algobj.AutomateSatanceatTribute InitializeatTributeparams(algobj);结尾
函数初始摄取素(ALGOBJ)%初始化与属性自动化相关的属性。
%标签必须具有具有名称距离的属性和type%数字值。hasAttribute = isfield(algobj.validlabeldefinitions,'属性')&& ... isStrint(algobj.validlabeldefinitions.attributes);如果hasAttribute attributeNames = fieldNames(algobj.validlabeldefinitions.attributes);idx = find(contains(attributeNames,algobj.s金宝appupportedDistanceAttribName));如果〜isempty(idx)algobj.distanceatTributeName = attributeNames {idx};algobj.hasvaliddistanceatTribute =验证istanceType(algobj);端端
函数tf =验证的cistanceType(algobj)%验证属性类型。
tf = isfield(algobj.validlabeldefinitions.attributes,algobj.distanceattributename)&& ... isfield(algobj.validlabeldefinitions.attributess.attributes.(algobj.distanceattributename).distanceatTributeName).defaultValue);结尾

步骤4包含更新的计算检测到的汽车的距离并将标签和属性信息写入输出标签的方法。

%---------------------------------------------------------------------------------------------- function autoLabels = run(algObj, I)
autoLabels = [];
%配置检测器。如果algobj.configuredEtector && 〜ISA(algobj.detector,'acfobjectDetectormonocamera')perainiclesize = [algobj.vehiclewidth; algobj.vehiclelength];algobj.detector = configuredetectortormonocamera(algobj.detector,algobj.sensorobj,perhiclesize);结尾
%使用初始化的车辆探测器检测车辆。[bboxes,分数] =检测(algobj.detector,i,...'selectstrongest',false);
[SelectedBbox,SelectedScore] = selectstrongestbbox(bbox,得分,...'ratiotype','min','min','offlapthreshold',algobj.overlapthrapthreshold);
% Reject detections with detection score lower than % ScoreThreshold. detectionsToKeepIdx = (selectedScore > algObj.ScoreThreshold); selectedBbox = selectedBbox(detectionsToKeepIdx,:);
如果〜ISEMPTY(selectionBbox)%在车辆检测器检测到%的边界框位置中添加自动标签,则具有所选标签名称的矩形类型。autolabels.name = algobj.SelectedLabelName;autolabels.type = labelType.Rectangle;autolabels.position = SelectedBbox;
if(algobj.automatedistanceatTribute && algobj.hasvaliddistanceatTribute)attribname = algobj.distanceatTributeName;%属性值是类型的“数字值” autolabels.attributes = ComputeVehicleDistances(Algobj,selectedbbox,attribName);结束否则自动标记= [];结尾
函数中间= helperfindBottommidpoint(Bboxes)%找到边界框底部边缘的中点。
xbl = bboxes(:,1);ybl = bboxes(:,2);
xm = xbl + bboxes(:,3)/2;ym = ybl + + bboxes(:,4)./ 2;中间= [xm ym];
结尾
函数距离=计算固定(algobj,bboxes)%辅助功能以计算车辆距离。
Midpts = HelperFindBottOmmidPoint(Bboxes);xy = algobj.sensorobj.imagetovehicle(中间);距离= sqrt(xy(:,1)。^2 + xy(:,2)。^2);
结尾
function attribS = computeVehicleDistances(algObj, bboxes, attribName) % Compute vehicle distance.
numcars = size(bboxes,1);attribs = repmat(struct(attribname,0),[numcars,1]);
对于i = 1:numcars distainval = computistances(algobj,bboxes(i,:));attribs(i)。(attribName)= dectionVal;结尾

在应用程序中使用车辆检测和距离估计自动化类

车辆距离计算算法的包装版本可在车辆DetectionAndDistanceEstimation班级。在应用程序中使用此类:

  • Create the folder structure required under the current folder, and copy the automation class into it.

mkdir('+vision/+labeler'); copyfile(fullfile(matlabroot,'examples','driving','main','VehicleDetectionAndDistanceEstimation.m'),'+vision/+labeler');
  • 加载单场information into the workspace. This camera sensor information is suitable for the camera used in the video used in this example,05_highway_lanechange_25s.mp4。如果您加载了其他视频,请使用适合该视频的传感器信息。

负载('FCWDEMOMONOCAMERASENSENSOR.MAT',“传感器”)
  • 打开groundTruthLabeler应用程序。

groundTruthLabeler 05_highway_lanechange_25s.mp4
  • 在里面ROI标签定义左边的窗格,单击标签。Define a label with name车辆和类型长方形。可选,添加标签描述。然后单击好的

  • 在里面ROI标签定义左边的窗格,单击属性。定义名称的属性距离, 类型数值和默认值0。可选,添加属性描述。然后单击好的

  • 选择算法>选择算法>刷新列表

  • 选择Algorithm > Vehicle Detection and Distance Estimation。如果您看不到此选项,请确保当前的工作文件夹具有一个名为的文件夹+vision/+labeler,带有名称的文件车辆DetectionAndDistanceEstimation.m在里面。

  • 点击自动化。打开一个新的选项卡,显示用于使用算法的方向。

  • 点击设置,,,,and in the dialog box that opens, enter传感器在第一个文本框中。在需要之前修改其他参数(如果需要)好的

  • 点击。车辆检测和距离计算算法通过视频进行。请注意,在某些框架中,结果并不令人满意。

  • 运行完成后,使用滑块或箭头键在视频上滚动滚动以找到算法失败的帧。

  • 通过移动车辆边界框或更改距离值来手动调整结果。您还可以删除边界框和关联的距离值。

  • 一旦您对车辆边界框及其整个视频的距离感到满意,请单击接受

视频上的自动化车辆检测和距离属性标签已完成。现在,您可以标记其他感兴趣的对象,并设置其属性,保存会话或导出此标签运行的结果。

结论

此示例显示了将车辆检测和距离属性估计自动化算法纳入到该算法的步骤地面真相标签应用程序。您可以将此概念扩展到其他自定义算法以扩展应用程序的功能。

也可以看看

应用

对象

相关话题