
MATLAB Code For Video Pattern Matching
by admin in Computer Vision System , Image Processing and Computer Vision , MATLAB Family on July 26, 2020This code shows how to use the 2-D normalized cross-correlation for pattern matching and target tracking. The code uses predefined or user specified target and number of similar targets to be tracked. The normalized cross correlation plot shows that when the value exceeds the set threshold, the target is identified.
Introduction:
In this code you use normalized cross correlation to track a target pattern in a video. The pattern matching algorithm involves the following steps:
- The input video frame and the template are reduced in size to minimize the amount of computation required by the matching algorithm.
- Normalized cross correlation, in the frequency domain, is used to find a template in the video frame.
- The location of the pattern is determined by finding the maximum cross correlation value.
Initialize Parameters and Create a Template:
Initialize required variables such as the threshold value for the cross correlation and the decomposition level for Gaussian Pyramid decomposition.
threshold = single(0.99); level = 2;
Prepare a video file reader.
hVideoSrc = VideoReader('vipboard.mp4');
Specify the target image and number of similar targets to be tracked. By default, the example uses a predefined target and finds up to 2 similar patterns. You can set the variable useDefaultTarget to false to specify a new target and the number of similar targets to match.
Create a System object to calculate the local maximum value for the normalized cross correlation.
Create a System object to display the tracking of the pattern.
sz = get(0,'ScreenSize'); pos = [20 sz(4)-400 400 300]; hROIPattern = vision.VideoPlayer('Name', 'Overlay the ROI on the target', ... 'Position', pos);
Initialize figure window for plotting the normalized cross correlation value
hPlot = videopatternplots('setup',numberOfTargets, threshold);
Search for a Template in Video
Create a processing loop to perform pattern matching on the input video. This loop uses the System objects you instantiated above. The loop is stopped when you reach the end of the input file, which is detected by the VideoReader
object.
Summary:
This code shows use of Computer Vision Toolbox™ to find a user defined pattern in a video and track it. The algorithm is based on normalized frequency domain cross correlation between the target and the image under test. The video player window displays the input video with the identified target locations. Also a figure displays the normalized correlation between the target and the image which is used as a metric to match the target. As can be seen whenever the correlation value exceeds the threshold (indicated by the blue line), the target is identified in the input video and the location is marked by the green bounding box.
See the Video:
Click here.
Recommended For You:
- MATLAB Code For Tracking Pedestrians from a Moving Car
- MATLAB Code For Object Detection in Image of a Cluttered Scene
- Matlab Code For Car Number Plate Recognition System
- Matlab Code for Recognition of License Plate
- Car License Plate Detection Using Morphological Operators
- Car Number Plate Detection Using MATLAB and Image Processing
- Fruit Classification Interactive Program
- MATLAB Code For Reading Car Plate Number
- Matlab Code For Eye Color Detection
- MATLAB Code For Face Recognition Based on Histogram of Oriented Gradients (HOG)
- MATLAB Code For Detecting and Counting Cars Using Gaussian Mixture Models
Codes and Articles:
- Noise Measurement with Matlab
- Resize an Image in Matlab
- Autopilot Model-Based Design for ARP-4754A, DO-178C and DO-331
- Finite Element Gui Matlab, 2d Linear Elements
- Noise Analysis and Measurement of Noise Statistics with Matlab
- MATLAB Code For Object Detection in Image of a Cluttered Scene
- Servo Motor Control using MATLAB
- Aircraft Power Network in Simscape Electrical with AC and DC networks
- Getting Started with MATLAB: A Quick Introduction
- PID Tuning Code using Zeigler-Nicholas Method in MATLAB
Share Now!