Get Started with Computer Vision Applications Using Android Device
This example shows how to use the Simulink® Support Package for Android® Devices to get started with computer vision applications on Android devices. The example also helps you get accustomed with the Android device driver blocks such as Camera and Video Display.
Prerequisites
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.
Required Hardware
Android device such as a phone or tablet
USB cable
Hardware Setup
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
Open the androidVisionGettingStarted
Simulink model.
Simulation Sources
An image is given as an input to the Simulation Image subsystem where its R, G, and B values are combined into a single matrix and further given as an input to the Algorithm area.
To change the input image in the Simulation Image subsystem, on the Modeling tab of the Simulink model, in the Design section, click Model Explorer.
In the Model Explorer window, in the Model Hierarchy pane, select the name of the Simulink model and expand the down arrow. Select Model Workspace.
In the Content of: Model Workspace pane, select RGB_image.
In the Data properties: RGB_image pane, enter the path of the simulation input image in this format:
imresize(imread('Your own image path\image.jpg'), [resize value]);
. For example,imresize(imread(matlabroot,'C:\Users\Pictures\image021.jpg'), [384, 512, 3]);
.Click Apply and close the window.
Android Inputs
Use the Camera block to capture video using your Android device. This block is configured to its default parameters. The R, G, and B components of the video are concatenated into a single image matrix and further given as an input to the Algorithm area.
Display and Visualization
The image_display
function in the MATLAB Function block displays the input image fed through the Simulation Sources area.
Android Outputs
In the deployment mode, use the Video Display block to display the output image on your Android device.
Run Simulink Model
In the Algorithm area of the Simulink model, position the Manual Switch to receive output from the Simulation Sources area.
On the Simulation tab of the Simulink model, click Run. Observe the simulation output on the figure window.
Deploy Simulink Model on Android Device
1. In the Algorithm area of the Simulink model, position the Manual Switch to receive output from the Simulation Sources area.
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 androidVisionGettingStarted application launches automatically on your Android device. On the App tab of the application, observe the input image that you set in the Model Explorer window.
1. In the Algorithm area of the Simulink model, position the Manual Switch to receive output from the Android Inputs area.
2. Redeploy the Simulink model on your Android device. On the App tab of the application, observe the live camera feed output on your Android device.