Creating an application with HDevEngineπ
HDevEngine is used in the same general way as other HALCON C++ or .NET applications. The difference is that you load and execute HDevelop programs or procedures through the HDevEngine API instead of exporting the algorithm as compiled C++ code.
At a glanceπ
The following settings are required for a project that uses HDevEngine with C++:
- Include path:
%HALCONROOT%\include - Library path:
%HALCONROOT%\lib\%HALCONARCH% - Include files:
HalconCpp.handHDevEngineCpp.h -
Link libraries:
hdevenginecpp.libandhalconcpp.libHALCON XL applications
If you want to use HALCON XL, link
hdevenginecppxl.libandhalconcppxl.libinstead.
Only use HALCON XL when you need its features.
- Include path:
$HALCONROOT/include - Library path:
$HALCONROOT/lib/$HALCONARCH - Include files:
HalconCpp.handHDevEngineCpp.h -
Link libraries:
-lhdevenginecpp -lhalconcpp -lhalconHALCON XL applications
If you want to use HALCON XL, link
-lhdevenginecppxl -lhalconcppxl -lhalconxlinstead.
Only use HALCON XL when you need its features.
For the available classes and methods, see About the main classes and methods of HDevEngine.
How to develop applications with HDevEngineπ
With HDevEngine, you can execute complete HDevelop programs or individual procedures. Which approach is better depends on the stage of development and on the task:
- When you are still developing the image-processing part of your application, you typically create an HDevelop program. As an early test, it is useful to execute the HDevelop program via HDevEngine to validate the overall configuration, procedure path, environment variables, and general runtime behavior.
- After the implementation is stable, you integrate the image-processing logic into the main application by executing the corresponding HDevelop procedures. In many cases you still use HALCONβs language-specific interface for rendering results, but you can also encapsulate recurring display work in HDevelop procedures.
- External procedures are useful for reusable tasks such as image acquisition setup or standard image-processing steps. Local procedures are suitable for application-specific logic, e.g. training or configuration steps that vary by application.
Further, keep the following in mind:
- Only procedures with public scope can be executed directly.
- Private procedures can be executed only as part of a public procedure or as part of a full HDevelop program.
- All occurrences of
stopare ignored when executing a program with HDevEngine. - You can redirect
dev_*operators to your own implementation if you need custom visualization or behavior.
Parallel programming with HDevEngineπ
HDevEngine is thread-safe and reentrant in the sense that multiple procedure or program call instances can be run from different threads. However, the global engine settings are shared and must be managed carefully.
The recommended pattern is:
- configure the engine and set the procedure path before starting additional application threads
- load programs or procedures before parallel execution begins
- avoid modifying procedure paths or operator implementations concurrently with other threads
If this is not possible, protect the setup and creation of programs or procedures with a synchronization primitive so that another thread cannot change the procedure path at the wrong time.
JIT compilationπ
For optimized performance, HDevEngine can also execute compiled procedures using its built-in just-in-time compiler. The compilation is enabled via engine configuration and then takes place the first time a procedure is called. It is also possible to explicitly compile the used procedures of a program or procedure.
Procedures that use unsupported features cannot be JIT-compiled, and in such cases the interpreter path is used instead.
Debugging HDevEngine applicationsπ
HDevEngine applications can be debugged remotely from HDevelop. The application must explicitly enable the debug server; HDevelop then connects to the debug server and allows debugging of the executed HDevelop code.
How to create an executable HDevEngine/C++ programπ
The general workflow is as follows:
-
Include the required HALCON and HDevEngine headers and use the matching namespaces:
-
Compile the application with the following include paths:
-
Link the required libraries:
Python setupπ
The Python interface follows the same concepts as the C++ interface.
No special HDevEngine setup is required beyond installing the HALCON Python package and then creating an HDevEngine instance:
import os
import halcon as ha
example_dir = ha.get_system_s('example_dir')
procedure_path = os.path.join(example_dir, 'hdevengine', 'procedures')
hdev_engine = ha.HDevEngine()
hdev_engine.set_procedure_path(procedure_path)
For more information, see HDevEngine in Python applications and the example project.