Main Content

snapshot

Acquire single image frame from an IP camera

Add-On Required: This feature requires the MATLAB Support Package for IP Cameras add-on.

Description

img = snapshot(cam); acquires a single image from the IP camera cam and assigns it to img. The snapshot function returns the current frame. Calling snapshot in a loop returns a new frame each time. The returned image uses whatever format and resolution the IP camera stream is set to, and these properties cannot be changed programmatically.

example

[img,ts] = snapshot(cam); acquires a single image from the IP camera cam, assigns it to the variable img, and returns the timestamp ts.

example

Examples

collapse all

Use the snapshot function to acquire one image frame from an IP camera. You then show it using a display function such as imshow or image.

Create an object, cam, using the URL of the IP camera. The URL address is for a Motion JPEG (mjpeg) over HTTP stream. For information about finding the URL, see Find IP Camera URL.

cam = ipcam('http://172.28.17.193/video.mjpeg')
cam = 

Display Summary for ipcam:

             URL: 'http://172.28.17.193/video.mjpeg'
        Username: ''
        Password: ''
         Timeout: 10
             

The ipcam function creates the object and connects it to the IP camera with the specified URL.

Preview the image from the camera.

preview(cam)

The preview window displays live video stream from your camera.

Close the preview.

closePreview(cam)

Acquire a single image from the camera using the snapshot function, and assign it to img.

img = snapshot(cam);

Display the acquired image.

imshow(img)

Clean up by clearing the object.

clear cam

Use the snapshot function to acquire one image frame from an IP camera. You can also acquire the timestamp of the snapshot.

Create an object, cam, using the URL of the IP camera. The URL address is for a Motion JPEG (mjpeg) over HTTP stream.

cam = ipcam('http://172.28.17.193/video.mjpeg')
cam = 

Display Summary for ipcam:

             URL: 'http://172.28.17.193/video.mjpeg'
        Username: ''
        Password: ''
         Timeout: 10
             

The ipcam function creates the object and connects it to the IP camera with the specified URL.

Acquire a single image from the camera using the snapshot function, assign it to img, acquire the timestamp, and assign it to ts.

[img, ts] = snapshot(cam);

Display the acquired image.

imshow(img)

Display the timestamp of the snapshot.

ts
ans = 

    13-Jan-2015 14:07:19

Release the camera by clearing the object.

clear cam

Output Arguments

collapse all

Timestamp of the snapshot, returned as a datetime object.

Version History

Introduced in R2015a