Main Content

readFrame

Read older image frame(s) from Raspberry Pi camera board or USB web camera

Description

data = readFrame(cameraboardObj) returns the oldest RGB image frame, as obtained from the Raspberry Pi™ camera board, as a 3-D image.

data = readFrame(cameraboardObj,count) returns multiple RGB image frames, as obtained from the Raspberry Pi camera board, as a 4-D array. The count value specifies the number of frames, with a maximum allowed value of 10. The oldest image is returned first. If count = 1, the function returns a 3-D image.

[data,ts] = readFrame(cameraboardObj) returns the oldest RGB image frame, as obtained from the Raspberry Pi camera board, as a 3-D image along with the timestamp. ts is the timestamp corresponding to the frame.

[data,ts] = readFrame(cameraboardObj,count) returns multiple RGB image frames, as obtained from the Raspberry Pi camera board, as a 4-D array along with the timestamps. The count value specifies the number of frames, with a maximum allowed value of 10. The oldest image is returned first. ts is the timestamp corresponding to each frame.

data = readFrame(webcamObj) returns the oldest RGB image frame, as obtained from the web camera attached to the Raspberry Pi board, as a 3-D image.

data = readFrame(webcamObj,count) returns multiple RGB image frames, as obtained from the web camera attached to the Raspberry Pi board, as a 4-D array. The count value specifies the number of frames, with a maximum allowed value of 10. The oldest image is returned first. If count = 1, the function returns a 3-D image.

[data,ts] = readFrame(webcamObj) returns the oldest RGB image frame, as obtained from the web camera attached to the Raspberry Pi camera board, as a 3-D image along with the timestamp. ts is the timestamp corresponding to the frame.

[data,ts] = readFrame(webcamObj,count) returns multiple RGB image frames, as obtained from the web camera attached to the Raspberry Pi board, as a 4-D array along with the timestamps. The count value specifies the number of frames, with a maximum allowed value of 10. The oldest image is returned first. ts is the timestamp corresponding to each frame.

Examples

collapse all

You can connect to the camera board on the Raspberry Pi hardware, from the MATLAB® software, and read up to a maximum of 10 different images with the oldest image being returned first.

Connect the Raspberry Pi to your host computer.

Note

If you have not previously configured your Raspberry Pi, see Install Support for Raspberry Pi Hardware.

Create a connection from the MATLAB software to the Raspberry Pi hardware.

mypi = raspi

Create a connection, mycam, from the MATLAB software to the camera board on the Raspberry Pi hardware, and set the image resolution. The connection displays the camera board properties.

mycam = cameraboard(mypi,'Resolution','1280x720')
mycam = 

Cameraboard with Properties:

                    Name: Camera Board   
              Resolution: '1280x720'       (View available resolutions)
                 Quality: 10              (1 to 100)
                Rotation: 0               (0, 90, 180 or 270)
          HorizontalFlip: 0              
            VerticalFlip: 0              
               FrameRate: 30              (2 to 30)
               Recording: 0              

   Picture Settings
              Brightness: 50              (0 to 100)
                Contrast: 0               (-100 to 100)
              Saturation: 0               (-100 to 100)
               Sharpness: 0               (-100 to 100)

   Exposure and AWB
            ExposureMode: 'auto'          (View available exposure modes)
    ExposureCompensation: 0               (-10 to 10)
                 AWBMode: 'auto'          (View available AWB modes)
            MeteringMode: 'average'       (View available metering modes)

   Effects
             ImageEffect: 'none'          (View available image effects)
      VideoStabilization: 'off'          
                     ROI: [0.00 0.00 1.00 1.00] (0.0 to 1.0 [top, left, width, height])

Obtain 10 images as a 4-D array with the corresponding timestamp, with the oldest image being returned first.

[imagedata,ts] = readFrame(mycam,10);

You can connect to the USB web camera, which is connected to Raspberry Pi board, from the MATLAB software, and read up to a maximum of 10 different images with the oldest image being returned first.

Connect the Raspberry Pi to your host computer.

Note

If you have not previously configured your Raspberry Pi, see Install Support for Raspberry Pi Hardware.

Create a connection from the MATLAB software to the Raspberry Pi hardware.

mypi = raspi

Create a connection, wcam, from the MATLAB software to the USB web camera connected to Raspberry Pi board, and set the image resolution. The connection displays the web camera properties.

wcam = webcam(mypi)
wcam = 

  webcam with properties:

                    Name: '/dev/video0'
              Resolution: '320x240'
    AvailableResolutions: {'320x240'  '640x480'}

Obtain 10 images as a 4-D array with the corresponding timestamp, with the oldest image being returned first.

[imagedata,ts] = readFrame(wcam,10);

Input Arguments

collapse all

Connection to camera board on the Raspberry Pi hardware, specified as a cameraboard object.

Use the cameraboard function to create this connection.

Example: mycam

Connection to a USB web camera connected to Raspberry Pi board, specified as a webcam object.

Use the webcam function to create this connection.

Example: mycam

Number of frames to be considered for obtaining the 4-D array of RGB images. The maximum value of count is 10.

Data Types: double

Output Arguments

collapse all

4-D array of RGB images, returned as RGB-by-n matrix of values, where n is the value specified as count. If count = 1, data is the 3-D image frame.

Data Types: uint8

Timestamp of RGB images, returned as n-by-1 matrix of values, where n is the value specified as count.

Extended Capabilities