This example shows how to use the V4L2 Video Capture and the SDL Video blocks from the Gumstix Overo® block library to implement an image inversion algorithm with a Simulink® model, and to run the model on Gumstix Overo hardware.
|On this page…|
Black and white image inversion refers to an image processing technique where light areas are mapped to dark, and dark areas are mapped to light. In other words, after image inversion black becomes white and white becomes black. An inverted black and white image can be thought of as a digital negative of the original image.
In this example, the inversion algorithm will be applied to the red (R), green (G) and blue (B) components of an image captured from a USB camera creating a color digital negative effect. The R, G and B components of the image are represented as uint8 values. That is, the range of the values that any of the color components can take is from 0 to 255. Assuming that the intensity value at position of the image is , the inversion mapping is defined by .
We recommend completing Getting Started with Gumstix Overo Hardware example.
To run this example you will need the following hardware:
Gumstix Overo hardware
A compatible USB camera
(Optional) To display the output video on an external monitor you will need the following:
A monitor with DVI-D connector
USB mouse and keyboard
In this task, you will connect a USB camera to your Gumstix Overo hardware, and run the image inversion model on Gumstix Overo hardware in External mode. When you run the model in External mode, the image is captured from the USB camera connected to the Gumstix Overo hardware and the results of the image inversion is sent back to the host computer to be displayed by the on SDL Video Display block.
1. Connect a USB camera to a USB port of your Gumstix Overo hardware.
3. In the Simulink model, click on the V4L2 Video Capture block and note the 'Device name' parameter. Execute the following commands on the MATLAB command window to verify the 'Device name' parameter:
h = overo [~, msg] = execute(h,'ls -al /dev/video*')
Typical output will be:
msg = crw-rw---T+ 1 root video 81, 0 Dec 16 14:43 /dev/video0
Make sure that the video device file name displayed above matches to the 'Device name' parameter specified on the V4L2 Video Capture block mask.
4. Select Tools > Run on Target Hardware > Options.... Review the parameters on the page that opens. If you performed a Firmware Update, Board information will be automatically populated with the host name, user name and password of your Gumstix Overo hardware. If you have not performed a Firmware Update or you want to change the board parameters, enter the IP address, user name and password of your Gumstix Overo hardware.
5. In the model, change the Simulation mode on the toolbar to External.
6. In the model, click the Run button on the toolbar to run the model on Gumstix Overo hardware.
7. Observe the display of inverted images on the host computer with the SDL Video Display block.
8. While the model is running, double click on the Constant block and change the Constant value from 255 to 120, for example. Observe the resulting image effect.
9. Press the Stop button on the model to stop model execution.
In this task, you will connect a monitor to Gumstix Overo hardware. The video captured from the USB camera will be inverted by the model running on Gumstix Overo hardware and displayed on the monitor connected to Gumstix Overo hardware.
1. Using an HDMI to DVI-D cable, connect a monitor to the Gumstix Overo hardware. The monitor, once connected, will display the Ubuntu desktop.
2. Connect a USB mouse and a keyboard to the Gumstix Overo hardware's USB ports. Once connected, login to Ubuntu desktop as you would to any Linux® computer. To find out the user name and the password of the board execute the following on the MATLAB command line:
h = overo
You will now configure and run the image inversion model on Gumstix Overo hardware as a standalone application. When you run the model, the image is captured from the USB camera connected to the Gumstix Overo hardware and the results of the image inversion is displayed on the monitor connected to the Gumstix Overo hardware.
4. Select Tools > Run on Target Hardware > Options.... Review the parameters on the page that opens.
5. In the model, click the Deploy To Hardware button on the toolbar to run the model on Gumstix Overo hardware. On the monitor connected to Gumstix Overo hardware, you will see a display of inverted images.
6. Stop the model running on the Gumstix Overo hardware by executing the following on the MATLAB® command line
h = overo; stop(h,'overo_inversion');
Change the model to use a different constant value for each color component. Then, independently change the value of each of the constants to get a wider range of imaging effects.
This example showed a Simulink model implementing an image inversion algorithm. V4L2 Video Capture and the SDL Video Display blocks from the Gumstix Overo library were used to capture and display video data. The example showed how the model may be run in External mode, and as a standalone application on Gumstix Overo hardware.