Main Content

Detect Stop Signal Traffic Sign Using Android Device

This example shows how to use the Simulink® Support Package for Android® Devices to detect a stop signal traffic sign using an Android device. The example uses a cascade object detector to detect a stop sign using the Viola-Jones algorithm.

Prerequisites

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.

Train Stop Sign Detector

To set up and train a stop-sign detector, load a sample data from a MAT file. In this example, stopSignsAndCars.mat file is used for training purpose. The output from training the cascade object detector is an XML file. For more information, see Get Started with Cascade Object Detector (Computer Vision Toolbox).

In the MATLAB® Command Window, run and execute the steps as mentioned in the Train Stop Sign Detector (Computer Vision Toolbox) section. After you complete executing the steps, a figure window opens with a bounding box drawn around the stop-sign.

Observe that the stopSignDetector.xml file is created in the current working folder of your MATLAB session.

Configure Simulink Model and Calibrate Parameters

Open the androidVisionCascadeObjDetector Simulink model.

For more information on Simulation Sources, Android Inputs, Display and Visualization, and Android Outputs area, see Get Started with Computer Vision Applications Using Android Device.

Algorithm

The function inside the MATLAB Function block uses the vision.CascadeObjectDetector (Computer Vision Toolbox) function to train the cascade object detector. While simulating or deploying the model on your Android device, enter the path location of the stopSignDetector.xml file as an input argument to the function.

Run Simulink Model

1. In the Algorithm area, position the Manual Switch to receive output from the Simulation Sources area.

2. Open the MATLAB Function block in the Algorithm area. Enter the path location of the stopSignDetector.xml file. For example, if the stopSignDetector.xml file is present in the current working directory of MATLAB, enter

detector = vision.CascadeObjectDetector('stopSignDetector.xml');

3. On the Simulation tab of the Simulink model, click Run. Observe the simulation output on the figure window.

Deploy Simulink Model

1. In the Algorithm area of the Simulink model, position the Manual Switch to receive output from the Android Inputs area.

2. Open the MATLAB Function block in the Algorithm area. Enter the path location of the SD card to deploy the stopSignDetector.xml file on your Android device. For example, if you want to save the stopSignDetector.xml file in folder123 of the SD card on your Android device, enter

detector = vision.CascadeObjectDetector('/sdcard/folder123/stopSignDetector.xml');

3. 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 androidVisionCascadeObjDetector application launches automatically on your Android device.

4. Point the camera of your Android device towards a stop sign traffic signal. Observe a bounding box around the stop sign.

See Also