Main Content

Acquire Images from IP Cameras

This example shows how to use the snapshot function to acquire one image frame from an IP camera and display it.

  1. Create a ipcam object using the URL of the IP camera. The URL must be for a Motion JPEG (mjpeg) over HTTP or RTSP stream or H.264 over RTSP stream with basic authentication or digest authentication. For more information on finding the URL, see Troubleshooting Connection Issues to the IP Camera.

    cam = ipcam('http://172.28.17.104/video/mjpg.cgi')
    cam = 
    
    Display Summary for ipcam:
    
                 URL: 'http://172.28.17.104/video/mjpg.cgi'
            Username: ''
            Password: ''
             Timeout: 10

    The ipcam function creates the object and connects it to the IP camera with the specified URL. The camera used in this example does not require user authentication. If your camera does, see Connect with User Authentication to create the object with user name and password.

  2. Optionally, preview the image from the camera.

    preview(cam)

    The preview window opens and displays live video stream from your camera. For more information about the preview window, see the preview function.

  3. You can close the preview window at any time.

    closePreview(cam)
  4. Acquire a single image from the camera using the snapshot function, and assign it to img.

    img = snapshot(cam);
  5. Display the acquired image.

    imshow(img)

  6. Release the camera by clearing the object.

    clear cam

Note

You can also acquire the timestamp with the snapshot. See Acquire One Image Frame and the Timestamp from an IP Camera.

See Also