Rapid Prototyping
Just quickly test an embedded image processing application? This task does not have to fail upon the complex cross compiling of source code. Fast and easy setup proof of concepts on an embedded board like the Raspberry Pi with existing components of the HALCON Embedded installation and the IDS embedded driver. This application note will give you step-by-step instructions building a simple embedded code reader with already existing components and comparing the performance with a desktop PC.
Code Reading with Raspberry Pi and IDS camera
Reading codes like QR, Atztec, ECC200 is implemented very easily with HALCON. HDevelop (HAL-CON development environment) contains several sample scripts. But how do you run this application on an embedded board? And has the embedded CPU enough power? This application note will give you step-by-step instructions building a simple embedded code reader with already existing compo-nents and comparing the performance with a desktop PC.
Using the HALCON script engine (HDevEngine) has the benefit that created scripts will run on all supported platforms. The image processing will remain platform independent and therefore expandable via HDevelop. HALCON scripts are created with HDevelop on the development PC and executed with the existing tool hrun on the embedded board. With this approach you do not have to cross compile any single line of source code on your own.
Requirements
With a few preparations, this and any other HALCON Embedded application could be realized very fast on a Raspberry Pi 3. You need the following items:
- Raspberry Pi (from version 2, ARMv7 platform compatible), ready installed with Raspbian image and the HALCON Embedded runtime environment.
- Desktop PC with installed (licensed) HALCON development environment
- For using an IDS uEye camera, the IDS embedded driver have to be installed on the Raspberry Pi (Install the embedded driver for IDS industrial cameras)
To try out HALCON Embedded, you can get an evaluation package containing the USB dongle license from IDS or MVTec.
Installing HALCON Embedded
Copy and unpack the HALCON Embedded “Runtime” package on your target platform. This installation path will be your HALCONROOT. (e. g. in /opt/halcon)
> sudo tar -xvf <paket> -C /opt/halcon
To use HALCON for applications in your system, you have to define a few environment variables. Create a shell script, set the appropriate variables (see markings) and save this script e. g. in your HALCONROOT folder. (/opt/halcon/.profile_halcon)
To activate the new HALCON environment at logon, add the following command to the end of your profile file in your user folder: ~/.profile
source /opt/halcon/.profile_halcon
Licensing HALCON Embedded
HALCON Embedded is activated via a license file with the corresponding USB dongle. You can request this license pair from the IDS Support or MVTec. You can look up the license procedure in the /opt/halcon/readme_embedded.txt file under topic “Licensing”.
- Copy the license.dat file, compatible with the USB dongle, in the /opt/halcon/license folder on the target system.
- Plug the USB dongle into a free USB port of the Raspberry Pi and check with the dmesg command on the Linux console if the dongle is recognized as VendorID 1547.
- Afterwards, create a UDEV rule in the Linux system to allow access to the dongle for all processes. Create the /etc/udev/rules.d/98-sglock.rules file with following content:
ATTRS{idVendor}=="1547", ATTRS{idProduct}=="1000", MODE="666"
- It is necessary to restart the UDEV daemon to activate the new rule. To do so, restart the Raspberry Pi or execute the following command to reload this service:
> sudo /etc/init.d/udev reload
- Use the hbench tool to test the HALCON installation. If error 2036 occurs, this indicates a problem with the license. In this case, check again all steps of the license procedure.
HALCON Benchmark tool
With the hbench tool, HALCON provides its own benchmark tool which can be used to evaluate and rate procedure calls on the test system. It is included in each HALCON installation for the corresponding platform (<HALCONROOT>/bin/<HALCONARCH>/hbench).
HALCON benchmark for operator find_data_code_2d on Raspberry Pi 3:
pi@raspberrypi:~ $ $HALCONROOT/bin/$HALCONARCH/hbench -operator
find_data_code_2d -reentrant
HALCON 12.0 Benchmark (v3.1)
============================
(computing on images of size 640x480)
OPERATOR reentrant
time[ms]
Data code reading, ecc 200 (byte) ...... 25.481
HALCON benchmark for operator find_data_code_2d on Core i7 Windows PC:
C:\Program Files\MVTec\HALCON-12.0\bin\x64-win64\hbench.exe -operator
find_data_code_2d –reentrant
HALCON 12.0.2 Benchmark (v3.1)
==============================
(computing on images of size 640x480)
OPERATOR reentrant
time[ms]
Data code reading, ecc 200 (byte) ...... 4.811
The benchmark of the HALCON operator for reading 2D codes (ECC200) shows significant differences in processing time on different platforms.
Simple image based code reading script
With a simple QR-Code HALCON script, that reads sample images and is executed on both systems with the HDevEngine, you can verify the differences in reading performance.
For example, start with the HALCON example script qrcode_simple.hdev. You find it in the /examples/hdevelop/Applications/Data_Codes/ folder. Enhance it with a simple time measurement for the reading process and an output message.
After testing the script with HDevelop, copy it to the embedded board and execute it directly with the hrun tool. This is delivered pre-compiled with HALCON embedded. You find it in the <HALCON-ROOT>/bin/<HALCONARCH>/hRun folder.
pi@raspberrypi:~ $ hrun qrcode_simple.hdev
The time measurement verifies the performance difference of the two systems. (left side: Windows Desktop Core i7, right side: Raspberry Pi 3):
Reading codes with an IDS camera
Next “scan” 2D codes with an IDS uEye camera. Therefore, the IDS Embedded driver has to be installed on the Raspberry Pi. (Embedded boards driver for IDS industrial cameras)
Start with the simple script “datcode.hdev”, that is also provided with the HALCON Embedded installation. You find it in the installation part for the development PC.
For using a uEye camera, you only have to modify a few lines of script code. You just need one single “framegrabber” call for all platforms, because the camera’s software interface stays the same on all platforms.
You can insert the code lines for the uEye camera image acquisition also with the HDevelop assistant “Image Acquisition”. Choose “uEye” as interface.
After that, the script could be executed both on the Desktop PC and on the Raspberry Pi. Copy the script on the embedded board and execute it again with the hrun tool.
pi@raspberrypi:~ $ hrun datacode.hdev
As result, you see a live display of your uEye camera. If you hold datamatrix codes of the type ECC200 in front of the camera, HALCON will decode the codes and show you the content.
Your simple Embedded Code Reader is ready to use.
Image acquisition tips
Because the camera configuration on the embedded board respectively under HALCON is not really easy, you better use the possibility of camera pre-configuration with a Windows PC and the uEye Cockpit. This is the best possible solution to adjust your camera. Save the configuration in the camera’s parameter set to use it afterwards in HALCON. This is very simply done when opening the frame grabber, by using /cam/set1 as parameter value for “CameraType”. For further information on uEye camera configuration read our TechTip "Parameterizing instead of Programming: The faster way to camera setup“.
Because the embedded board does not have the performance of a Desktop PC, you should reduce the camera framerate for your first test. First try getting a stable camera live display without HALCON before using the camera configuration with your image processing.
Tips for building your embedded development environment
Setup your embedded board starting with preparing the OS image, copying files from place to place until the program execution, could be handled in different ways. With the latest Raspbian image you can work with your Raspberry Pi also completely “headless” (without connecting a display, keyboard and mouse) over SSH and VNC servers. However, there are several obstacles to be taken. Especially in a company network the network connection from your development PC to your Raspberry Pi can be a tremendous challenge.
The easiest way to start is the classical way by connecting a display, a mouse, a keyboard and by using an USB memory stick for copying data (programs, scripts, HALCON installation files) between your two systems. For more complex applications this is not the most comfortable way, but for a first proof of concepts really easy and fast to realize.
More application notes and TechTips can be found at our website https://en.idsimaging.com/knowledge-base.html
Appendix
Source code “datacode.hdev”
Modified code of script datacode.hdev to read codes with a uEye camera. The most important modifi-cations are colored. For using the script, copy it in HDevelop und save it as “datacode.hdev”