Main Content

Set Properties for IP Camera Acquisition

IP Camera Properties

For IP cameras, device-specific properties cannot be set programmatically using the ipcam object. The snapshot function uses the resolution and other properties that are already set on the camera. However, you can set device-specific properties using the webread function. See Change a Device-Specific Property Using webread.

When you create the ipcam object, the object has four properties that are used as input arguments — the URL, which is required, and three optional properties that can be set when you create the object.

PropertyValues
URL

URL of the IP camera, specified as a character vector. The URL is necessary to create the object. Other arguments are optional.

The URL must either be for a MJPEG camera over HTTP or RTSP stream or H.264 over RTSP stream. So the URL must start with http or rtsp.

UsernameUser name for the IP camera, specified as a character vector. Use the Username argument, along with the Password argument, if the camera requires authentication. Username is the second argument.
PasswordPassword for the IP camera, specified as a character vector. Use the Password argument, along with the Username argument, if the camera requires authentication. Password is the third argument.
Timeout

Timeout duration, specified as a numeric, in seconds. The Timeout property specifies the amount of time that the snapshot function waits for data to be returned.

Timeout is the only name-value pair that the ipcam function accepts. It must appear last, after the URL, Username, and Password. Timeout is a double data type and has a range of 0 to Inf. Use the property to change the duration from the default value of 10 seconds. You can also change the value after object creation.

Set the Timeout Property During Object Creation

Use the ipcam function with the URL of the camera and the optional Timeout argument to specify the timeout used during acquisition. The Timeout property specifies the amount of time in seconds that the snapshot function waits for data to be returned.

  1. Create an object, cam, using the URL of the IP camera, and change the Timeout value from the default of 10 seconds. For information about finding the URL, see Troubleshooting Connection Issues to the IP Camera.

    cam = ipcam('http://172.28.17.193/video.mjpeg', '', '', 'Timeout', 20)
    cam = 
    
    Display Summary for ipcam:
    
                 URL: 'http://172.28.17.193/video.mjpeg'
            Username: ''
            Password: ''
             Timeout: 20
                 

    The ipcam function creates the object and connects it to the IP camera with the specified URL, and sets the Timeout to 20 seconds. Timeout must appear last, after the URL, Username, and Password. If your camera does not require user authentication, you can just enter empty character vectors for the Username and Password arguments, as shown here.

  2. After creating the object, you can preview the image and take snapshots from the camera. For more information, see Acquire Images from IP Cameras.

Set the Timeout Property After Object Creation

You can set the Timeout property after object creation.

  1. Create an object, cam, using the URL of the IP camera. For information about finding the URL, see Troubleshooting Connection Issues to the IP Camera.

    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. This way of creating the object requires no user authentication, so the Username and Password properties are blank in the object display. The default Timeout of 10 is used if you do not specify the property when creating the object.

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

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

    imshow(img)
  4. You can change the Timeout property any time after the object is created. In this case, increase it to 25 seconds.

    cam.Timeout = 25
  5. Now when you use snapshot, the new duration of 25 seconds is in effect.

Change a Device-Specific Property Using webread

For IP cameras, device-specific properties cannot be set programmatically using ipcam. However, you can change camera properties using webread before creating the ipcam object.

This example shows how to use webread to change the brightness of an IP camera.

  1. Create a weboptions object.

    o = weboptions;
  2. Set the Username of the IP camera.

    o.Username = 'admin'
  3. Set the Password of the IP camera.

    o.Password = 'admin'
  4. Use the webread function to set the brightness.

    webread('http://172.28.22.25/command/camera.cgi/?Brightness=1',o)
  5. You can then create an ipcam object using the same camera and take snapshots, as described in Acquire Images from IP Cameras.

Note

You need to contact your camera vendor to get the URL to access properties.