resetSequence
Reset video and optical flow sequence properties for streaming video classification
Since R2021b
Description
resets the video and optical flow sequences for classification. i3dReset
= resetSequence(i3d
) i3d
is
the classifier, specified as an inflated3dVideoClassifier
object.
Examples
Classify Two Videos Using a Video Classifier
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 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
i3d
— Classifier
inflated3dVideoClassifier
object
Classifier, specified as an inflated3dVideoClassifier
object.
Output Arguments
i3dReset
— Reset video classifier
inflated3dVideoClassifier
object
Reset video classifier, returned as an inflated3dVideoClassifier
object.
Version History
Introduced in R2021b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)