You are here: Start » Program Examples » HMI Grab Single Image
HMI Grab Single Image
Aim:
The task is to create a simple application for grabbing and saving images from a camera.
Hints:
For training purposes, it is not necessary to have a camera connected to the PC. Instead of this, you can load images from a disk directory.
Solution (FIS):
-
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.
-
Add the EnumerateImages to get images from a directory. Create an output of type Image and connect it with the outImage.
-
Add the Delay filter for simulating the camera's delay.
-
Add the Variant macrofilter StoreImage with the forking port inButtonPressed of type Bool.
-
To the variant True:
- Add the CurrentDateTime filter to create a timestamp in the format YYYY_MM_DD-hh_mm_ss.
- Add the Formula to create the FilePath to the location where the image will be saved.
- Add the Formula's input inDateAndTime of type String and connect it with the outDateTimeString. Then add other inputs of type String: inDirectory and inFileNamePrefix. These inputs will be connected to specific HMI controls, since the user has to be able to set a destination directory and a name prefix of file.
- Add the SaveImage filter to save the image to a file.
-
The next step is to create the HMI using the HMI Designer available in the toolbar.
-
At the top of your HMI, put the Label control, available in the Controls category, and set its Text property as Grab Single Image.
-
To allow the end-user to select a directory where the 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.
-
To display the loaded image, add VideoBox control from Video Box category and connect its input with the output of GrabImage macrofilter.
-
The task of this application is to grab and save an image at a 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 macrofilter forking port.
-
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.
-
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. |