Main Content

Deleting Image Acquisition Objects

When you finish using your image acquisition objects, use the delete function to remove them from memory. After deleting them, clear the variables that reference the objects from the MATLAB® workspace by using the clear function.

Note

When you delete a video input object, all the video source objects associated with the video input object are also deleted.

To illustrate, this example creates several video input objects and then deletes them.

  1. Create several image acquisition objects — This example creates several video input objects for a single webcam image acquisition device, specifying several different video formats. To run this example on your system, use the imaqhwinfo function to get the object constructor for your image acquisition device and substitute that syntax for the following code.

    vid = videoinput('winvideo',1);
    vid2 = videoinput('winvideo',1,'RGB24_176x144');
    vid3 = videoinput('winvideo',1,'YV12_352x288');
  2. Clean up — Always remove image acquisition objects from memory, and the variables that reference them, when you no longer need them.

    You can delete image acquisition objects one at a time, using the delete function.

    delete(vid)
    

    You can also delete all the video input objects that currently exist in memory in one call to delete by using the imaqfind function. The imaqfind function returns an array of all the video input objects in memory.

    imaqfind
    
       Video Input Object Array:
    
       Index:   Type:          Name:  
       1        videoinput     RGB555_128x96-winvideo-1
       2        videoinput     RGB24_176x144-winvideo-1
       3        videoinput     YV12_352x288-winvideo-1

    Nest a call to the imaqfind function within the delete function to delete all these objects from memory.

    delete(imaqfind)

    Note that the variables associated with the objects remain in the workspace.

    whos
      Name       Size                   Bytes  Class
    
      vid        1x1                     1120  videoinput object
      vid2       1x1                     1120  videoinput object
      vid3       1x1                     1120  videoinput object
      vids       1x3                     1280  videoinput object

    These variables are not valid image acquisition objects.

    isvalid(vid)
    
    ans =
        0
    

    To remove these variables from the workspace, use the clear command.