Connection to camera board on Raspberry Pi hardware
This object represents a connection from the MATLAB® software to the camera board on the Raspberry Pi™ hardware. To interact with the camera board, use this object with the functions listed in Object Functions.
creates a connection, mycamera
= cameraboard(mypi
)mycamera
,
from the MATLAB software to a camera board on the Raspberry Pi hardware.
uses name-value pair arguments to override the default
values of writable camera board properties. You can use
these properties to control image properties such as size,
resolution, orientation, exposure, and special
effects.mycamera
= cameraboard(mypi
,Name,Value
)
mypi
— Connection to specific Raspberry Pi hardware boardConnection to a specific Raspberry Pi hardware board, specified
as a raspi
object.
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
mycam =
cameraboard(mypi,'Resolution','1280x720')
'Resolution'
— Image dimensions'640x480'
(default) | '160x120'
| '320x240'
| '800x600'
| '1024x768'
| '1280x720'
| '1920x1080'
The height and width of the image in pixels that the camera captures, specified as as character vector.
Example: '1024x768'
Data Types: char
'Quality'
— JPEG image quality10
(default) | integer between 1
and 100
The quality of the image that the camera captures, specified as a scalar between
1
and 100
(low to high).
The value of this parameter is inversely related to the amount of compression
the camera performs upon the JPEG images. A value of 1
applies
maximum compression. A value of 100
applies minimal
compression.
Example: 10
Data Types: double
'Rotation'
— Degrees of clockwise rotation0
(default) | 90
| 180
| 270
The orientation of the image that the camera
captures, specified as 0
,
90
, 180
, or
270
.
Example: 180
Data Types: double
'HorizontalFlip'
— Flip image horizontally0
(default) | 1
Reverse the left and right orientation of the image that the camera captures.
Example: 1
Data Types: scalar
'VerticalFlip'
— Flip image vertically0
(default) | 1
Reverse the top and bottom orientation of the image that the camera captures.
Example: 1
Data Types: scalar
'FrameRate'
— Video frame rate30
(default) | integer between 2
and 90
This property is read-only.
The number of frames per second (fps) that
the camera captures, specified as a scalar between 2
and
90
.
Example: 30
Data Types: double
'Brightness'
— Image brightness50
(default) | integer between 0
and
100
The brightness level to adjust for the
amount of lighting on the image that the camera
captures, specified as a scalar between
0
and 100
(low to high).
Example: 60
Data Types: double
'Contrast'
— Image contrast0
(default) | integer between -100
to
100
The contrast level to adjust for the
difference between brightest and dimmest areas in
the image that the camera captures, specified as a
scalar between -100
and
100
(low to high).
Example: 60
Data Types: double
'Saturation'
— Image color saturation0
(default) | integer between -100
to
100
The saturation level to adjust the amount of
color in the image that the camera captures,
specified as a scalar between
-100
and 100
(low to high).
Example: 60
Data Types: double
'Sharpness'
— Image sharpness0
(default) | integer between -100
and
100
The sharpness level to adjust the clarity of
the image that the camera captures, specified as a
scalar between -100
to
100
(low to high).
Example: 60
Data Types: double
'ExposureMode'
— Exposure mode'auto'
(default) | 'night'
| 'nightpreview'
| 'backlight'
| 'spotlight'
| 'sports'
| 'snow'
| 'beach'
| 'verylong'
| 'fixedfps'
| 'antishake'
| 'fireworks'
The exposure mode of the image that the
camera captures. Use auto
for
the camera select the best mode.
Example: 'backlight'
Data Types: char
'ExposureCompensation'
— Exposure compensation0
(default) | integer between -10
and
10
The exposure compensation applied to the
image that the camera captures, specified as a
scalar from -10
to
-10
(low to high).
Fine-tune the automatic exposure. For
example, if a backlit subject is too dark when
ExposureMode
is
'backlight'
, increase the value
of ExposureCompensation
.
Example: -1
Data Types: double
'AWBMode'
— Automatic white balance mode'auto
(default) | 'off'
| 'sun'
| 'cloud'
| 'shade'
| 'tungsten'
| 'fluorescent'
| 'incandescent'
| 'flash'
| 'horizon'
The automatic white balance (AWB) mode
applied to the image that the camera captures,
specified as a character vector. The AWB mode
adjusts the hue of the image to match the color
temperature of various light sources. Use
auto
for the camera to select
the best mode for image capture.
For example, tungsten light bulbs tend to
produce images that have an orange hue. To reduce
this effect, set AWBMode
to
auto
or
tungsten
. To keep this effect,
set AWBMode
to
off
. To heighten this effect,
set AWBMode
to
auto
or
shade
.
Example: 'fluorescent'
Data Types: char
'MeteringMode'
— Metering mode'average'
(default) | 'spot'
| 'backlit'
| 'matrix'
The mode to select which portion of the image determines exposure, specified as a character vector.
average
— Uses values
from across the scene, with a moderate bias toward
values near the center.
spot
— Uses values from a
narrow area in the center of the image.
backlit
— Uses a cluster
of lower values near the center of the
image.
matrix
— Uses values from
a grid of specific points in the image.
Example: 'backlight'
Data Types: char
'ImageEffect'
— Image special effect'none
(default) | 'negative'
| 'solarise'
| 'sketch'
| 'denoise'
| 'emboss'
| 'oilpaint'
| 'hatch'
| 'gpen'
| 'pastel'
| 'watercolour'
| 'film'
| 'blur'
| 'saturation'
| 'colourswap'
| 'washedout'
| 'posterise'
| 'colourpoint'
| 'colourbalance'
| 'cartoon'
The special effect applied to the image that
the camera captures, specified as a character
vector. Use none
to disable
special effects on the image.
Example: 'cartoon'
Data Types: char
'VideoStabilization'
— Video stabilization'off'
(default) | 'on'
Activate built-in stabilization to reduce effects of vibration on the video that the camera captures, specified as a character vector.
Example: 'on'
Data Types: char
'ROI'
— Region of interest[0.00 0.00 1.00
1.00]
(default)The portion of the camera sensor to use when capturing the image, specified as a vector of four values: x, y, width, and height. You can use this definition to perform digital panning and zooming while you record video.
For still images
(snapshot
) and video
(record
), the camera smooths
the Region of interest (ROI) changes by applying
them gradually over a sequence of image
frames.
The following values define the starting point and the size of ROI:
X, the vertical starting point of ROI, from 0.0000 to 1.0000 (top to bottom)
Y, the horizontal starting point of ROI, from 0.0000 to 1.0000 (left to right)
Height of ROI, from 0.0000 to 1.0000 (small to large)
Width of ROI, from 0.0000 to 1.0000 (small to large)
The following illustration shows how X and Y position the ROI relative to the camera board sensor:
The red dot is at X = 0.00 and Y = 0.00.
The blue dot is at X = 1.00, Y = 1.00.
For example, entering:
mycam.ROI = [0.50 0.50 0.33 0.33]
The 0.50 0.50
values
place the upper left corner of the ROI in the
center of the sensor. The 0.33
0.33
values resize the ROI to 1/3 of the
sensor. If ROI exceeds the dimensions of the
sensor, the method that you are using produces the
following error:
Index exceeds matrix dimensions.
Example: [0.50 0.50 0.33
0.33]
Data Types: double
You can connect to the camera board from the MATLAB software, take a photograph, and record video.
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, 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])
Import and display a sequence of 10 snapshots on your computer.
for ii = 1:10 img = snapshot(mycam) imagesc(img) drawnow end
If the image is upside down, change its orientation.
mycam.Rotation = 180
You can use the same approach to change the values of other cameraboard
properties.
Record a 60 second video.
record(mycam,'myvideo.h264',60)
Stop the recording immediately.
stop(mycam)
Copy the video from the board to your computer.
getFile(mypi,'myvideo.h264','C:\MATLAB ')
Delete the video file from the hardware to free up space.
deleteFile(mypi,'myvideo.h264')
You can also deploy the cameraboard
object on the Raspberry Pi hardware in MATLAB
Online™.
Using the full version of the Raspberry Pi OS is recommended when deploying cameraboard
on the
Raspberry Pi hardware in MATLAB
Online.
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.