MATLAB Examples

Automatic Ground Truth Generation

This example shows how to automatically generate ground truth information for a video.



Automatic Ground Truth Generation is a technique used to reduce the amount of time that it takes to record ground truth information for media. It involves using a robust object detector or combination of them to automatically detect the location of objects in a frame and label them appropriately.

Often, the user is required to inspect and adjust the results. When this manual validation is required, the process is known as Semi-Automatic Ground Truth Generation.


We are going to use the provided example red buoy detector "ThresholdingObjectDetector" to find the red buoys in each frame of the provided example "buoyRun.avi" video.

We are then going to append the automatically generated ground truth information to a Ground Truth Session so that we can open it in the Ground Truth Labeler.


Load a ground truth session. This one only contains the media "buoyRun.avi" without any ROI's labeled.

load GroundTruthSessionBuoyRun

Confirm that the name of the name of the file in the GTS MediaInfo is the BuoyRun.avi video


Use the provided example function "ThresholdingObjectDetector" to obtain the bounding boxes of red buoys and concatenate onto existing Ground Truth Session

FR = vision.VideoFileReader(GTS.MediaInfo(1).filename);
for FrameIndex = 1:length(GTS.MediaInfo(1).FrameInfo);
    % Acquire next frame in video
    frame = step(FR);
    % Obtain bounding boxes for red buoys in frame
    bboxes = ThresholdingObjectDetector(frame);
    nboxes = size(bboxes,1);
    % Add bounding box and label to Ground Truth Session
    GTS.MediaInfo(1).FrameInfo(FrameIndex).bboxes = [GTS.MediaInfo(1).FrameInfo(FrameIndex).bboxes mat2cell(bboxes,ones(1,nboxes))'];
    GTS.MediaInfo(1).FrameInfo(FrameIndex).labels = [GTS.MediaInfo(1).FrameInfo(FrameIndex).labels mat2cell(repmat('red buoy',nboxes,1),ones(1,nboxes))'];

Save the Ground Truth Session to a .mat file

save GroundTruthSessionBuoyRunLabeled GTS

Open the Ground Truth Session in the app to verify that it has been labeled correctly. Make adjustments as needed.