Video Labeler App and exporting the data

12 views (last 30 days)
Martine Banville
Martine Banville on 16 Jun 2020
Edited: Martine Banville on 19 Jun 2020
Hi there,
I have been using the App Video Labeler to track objects. So I created ROI for various features but I am having a hard time exporting this data so that I can use it outside the App. Attached is an example of a short video where I have tracked 2 things (using rectangle ROI) and I also created an horizontal line (using a ROI line) but I now want to export that data to further calculate the trajectory, maybe the angle of the line with respect to the bottom of the photo, etc... but once I export the groundTruth data using the Export Labels + to File, I don't understand how I can use the groundTruth exported labels to use elsewhere. Can I get the x,y coordinate for each object for each frame? If so how do I access that? Can I get the line equation?
Anyway I have been searching the help but I find it very basic and can not make sense of all this. Does anyone have concret examples to share? Does anyone have any useful tutorial? I also tried with pixel labeler using Video Labeler and I was able to generate a movie of the pixel label but unable to extract separately each object from the movie.
Attached is an example of a movie with the exported data from the Video Labeler App. At this point anything would help! Thank you.

Answers (1)

Harsha Priya Daggubati
Harsha Priya Daggubati on 19 Jun 2020
Hi,
I can answer a part of your question, to my understanding you can get the 'position' of the object labelled by bounding boxes from 'gTruth' in MATLAB Workspace as follows:
You might know, that ground truth exported to MATLAB Workspace from Video Labeler App, is a structure with 3 fields: DataSource, Label Definitions, Label Data. You can get the position of every bounding box using Label Data field. You can work as follows:
labelData = gTruth.labelData;
head(labelData)
gTruthInterval(1,:).Car{1}.Position % [x y width height], in pixels
The code above helps you get x, y coordinates of an object.
  1 Comment
Martine Banville
Martine Banville on 19 Jun 2020
Edited: Martine Banville on 19 Jun 2020
Thank you I was finally able to get the gTruth data that I required using the following commands:
gTruth = selectLabels(gTruth,'Roof');
% This creates another gTruth but with the isolated variable 'Roof' in this case.
or
for i=1:NumberofFrames
C = gTruth.LabelData.Roof{i,1};
...
end
% This allow me to get access to the data from Label 'Roof' in this case for each frame.
However now I am having difficulty reading the pixel label data. I am using this code to retrieve all the label for each frame and later generating a video with only the label data:
Img = zeros(VideoHeight,VideoWidth,3,NumberofFrames); % Create a matrix of Black Frames
labelIDs = [1,2];
labelcats = ["Aircraft" "FOD"];
for i=1:NumberofFrames %Looping though each Pixel Label Frame
formatSpec = 'Label_%d.png';
str = sprintf(formatSpec,i);
LabelImageFile = fullfile(LabelDir,str);
% Here since the Pixel Label Data might not be available for a particular
% frame due to the fact that some frame have no data (nothing was tagged in
% certain frame) I decided to generate a black image when this occurs.
if exist(LabelImageFile,'File') == 0 % If Label file does not exist generate a black image
Img(:,:,1,i) = zeros(VideoHeight,VideoWidth);
Img(:,:,2,i) = zeros(VideoHeight,VideoWidth);
Img(:,:,3,i) = zeros(VideoHeight,VideoWidth);
else
Label = imread(LabelImageFile); % If Label exist use the generated Label
LabelCats = categorical(Label,labelIDs,labelcats); % Construct a categorical matrix
% using the image and the definitions.
Img(:,:,:,i) = labeloverlay(Img(:,:,:,i),LabelCats); % This overlays all the pixel data
% onto the one frame
end
end
So the above code works ok. It is probably not very efficient but this is the way I came up with for now. So my problem is that I don't have a good understanding of how to separate each label. What if I don't want to overlay all the label in one frame. Now I am using the 'labeloverlay' function but if I would want to only select one label how can I do so?
Is there a command to change the color of a particular label to a given color i.e. pure Red or pure Blue? I was unable to change the colors in the Video Label app.
If I could isolate one particular label per frame I could then turn it into a bw image and do some use some morphological processing to later use the function 'regionprops' to get some statistics of what I am tracking.
Thank you

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!