Main Content

snapshot

Acquire single image frame from mobile device camera

Description

Add-On Required

To use this function for accessing mobile device sensors remotely from MATLAB® installed on a desktop or laptop computer, you must also install either MATLAB Support Package for Apple iOS Sensors or MATLAB Support Package for Android® Sensors. For more information, see Get and Manage Add-Ons.

[img,timestamp] = snapshot(cam,shutterMode); acquires a single image and its timestamp from a mobile device camera cam using the specified shutter option shutterMode. The snapshot function opens a camera preview on the device and returns the current frame in MATLAB as an RGB image. The resolution of the image is specified by the Resolution property of the camera object cam.

Preview the image using image.

example

Examples

collapse all

Acquire an image frame using immediate shutter mode from a mobile device camera. To complete this example, you must have MATLAB Mobile™ on your mobile device and you must be connected to the MathWorks® Cloud. If you have not, see Install MATLAB Mobile on Your Device.

Start MATLAB Mobile on your device.

On the Commands screen of MATLAB Mobile, create a mobiledev object, m.

m = mobiledev
m = 
mobiledev with properties:

                   Connected: 1
            AvailableCameras: {'back' 'front'}
                     Logging: 0
            InitialTimestamp: ''

   AccelerationSensorEnabled: 0
AngularVelocitySensorEnabled: 0
       MagneticSensorEnabled: 0
    OrientationSensorEnabled: 0
       PositionSensorEnabled: 0

Create a connection to the 'back' camera of the device.

cam = camera(m,'back')
cam = 
  Camera with properties:

                    Name: 'back'
    AvailableResolutions: {'640x480'  '1280x720'}
               ZoomRange: [1 121.8750]
              Resolution: '640x480'
                    Zoom: 1
               Autofocus: 'on'
                   Flash: 'off'

Acquire a single image and timestamp from the camera. The camera preview opens on your device and immediately captures an image.

[img,t] = snapshot(cam,'immediate');

Display the acquired image in MATLAB.

image(img)

Acquire an image frame using manual shutter mode from a mobile device camera. To complete this example, you must have MATLAB Mobile on your mobile device and you must be connected to the MathWorks Cloud. If you have not, see Install MATLAB Mobile on Your Device.

Start MATLAB Mobile on your mobile device.

On the Commands screen of MATLAB Mobile, create a mobiledev object, m.

m = mobiledev
m = 
mobiledev with properties:

                   Connected: 1
            AvailableCameras: {'back' 'front'}
                     Logging: 0
            InitialTimestamp: ''

   AccelerationSensorEnabled: 0
AngularVelocitySensorEnabled: 0
       MagneticSensorEnabled: 0
    OrientationSensorEnabled: 0
       PositionSensorEnabled: 0

Create a connection to the 'back' camera of the device.

cam = camera(m,'back')
cam = 
  Camera with properties:

                    Name: 'back'
    AvailableResolutions: {'640x480'  '1280x720'}
               ZoomRange: [1 121.8750]
              Resolution: '640x480'
                    Zoom: 1
               Autofocus: 'on'
                   Flash: 'off'

Acquire a single image and timestamp from the camera using the manual shutter mode. The camera preview opens on your device. You can move your mobile device to capture the desired image in the preview. Press the shutter button on the device to acquire the image.

[img,t] = snapshot(cam,'manual');

Display the acquired image in MATLAB.

image(img)

Input Arguments

collapse all

Mobile device camera connection, specified as a camera object.

Shutter mode, specified as 'immediate' or 'manual'.

  • 'immediate' — The specified camera opens on the device and captures an image when you call snapshot.

  • 'manual' — The specified camera opens on the device and captures an image when you tap the shutter button.

Data Types: char | string

Output Arguments

collapse all

RGB image data, returned as an M-by-N-by-3 matrix of values.

Data Types: uint8

Timestamp for acquired image, returned as a datetime.

Data Types: datetime

Version History

Introduced in R2019a