Main Content

resetSequence

Reset video sequence properties for streaming video classification

Since R2021b

Description

classifierReset = resetSequence(classifier) resets the video sequences for classification. classifier is the classifier, specified as a r2plus1dVideoClassifier or slowFastVideoClassifier object.

example

Examples

collapse all

This example shows how to classify two different video sequences one after the other by reseting the video sequences of the video classifier using the resetSequence function. To learn more about how to train a video classifier network for your dataset, see Gesture Recognition using Videos and Deep Learning.

Load SlowFast Video Classifier

Load the SlowFast Video Classifier pretrained on the Kinetics-400 dataset.

sf = slowFastVideoClassifier();

Classify First Video Sequence

Specify the video file name.

videoFilename = "washingHands.avi";

Create a VideoReader to read the video frames.

reader = VideoReader(videoFilename);

Update the video classifier sequence with video frames before using classifySequence. The required number of frames is defined by the value of the 4th element of InputSize property of the video classifier.

sequenceLength = sf.InputSize(4);

Read a video sequence starting from the first frame.

startSequenceIndex = 1;
sequenceRange = [startSequenceIndex, startSequenceIndex + sequenceLength - 1];

Update the video classifier sequence with video frames.

for ii = sequenceRange
    videoFrame = read(reader, ii);
    sf = updateSequence(sf,videoFrame);
end

Classify the video sequence updated so far.

[label1, score1] = classifySequence(sf)
label1 = categorical
     washing hands 

score1 = single
    0.0031

Display the classified label.

player = vision.VideoPlayer('Name','Washing Hands');
for ii = sequenceRange    
    frame = read(reader,ii);
    % Resize the frame by 1.5 times for display
    frame = imresize(frame,1.5);
    frame = insertText(frame,[2,2], string(label1),'FontSize',18);
    step(player,frame);
end

Classify Second Video Sequence

Reset the video sequence of the video classifier without creating a new video classifier.

sf = resetSequence(sf);

Specify another video file to classify.

videoFilename = "vipmen.avi";

Create a VideoReader to read the video frames.

reader = VideoReader(videoFilename);

Read a video sequence starting from the 131st frame, where the "shaking hands" action begins.

startSequenceIndex = 131;
sequenceRange = [startSequenceIndex, startSequenceIndex + sequenceLength - 1];

Classify the second video sequence.

for ii = sequenceRange    
    videoFrame = read(reader,ii);
    sf = updateSequence(sf,frame);
end

[label2, score2] = classifySequence(sf)
label2 = categorical
     shaking hands 

score2 = single
    0.0039

Display the classified label.

player = vision.VideoPlayer('Name','Shaking Hands');
for ii = sequenceRange    
    frame = read(reader,ii);
    % Resize the frame by 4 times for display
    frame = imresize(frame, 4);
    frame = insertText(frame,[2,2], string(label2),'FontSize',18);
    step(player,frame);
end 

Input Arguments

collapse all

Classifier, specified as a r2plus1dVideoClassifier or slowFastVideoClassifier object.

Output Arguments

collapse all

Reset video classifier, returned as a r2plus1dVideoClassifier or slowFastVideoClassifier object.

Version History

Introduced in R2021b