You are here: Start » Program Examples » HMI Grab Single Image

HMI Grab Single Image


The task is to create simple application for grabbing and saving images from a camera.


For training purpose it is not needed to have a camera connected to PC. Instead of this, you can load images from a disk directory.

Solution (AVS)

  1. Create Step macrofilter GrabImage. This macrofilter simulates the operation of filters for acquiring images from cameras. If you have a connected camera compliant with any supported standard, add the appropriate filter from the Image Acquisition category and go to step 4.

  2. Add EnumerateImages to get images from a directory. Create a output of type Image and connect it with outImage.

  3. Add a Delay filter for simulating the camera's delay.

  4. Add Variant macrofilter StoreImage with forking port inButtonPressed of type Bool.

  5. To the variant True:

    • Add CurrentDateTime filter to create a timestamp in format YYYY_MM_DD-hh_mm_ss.
    • Add Formula to create FilePath to location where an image will be saved.
    • Add Formula's input inDateAndTime of type String and connect it with the outDateTimeString. Then add another inputs of type String inDirectory and inFileNamePrefix. These inputs will be connected to specific HMI controls, since user has to be able to set a destination directory and a name prefix of file.
    • Add SaveImage filter to save an image to a file.
  6. The next step is to create HMI using HMI Designer available in the toolbar.

  7. At the top of your HMI put Label control, available in Controls category and set its Text property as "Grab Single Image".

  8. To allow end-user to select a directory where an image should be saved, add DirectoryPicker control from File System category. Connect its output outDirectory with the formula's input of the same name.

  9. To display the loaded image, add VideoBox control from Video Box category and connect its input with the output of GrabImage macrofilter.

  10. The task of this application is to grab and save an image in certain time, not in every iteration. Therefore ImpulseButton available in the Controls category can be used as a trigger. Connect its output outValue to the StoreImage's macrofilter forking port.

  11. Add EnumBox control available in Controls category and set its Type property to ImageFileFormat. Connect the output outValue with input inImageFileFormat.

  12. Add TextBox control to enable the user to enter a prefix of FileName. Connect its output outText with the input InFileNamePrefix of the previously created formula.

Macrofilter Main

Macrofilter GrabImages

Macrofilter StoreImage(True)

Macrofilter StoreImage(False)

Used Filters

Icon Name Description
Delay Suspends the program workflow for inTime milliseconds.
EnumerateImages Emulates image acquisition with images stored on disk.
SaveImage Saves an image to a file.
CurrentDateTime Returns a string containing the date time information in selected format and all of the date time data separately.