///////////////////////////////////////////////////////////////////////////////
// File generated by HDevelop for HALCON/C++ Version 12.0
///////////////////////////////////////////////////////////////////////////////
#ifndef __APPLE__
# include "HalconCpp.h"
# include "HDevThread.h"
# if defined(__linux__) && !defined(NO_EXPORT_APP_MAIN)
# include <X11/Xlib.h>
# endif
#else
# ifndef HC_LARGE_IMAGES
# include <HALCONCpp/HalconCpp.h>
# include <HALCONCpp/HDevThread.h>
# else
# include <HALCONCppxl/HalconCpp.h>
# include <HALCONCppxl/HDevThread.h>
# endif
# include <stdio.h>
# include <HALCON/HpThread.h>
# include <CoreFoundation/CFRunLoop.h>
#endif
using namespace HalconCpp;
#ifndef NO_EXPORT_MAIN
// Main procedure
void action()
{
// Local iconic variables
HObject ho_Image, ho_SymbolXLDs;
// Local control variables
HTuple hv_DataCodeHandle, hv_ResultHandles, hv_DecodedDataStrings;
//create_data_code_2d_model ('Data Matrix ECC 200', 'default_parameters', 'maximum_recognition', DataCodeHandle)
//set_data_code_2d_param (DataCodeHandle, 'timeout', 200)
//set_data_code_2d_param (DataCodeHandle, 'polarity', 'light_on_dark')
//set_data_code_2d_param (DataCodeHandle, 'symbol_size_min', 16)
//set_data_code_2d_param (DataCodeHandle, 'symbol_size_max', 2)
//set_data_code_2d_param (DataCodeHandle, 'module_size_min', 10)
//set_data_code_2d_param (DataCodeHandle, 'module_size_max', 14)
//read_image (Image, 'D:/timg.jpg')
//find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)
//clear_data_code_2d_model (DataCodeHandle)
CreateDataCode2dModel("Data Matrix ECC 200", HTuple(), HTuple(), &hv_DataCodeHandle);
//该模型默认属性是‘default_parameters’,默认属性值是 ‘standard_recognition’。实际上,为了获得更好的解码结果,可以将属性值置为‘enhanced_recognition’、‘maximum_recognition’。
//读取图片
ReadImage(&ho_Image, "D:/timg.bmp");
//解码
FindDataCode2d(ho_Image, &ho_SymbolXLDs, hv_DataCodeHandle, HTuple(), HTuple(),
&hv_ResultHandles, &hv_DecodedDataStrings);
//默认为空,也可以使用‘train’, ‘all’配套属性参数,在这种方式下,模型会自主微参数来达到最好的解码效果。
//find_data_code_2d (Image, SymbolXLDs, DataCodeHandle, ‘train’, ‘all’, ResultHandles, DecodedDataStrings)
//清除模型
ClearDataCode2dModel(hv_DataCodeHandle);
CreateDataCode2dModel("Data Matrix ECC 200", HTuple(), HTuple(), &hv_DataCodeHandle);
}
#ifndef NO_EXPORT_APP_MAIN
#ifdef __APPLE__
// On OS X systems, we must have a CFRunLoop running on the main thread in
// order for the HALCON graphics operators to work correctly, and run the
// action function in a separate thread. A CFRunLoopTimer is used to make sure
// the action function is not called before the CFRunLoop is running.
HTuple gStartMutex;
H_pthread_t gActionThread;
static void timer_callback(CFRunLoopTimerRef timer, void *info)
{
UnlockMutex(gStartMutex);
}
static Herror apple_action(void **parameters)
{
LockMutex(gStartMutex);
action();
CFRunLoopStop(CFRunLoopGetMain());
return H_MSG_OK;
}
static int apple_main(int argc, char *argv[])
{
Herror error;
CFRunLoopTimerRef Timer;
CFRunLoopTimerContext TimerContext = { 0, 0, 0, 0, 0 };
CreateMutex("type","sleep",&gStartMutex);
LockMutex(gStartMutex);
error = HpThreadHandleAlloc(&gActionThread);
if (H_MSG_OK != error)
{
fprintf(stderr,"HpThreadHandleAlloc failed: %d\n", error);
exit(1);
}
error = HpThreadCreate(gActionThread,0,apple_action);
if (H_MSG_OK != error)
{
fprintf(stderr,"HpThreadCreate failed: %d\n", error);
exit(1);
}
Timer = CFRunLoopTimerCreate(kCFAllocatorDefault,
CFAbsoluteTimeGetCurrent(),0,0,0,
timer_callback,&TimerContext);
if (!Timer)
{
fprintf(stderr,"CFRunLoopTimerCreate failed\n");
exit(1);
}
CFRunLoopAddTimer(CFRunLoopGetCurrent(),Timer,kCFRunLoopCommonModes);
CFRunLoopRun();
CFRunLoopRemoveTimer(CFRunLoopGetCurrent(),Timer,kCFRunLoopCommonModes);
CFRelease(Timer);
error = HpThreadHandleFree(gActionThread);
if (H_MSG_OK != error)
{
fprintf(stderr,"HpThreadHandleFree failed: %d\n", error);
exit(1);
}
ClearMutex(gStartMutex);
return 0;
}
#endif
int main(int argc, char *argv[])
{
// Default settings used in HDevelop (can be omitted)
int ret=0;
SetSystem("width", 512);
SetSystem("height", 512);
#if defined(_WIN32)
SetSystem("use_window_thread", "true");
#elif defined(__linux__)
XInitThreads();
#endif
#ifndef __APPLE__
action();
#else
ret = apple_main(argc,argv);
#endif
return ret;
}
#endif
#endif