Show a Video Stream from a Camera

Updated: April 19, 2023

You can use the Camera library to show a video stream (image buffers) from a live camera or file camera. This section shows you the basic workflow for doing so.

One important thing to mention is that our Camera library examples use the Screen Graphics Subsystem to show the image buffers from the camera on a display. (You don't need Screen if you don't want to do this.) To understand our examples, you should have a basic understanding of how to set up Screen to handle image buffers from the Camera library and show them on a display. You can access the image buffers and process them using either event mode or callback mode.

These are the steps that an application must do to show the image buffers from a camera on a display:
  1. Connect to the camera. You must connect to the camera to a get a valid handle to work with the Camera API.
  2. Set the viewfinder mode for the camera. We recommend that you set the viewfinder mode before you set any configuration settings on the camera. If you don't, any previous configuration settings are lost because setting the viewfinder mode resets the camera's configuration to its default values for the viewfinder.
  3. Connect Screen with the Camera API. Screen is required to show the video from the camera on a display. You must do some initial setup to connect Screen with the Camera API.
  4. Start the viewfinder and configure camera settings. You can then start processing the imaging datapath from the camera. You can set viewfinder settings (e.g., rotation, height, and width) and image attributes (e.g., contrast and hue). Often, this is necessary in order to provide the correct settings for your camera. For example, a camera may use YCbYCr as the default frame format, but you could change it to use RGB8888, provided that format is supported on the camera.
  5. Use Screen to show the viewfinder window. In this step, you catch the Screen Create event to get access to the viewfinder window and then use the Screen API to show the viewfinder window on the display.
  6. Stop the viewfinder. You can stop the viewfinder to stop the image buffers from streaming. You don't need to disconnect from (close) the camera until you are done using it. For example, you can stop and then start the viewfinder again.
The previous steps describe the basic workflow for using the Camera API. See the following sections for some more advanced tasks you can do with the API: