The ultimate expert guidance for HALCON Extension Package development (C). Combines low-level implementation rules, mandatory error handling patterns, systematic debugging, and implementation contracts.
This skill provides the comprehensive technical knowledge required to extend HALCON's core functionality. It merges legacy best practices with modern MCP-based retrieval to ensure production-grade stability, memory integrity, and localized clarity.
.def files with strict slot and bilingual requirements.Always use the search_halcon_knowledge tool with domain="extension_package_development".
Multi-Version Strategy:
HAlloc behavior change between 23.11 and 24.05), perform parallel searches for both versions.halcon_version parameter (e.g., halcon_version="24.11") to isolate macros, headers, and rules for a specific target environment.HALCONROOT version but will fallback to others if no results are found.Optimal Workflow:
source_type="header" for exact C signatures (e.g., HGetCPar, HPGetPElemD) and macro definitions.source_type="example" and language="c" to see Hproc_handle orchestration.source_type="documentation" for memory ownership and parallelization rules in the "Extension Package Manual".malloc/free. ALWAYS use HAlloc and HFree. Use deallocators immediately when scope ends.NULL pointers after every allocation or parameter retrieval.snake_case for all C functions and variables. External operators must have descriptive names without suffixes (e.g. my_op not my_op_c).#ifndef, #define, #endif guards are present in all .h files./** ... */ blocks for all public functions/structs. Define @param[in/out], @brief, and @return.CIP...):
Herror CIPMyOp(Hproc_handle proc_handle).Hproc_handle.HGetCPar, HGetObj), handle tuples (HAllSegm), validate types, call the Action Procedure, and return results (HNewRegion, HPutObj).IPB...):
Hrlregion, Himage, Hlong*).Before implementing any C logic, you MUST create a verification script.
halcon-developer skill..hdev test using synthetic data (e.g., gen_image_const) to ensure portability.try/catch, avoid stop(), and use buffer windows for rendering.Descriptive error messages are mandatory. Standard codes (1-1000) are reserved; use the 33000 offset for custom validation.
snprintf to format a context-rich string.HSetErrText(msg).Search for standard codes in headers (e.g., H_ERR_WRP) to find their base values.
Avoid "silent crashes" with this diagnostic workflow:
HPGetPElemD, HPGetPElemS, etc.) and return HAllocOutpCtrl with a simple constant to verify integration first.fflush(stdout) after every printf to ensure output is captured before a potential crash.n_values > 0 before indexing.CONV_CAST in HPGetPElem to handle both INT and REAL tuples.#pragma OpenMP blocks to rule out race conditions.cmake -DHALCON_XL=1.halcon-doc-specialist skill to write an optimal .def file.short, module (before abstract), abstract, result_state, parameter descriptions.HALCONEXTENSIONS and bin/<ARCH> to PATH.search_halcon_knowledgedomain: "extension_package_development".source_type: "header", "documentation", or "example".language: "c", "def", or "cmake".fast_search: Set to true for exact name searches or macro lookups to skip the reranker and get results faster.