Main Content

readFrame

Return oldest image frame from board, web, or ArduCam module camera

Add-On Required: This feature requires the MATLAB Support Package for Raspberry Pi Hardware add-on.

Description

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

[data,ts] = readFrame(cameraboardObj) also returns the timestamp of the oldest 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,count) also returns the timestamps corresponding to each image 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,ts] = readFrame(webcamObj) also returns the timestamp of the oldest 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,count) also returns the timestamps corresponding to each image frame.

data = readFrame(aCamObj) returns the oldest RGB image frame from the selected camera on ArduCam Multi Camera Adapter Module as a 3-D array.

[data,ts] = readFrame(aCamObj) also returns the timestamp of the oldest image.

data = readFrame(aCamObj,count) returns multiple RGB image frames, as obtained from the selected camera attached to the ArduCam Multi Camera Adapter Module, 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(aCamObj,count) also returns the timestamps corresponding to each image frame.

Examples

collapse all

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® to the Raspberry Pi board. If you encounter errors after running the above command, try using additional arguments (as listed in raspi) or refer to Troubleshoot Connecting Issues to 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 with the corresponding timestamps.

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

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);

Create a connection from the MATLAB to the Raspberry Pi board. If you encounter errors after running the above command, try using additional arguments (as listed in raspi) or refer to Troubleshoot Connecting Issues to Raspberry Pi Hardware.

mypi = raspi;

Create a connection from MATLAB to the ArduCam module attached to the Raspberry Pi board. Set the image resolution. The connection displays the ArduCam properties.

aCamObj = arducam(mypi,"MultiCamAdapter","Resolution","1280x720")
aCamObj = 

ArduCam with Properties:

              ModuleName: "Multi Camera Adapter"  
          SelectedCamera: "Camera A" 
              Resolution: "1280x720"       (View available resolutions)
               Recording: 0              

Obtain 10 images with the corresponding timestamps.

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

Input Arguments

collapse all

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

Example: mycam

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

Example: mycam

Connection to a camera on the ArduCam Multi Camera Adapter Module, specified as an arducam object.

Example: myarducam

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 the RGB images, returned as N-by-1 matrix, where n is the value specified in count.

Extended Capabilities