readFrame - Return oldest image frame from board, web, or ArduCam module
camera - MATLAB ([original](http://www.mathworks.com/help/matlab/supportpkg/readframe.html)) ([raw](?raw))
Return oldest image frame from board, web, or ArduCam module camera
Syntax
Description
[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564) = readFrame([mycamera](#mw%5Fbbe4eeb9-8835-4f17-b5a0-7e9b08fd9b84))
returns the oldest RGB image frame, as obtained from the Raspberry Pi® camera board, as a 3-D image.
[[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564),[ts](#mw%5Fff9b6e55-790f-4671-bab4-e4df51fdf1c3)] = readFrame([mycamera](#mw%5Fbbe4eeb9-8835-4f17-b5a0-7e9b08fd9b84))
also returns the timestamp of the oldest image.
[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564) = readFrame([mycamera](#mw%5Fbbe4eeb9-8835-4f17-b5a0-7e9b08fd9b84),[count](#mw%5Fe645ad70-86ff-4090-8fe6-09fdaa16bbac))
returns multiple RGB image frames, as obtained from the Raspberry Pi camera board, as a 4-D array. Thecount
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](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564),[ts](#mw%5Fff9b6e55-790f-4671-bab4-e4df51fdf1c3)] = readFrame([mycamera](#mw%5Fbbe4eeb9-8835-4f17-b5a0-7e9b08fd9b84),[count](#mw%5Fe645ad70-86ff-4090-8fe6-09fdaa16bbac))
also returns the timestamps corresponding to each image frame.
[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564) = readFrame([wcam](#mw%5F41c1029d-8e1e-49fd-9198-7edc55746f2f))
returns the oldest RGB image frame, as obtained from the web camera attached to the Raspberry Pi board, as a 3-D image.
[[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564),[ts](#mw%5Fff9b6e55-790f-4671-bab4-e4df51fdf1c3)] = readFrame([wcam](#mw%5F41c1029d-8e1e-49fd-9198-7edc55746f2f))
also returns the timestamp of the oldest image.
[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564) = readFrame([wcam](#mw%5F41c1029d-8e1e-49fd-9198-7edc55746f2f),[count](#mw%5Fe645ad70-86ff-4090-8fe6-09fdaa16bbac))
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. Ifcount
= 1
, the function returns a 3-D image.
[[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564),[ts](#mw%5Fff9b6e55-790f-4671-bab4-e4df51fdf1c3)] = readFrame([wcam](#mw%5F41c1029d-8e1e-49fd-9198-7edc55746f2f),[count](#mw%5Fe645ad70-86ff-4090-8fe6-09fdaa16bbac))
also returns the timestamps corresponding to each image frame.
[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564) = readFrame([aCamObj](#mw%5Ff0b24922-67b2-4f43-884b-5c048f2cca73))
returns the oldest RGB image frame from the selected camera on ArduCam Multi Camera Adapter Module as a 3-D array.
[[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564),[ts](#mw%5Fff9b6e55-790f-4671-bab4-e4df51fdf1c3)] = readFrame([aCamObj](#mw%5Ff0b24922-67b2-4f43-884b-5c048f2cca73))
also returns the timestamp of the oldest image.
[data](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564) = readFrame([aCamObj](#mw%5Ff0b24922-67b2-4f43-884b-5c048f2cca73),[count](#mw%5Fe645ad70-86ff-4090-8fe6-09fdaa16bbac))
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](#mw%5F6c13cb7b-2ac6-4644-b713-f4d14f417564),[ts](#mw%5Fff9b6e55-790f-4671-bab4-e4df51fdf1c3)] = readFrame([aCamObj](#mw%5Ff0b24922-67b2-4f43-884b-5c048f2cca73),[count](#mw%5Fe645ad70-86ff-4090-8fe6-09fdaa16bbac))
also returns the timestamps corresponding to each image frame.
Examples
Connect the Raspberry Pi to your host computer.
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.
Create a connection,mycamera
, 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.
mycamera = cameraboard(mypi,"Resolution","1280x720");
mycamera =
Cameraboard with Properties:
Name: Camera Board
Resolution: "1280x720" (View available resolutions)
Quality: 10 (1 to 100)
Rotation: 0 (0 or 180)
HorizontalFlip: 0
VerticalFlip: 0
FrameRate: 30 (2 to 90)
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: "normal" (View available exposure modes) ExposureCompensation: 0 (-10 to 10) AWBMode: "indoor" (View available AWB modes) MeteringMode: "average" (View available metering modes)
Effects 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(mycamera,10);
Connect the Raspberry Pi to your host computer.
Create a connection from the MATLAB software to the Raspberry Pi hardware.
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 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.
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
Connection to camera board on the Raspberry Pi hardware, specified as acameraboard
object.
Example: mycamera
Connection to a USB web camera connected to Raspberry Pi board, specified as awebcam
object.
Example: wcam
Connection to a camera on the ArduCam Multi Camera Adapter Module, specified as anarducam
object.
Example: aCamObj
Number of frames to be considered for obtaining the 4-D array of RGB images. The maximum value ofcount
is 10.
Data Types: double
Output Arguments
4-D array of RGB images, returned as RGB-by-n matrix of values, where n is the value specified ascount. Ifcount
= 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 incount.
Extended Capabilities
- You can also deploy
readFrame
on the Raspberry Pi hardware in MATLAB Online™. - Bullseye and Bookworm OS only supports C++ code generation while using
readFrame
function withcameraboard
object.