快速完成原型设计

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.

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

The HALCON Embedded installation contains the script “datacode.hdev” for reading 2D codes
The HALCON Embedded installation contains the script “datacode.hdev” for reading 2D codes
uEye cameras with driver software are available for both platforms with identical interfaces
uEye cameras with driver software are available for both platforms with identical interfaces

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.

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”