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

HMI Grab Single Image

Aim

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

Hints

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 the 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 the EnumerateImages to get images from a directory. Create a output of type Image and connect it with the outImage.

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

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

  5. To the variant True:

    • Add the CurrentDateTime filter to create a timestamp in format YYYY_MM_DD-hh_mm_ss.
    • Add the Formula to create the FilePath to location where an image will be saved.
    • Add the 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 the 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 the Label control, available in the Controls category and set its Text property as Grab Single Image.

  8. To allow the end-user to select a directory where an image should be saved, add the DirectoryPicker control from the 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 outValue output to the StoreImage's macrofilter forking port.

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

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

Macrofilter Main

Macrofilter GrabImages

Macrofilter StoreImage(True)

Macrofilter StoreImage(False)

Used Filters

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