This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

snapshot

Capture RGB image and elapsed time from camera

Syntax

[img,time] = snapshot(mycamera)
[img,time] = snapshot(wcam)

Description

example

[img,time] = snapshot(mycamera) returns a still image with the elapsed time of image capture from the Camera Board.

[img,time] = snapshot(wcam) returns a still image with the elapsed time of image capture from the web camera.

Examples

collapse all

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 connect from the MATLAB software to the web camera and take a photograph.

Connect the Raspberry Pi to your host computer.

Note

If you have not previously configured your Raspberry Pi, see Update Support Package.

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

mypi = raspberrypi

Create a connection, wcam, from the MATLAB software to the web camera, 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'}

Import and display a sequence of 10 snapshots on your host computer.

for ii = 1:10
    img = snapshot(wcam)
    imagesc(img)
    drawnow
end

Input Arguments

collapse all

Connection to a Camera Board, specified as a cameraboard object.

Example: mycam

Connection to a Webcam, specified as a webcam object.

Example: mycam

Output Arguments

collapse all

RGB image, returned as an n-by-n-by-3 matrix of values.

The elapsed time since the most recent call to the snapshot function after you power on the hardware, in seconds.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.