Stabilize Shaky Video Using Android Device
This example shows how to use the Simulink® Support Package for Android™ Devices to remove the effect of camera motion from a video stream. In the first video frame, the model defines the target to track. It also establishes dynamic search region, whose position is determined by the last known target location. The model only searches for the target within this search region, which reduces the number of computations required to find the target. In each subsequent video frame, the model determines how much the target has moved relative to the previous frame. It uses this information to remove unwanted translational camera movements and generate a stabilized video.
Ensure that you install OpenCV version 4.5.2 from the Hardware Setup window.
For more information on how to use the Simulink Support Package for Android Devices to run a Simulink model on your Android device, see Getting Started with Android Devices.
For more information on how to get started with computer vision applications on your Android device, see Get Started with Computer Vision Applications Using Android Device.
Android device such as a phone or tablet
Connect your Android device to the host computer using the USB cable. Set up your Android device using the Hardware Setup. For more information, see Hardware Setup.
Configure Simulink Model and Calibrate Parameters
This example uses a preconfigured Simulink model from the Simulink Support Package for Android Devices.
To open the Simulink model, run this command in the MATLAB® Command Window.
Estimate Motion Subsystem
The model uses the Template Matching (Computer Vision Toolbox) block to move the target over the search region and compute the sum of absolute differences (SAD) at each location. The location with the lowest SAD value corresponds to the location of the target in the video frame. Based on the location information, the model computes the displacement vector between the target and its original location. The Translate (Computer Vision Toolbox) block in the Stabilization subsystem uses this vector to shift each frame so that the camera motion is removed from the video stream.
To open the this subsystem, click the down arrow on the block.
Display Results Subsystem
The model uses the Resize (Computer Vision Toolbox), Compositing (Computer Vision Toolbox), and Insert Text (Computer Vision Toolbox) blocks to embed the enlarged target and its displacement vector on the original video.
To open the this subsystem, run this command in the MATLAB Command Window.
Deploy Simulink Model
1. Ensure to keep your Android device, that has been configured using the Hardware Setup, connected to your host computer. In the Simulink model, double-click the block to open the Block Parameters dialog box. Click Refresh. Set Resolution to
Back - 320x240.
2. On the Hardware tab of the Simulink model, in the Mode section, click
Run on board. In the Deploy section, click Build, Deploy & Start. The androidVisionStabilize application launches automatically on your Android device.
3. Capture a shaky video of an object. On the App tab of the application, the section on the left shows the original shaky video, while the section on the right shows the stabilized video.
4. On the Dashboard tab of the application, enable Subpixel Estimation and Clip Border. Again, observe the stabilized video output on the application.
Get Started with Computer Vision Applications Using Android Device
Implement Histogram Equalization and Median Filtering on Images Using Android Device
Detect and Match Local Features Between Image Frames Using Android Device