Table of Contents

Overview

HALCON is the comprehensive standard software library with an integrated development environment (IDE) for machine vision from MVTec.

HALCON provides an extensive library of more than 1300 operators with outstanding performance for blob analysis, morphology, pattern matching, measuring, 3D object recognition, and binocular stereo vision, to name just a few. Easy programming in C, C++, C#, Visual Basic .NET, and Delphi

Installation

SBOx-C preparation

  1. download the Embedded Halcon library (examples inside) (according to your purchased halcon runtime license!!) and install the package on your camera
    ipkg-cl install halcon_8.0.1_arm.ipk
  2. install framegrabber (= data acquisition) package
    ipkg-cl install hfgfesto_7.1-3.1.5-festo0_arm.ipk
  3. install X11 package for visualiziation (optional, without limited feature support)
    ipkg-cl install x11_X11R7-3.1.5-festo0_arm.ipk
  4. set environment variables HALCONROOT and LD_LIBRARY_PATH according to /ffx/halcon/.profile_halcon or
    create a shell script starting your application including the following lines of code for the target PC with IP 192.168.1.7 and X11 visualiziation
    export HALCONROOT=/ffx/halcon
    export LD_LIBRARY_PATH=/ffx/halcon/lib/arm-eneo-linux2.6:$LD_LIBRARY_PATH
    export DISPLAY=192.168.1.7:0.0

    You can also add the following lines to your startupscript /ffx/rcS

    export HALCONROOT=/ffx/halcon
    export LD_LIBRARY_PATH=/ffx/halcon/lib/arm-eneo-linux2.6:$LD_LIBRARY_PATH
    ldconfig
    
  5. copy the license.dat file into the directory /ffx/halcon/license. The id within the licensefile should match the unique id otherwise the halcon license checkout will fail!!

ATTENTION: Maybe you have to adapt /ffx/etc/ld.so.config (→ see Installing plain libraries) for the halcon lib file (also /ffx/halcon/.profile_halcon)

Programming PC for image processing algorithm developement

Download the full version for your PC at Halcon release download link and install it.

Remember you need a full halcon release license if you want to develop your image processing algorithm using the integrated halcon IDE.

Develop image processing algorithm using HDevelop

  1. generate a hdevelop script for your image processing problem
  2. save the script as *.cpp-file
  3. remove everything visualiziation relevant from *.cpp-Sourcecode, such as
    dev_close_window
    dev_update_window
    dev_update_pc
    set_window_attr
    open_window
    disp_obj
    clear_window
    ...

    if x11_X11R7-3.1.5-festo0_arm.ipk is NOT installed at camera

Compilation

The headerfiles for the libraries (→ see SBOx-C preparation) can be found at the PC with an installed HALCON application inside the subdirectory include (i.e. c:\Program Files\MVTec\HALCON\include)

Example

Examples for the HALCON library usage are found inside the *.tar.gz archive (i.e. halcon-8.0.1-eneo-sc.tar.gz) of the downloaded Embedded Halcon library.

The default example3.cpp for the camera can also be found → here

PC visualiziation

You will find a detailled setup-procedure under X.

Hints + FAQs

HALCON stops with HALCON exception

file      = /halcon/revisions-7.1/source/interfaces/C++/HCPP.cxx
procedure = set_system
line      = 432
error#    = 2041
message   =  HALCON error #2041: Invalid host in operator set_system
thread    = 16384

Solution: Check if your license file at /ffx/halcon/license/license.dat is valid and the id inside matches the unique id!!

ipkg-cl install hangs during install of a package

Solution:

Wrong time values with count_seconds function

The HALCON function count_seconds returns unreliable results for image processing time calculation.

HTuple Start, End, ElapsedTime;
...
count_seconds(&Start);
...
// some time consuming image processing
...
count_seconds(&End);
ElapsedTime = End-Start;

Solution: You have to add

set_system("clock_mode","elapsed_time");

to your source code for correct elapsed time calculation inside HALCON.

Anyway there still remains a jitter of ± 20 ms (1 ms = 10^-3 s).
So for exact time calulation use the function gettimeofday as shown below:

#include <sys/time.h>	// struct timeval, gettimeofday()
 
/** Calculate the time difference from (End - Start).
 * \param pStart starting time value received from function gettimeofday
 * \param pEnd end time value received from function gettimeofday
 * \return time difference in usec (10e-6)
 */
long lTimeDiff(struct timeval *pStart, struct timeval *pEnd)
{
  return((pEnd->tv_sec - pStart->tv_sec)*1000000 + (pEnd->tv_usec - pStart->tv_usec));
}
/** Calculate the time difference from start to now.
 * \param pStart starting time value received from function gettimeofday
 * \return time difference in usec (10e-6)
 */
long lTimeDiffNow(struct timeval *pStart)
{
  struct timeval Now;
  gettimeofday(&Now,0);
  return((Now.tv_sec - pStart->tv_sec)*1000000 + (Now.tv_usec - pStart->tv_usec));
}
 
/** Calculate the time difference from (End - Start).
 * \param pStart starting time value received from function gettimeofday
 * \param pEnd end time value received from function gettimeofday
 * \return time difference in structure struct timeval
 */
struct timeval tTimeDiff(struct timeval *pStart, struct timeval *pEnd)
{
  struct timeval Result;
  Result.tv_sec = pEnd->tv_sec - pStart->tv_sec;
  Result.tv_usec = pEnd->tv_usec - pStart->tv_usec;
  if(Result.tv_usec < 0)
  {
    Result.tv_usec += 1000000;
    Result.tv_sec--;
  }
  return(Result);
}
/** Calculate the time difference from start to now.
 * \param pStart starting time value received from function gettimeofday
 * \return time difference in structure struct timeval
 */
struct timeval tTimeDiffNow(struct timeval *pStart)
{
  struct timeval Now;
  gettimeofday(&Now,0);
  Now.tv_sec -= pStart->tv_sec;
  Now.tv_usec -= pStart->tv_usec;
  if(Now.tv_usec < 0)
  {
    Now.tv_usec += 1000000;
    Now.tv_sec--;
  }
  return(Now);
}
 
struct timeval	Start, End:
long ElapsedTime;               // elapsed image processing time in usec (10e-6)
...
gettimeofday(&Start, 0);
...
// some time consuming image processing
...
gettimeofday(&End, 0);
ElapsedTime = lTimeDiff(&Start, &End);

Hint: Uncomment source code lines from CPP-hdevelop-export

HALCON's cpp-export from hdevelop does NOT support commented lines with code.
If uncommenting source code lines there has to be done some additional work.