halcon中tuple变量定义
By
笑口常开
at 2018-03-25 • 0人收藏 • 3929人看过
typedef void* VOIDP;
/*****************************************************************************/
/* Parameter passing (Control parameters) */
/*****************************************************************************/
#define UNDEF_PAR 0 /* Parameter type: no defined type */
#define LONG_PAR 1 /* Parameter type: long */
#define HANDLE_PAR LONG_PAR /* Parameter type: long */
#define FLOAT_PAR 2 /* Parameter type: float */
#define STRING_PAR 4 /* Parameter type: string */
/* Possible parameter types for a single element: */
#define ANY_ELEM (LONG_PAR|FLOAT_PAR|STRING_PAR)
#define INT_PAR LONG_PAR /* Parameter type: int */
#define DOUBLE_PAR FLOAT_PAR /* Parameter type: double */
#define MIXED_PAR 8 /* Parameter type: Hcpar */
#define MAX_TUPLE_TYPE MIXED_PAR/* maximum type number */
/* Possible parameter types for a tuple: */
#define ANY_TUPLE (LONG_PAR|FLOAT_PAR|STRING_PAR|MIXED_PAR)
/* 16 reserved */
/* 32 reserved */
#define POINTER_PAR 64 /* Parameter type: pointer to any type */
#define TUPLE_PAR 128 /* Parameter type: pointer to tuple */
#define MAX_PAR MIXED_PAR
/*****************************************************************************/
/* Constants and basic types */
/*****************************************************************************/
#define MAX_TUPLE_LENGTH 1000000 /* max. length of a tuple */
#define MAX_STRING 1024 /* max. length of a string */
typedef UINT4 Herror; /* Type function values (error messages) */
typedef long *Hkey; /* primary key in DB (for iconic objects) */
#define UNDEF_KEY (Hkey)(0) /* Undefined iconic object */
/*****************************************************************************/
/* Structures for passing parameters between language interface and core */
/*****************************************************************************/
#ifndef HC_NO_STRUCT_MEMBER_ALIGNMENT
/* sets the struct member alignment to avoid problems if
* the settings of the user differ to those of the HALCON
* version. (8 is the default alignment, generally) */
# pragma pack(push,8)
#endif
typedef union
{
INT4_8 l; /* 4/8 byte integer (input) */
double d; /* 8 byte real (input) */
char *s; /* pointer to strings (input) */
double f; /* 8 byte real (legacy 11.0) (input) */
} Hpar; /* parameter passing for the C interface */
typedef union
{
INT4_8 *l; /* 4/8 byte integer (output) */
double *d; /* 8 byte real, (output) */
char *s; /* pointer to strings (output) */
VOIDP p; /* pointer to var. of any type (e.g. tuple)(output)*/
double *f; /* 8 byte real, (legacy 11.0) (output) */
} Hvar; /* parameter passing for the C interface */
typedef struct
{
Hpar par; /* values */
HINT type; /* type flag */
} Hcpar; /* parameter passing for the C interface */
typedef struct
{
Hvar var; /* values */
HINT type; /* type flag */
} Hcvar; /* parameter passing for the C interface */
typedef union {
INT4_8 *l;
double *d;
char **s;
Hcpar *cpar;
} Hcelem; /* pure type array */
typedef struct HCTUPLE
{
Hpar val;
HINT type;
char pad[sizeof(Hcpar)-sizeof(Hpar)-sizeof(HINT)]; /* padding for data
* structure alignement to enable val and type
* to get used as Hcpar structure */
INT4_8 num; /* number of set array elements */
INT4_8 capacity; /* allocated array length */
HINT free; /* free array elem when destroying tuple? */
Hcelem elem; /* the actual array */
} Hctuple;
#define HCTUPLE_INITIALIZER {{0},UNDEF_PAR,{0},0,0,0,{NULL}}
typedef struct
{
Hcvar *variables; /* variables (of application) to write back values */
Hcpar *element; /* tuple element(s) */
INT4_8 num_el; /* number of used elements */
INT4_8 length; /* total length of array (incl. unused elements) */
} Hcvtuple; /* for passing control parameter variables from */
typedef struct /* Tuple representation */
{
Hcpar *tuple;
INT_PTR length;
} Htuple;
11 个回复 | 最后更新于 2018-04-02
/* INT4_8 is 4 bytes on all 32-bit and 8 bytes on all 64-bit platforms */ #ifndef _WIN64 /* LP64 data model */ # if !defined(_TMS320C6X) # define HINT4_8 long /* workaround for preprocessor bug */ # define INT4_8 HINT4_8 # define INT4_8_FORMAT "l" # define INT4_8_MIN LONG_MIN # define INT4_8_MAX LONG_MAX # define UINT4_8_MIN 0UL # define UINT4_8_MAX ULONG_MAX # else /* _TMS320C6X long is really 40Bit, but sizeof(long)=8 */ # define INT4_8 int # define INT4_8_FORMAT "" # define INT4_8_MIN INT_MIN # define INT4_8_MAX INT_MAX # define UINT4_8_MIN 0 # define UINT4_8_MAX UINT_MAX # endif #else /* LLP64 data model */ # define INT4_8 __int64 # define INT4_8_FORMAT "I64" # define INT4_8_MIN _I64_MIN # define INT4_8_MAX _I64_MAX # define UINT4_8_MIN 0UL # define UINT4_8_MAX _UI64_MAX #endif
void create_tuple(tuple,length) or macro CT(tuple,length) Htuple *tuple; Hlong length; /* creates a MIXED_PAR tuple that can hold 'length' entries h */ void create_tuple_type(tuple,length,type) Htuple *tuple; Hlong length; Hlong type /* creates a tuple of 'type' that can hold 'length' entries. * 'type' can hold either LONG_PAR, DOUBLE_PAR, STRING_PAR, * or MIXED_PAR. */ void destroy_tuple(tuple) or macro DT(tuple) Htuple tuple; /* deletes a tuple (if the tuple contains string entries, */ /* the memory allocated by the strings is freed, too) */ Hlong length_tuple(tuple) or macro LT(tuple) Htuple tuple; /* returns the length of a tuple (number of entries) */ void copy_tuple(input,output) or macro CPT(input,output) Htuple input; Htuple *output; /* creates a tuple and copies the entries of the input tuple */ void resize_tuple(htuple,new_length) or macro RT(htuple,new_length) Htuple *htuple; Hlong new_length; /* creates a tuple with the new size and copies the previous entries */ Figure 21.2: HALCON/C Htuple procedures (part one). void create_tuple_i(tuple,value) Htuple *tuple; Hlong val; /* creates a tuple with specifified integer value */ void create_tuple_d(tuple,value) Htuple *tuple; double val; /* creates a tuple with specifified double value */ void create_tuple_d(tuple,value) Htuple *tuple; char *val; /* creates a tuple with specifified string value */ void reuse_tuple_i(tuple,val) Htuple *tuple; Hlong val; /* reuses a tuple with specifified integer value */ void reuse_tuple_d(tuple,val) Htuple *tuple; double val; /* reuses a tuple with specifified double value */ void reuse_tuple_s(tuple,val) Htuple *tuple; char *val; /* reuses a tuple with specifified string value */ Figure 21.3: HALCON/C Htuple procedures (part two).
void set_i(tuple,val,index) or macro SI(tuple,val,index)
Htuple tuple;
Hlong val;
Hlong index;
/* inserts an integer with value 'val' into a tuple at */
/* position 'index' ('index' in [0,length_tuple(tuple) - 1]) */
void set_d(tuple,val,index) or macro SD(tuple,val,index)
Htuple tuple;
double val;
Hlong index;
/* inserts a double with value 'val' into a tuple at */
/* position 'index' ('index' in [0,length_tuple(tuple) - 1]) */
void set_s(tuple,val,index) or macro SS(tuple,val,index)
Htuple tuple;
char *val;
Hlong index;
/* inserts a copy of string 'val' into a tuple at */
/* position 'index' ('index' in [0,length_tuple(tuple) - 1]). */
/* The memory necessary for the string is allocated by set_s. */
int get_type(tuple,index) or macro GT(tuple,index)
Htuple tuple;
Hlong index;
/* returns the type of the value at position 'index' in the */
/* tuple. Possible values: LONG_PAR, DOUBLE_PAR or STRING_PAR */
Hlong get_i(tuple,index) or macro GI(tuple,index)
Htuple tuple;
Hlong index;
/* returns the integer at position 'index' in the tuple */
/* (a type error results in a run time error) */
double get_d(tuple,index) or macro GD(tuple,index)
Htuple tuple;
Hlong index;
/* returns the floating point number at position 'index' in the */
/* tuple. (a type error results in a run time error) */
char *get_s(tuple,index) or macro GS(tuple,index)
Htuple tuple;
Hlong index;
/* returns the pointer(!) to the string at position 'index' in */
/* the tuple. (a type error results in a run time error) */
/* Attention: all indices must be in [0,length_tuple(tuple) - 1] */
Figure 21.4: HALCON/C Htuple procedures (part three).搞定:
原来dll中是有这么个函数可以操作tuple的,包含了创建/设置/销毁.....
import console
console.open()
dll = ..raw.loadDll("\res\halconc.dll","AArHalconC","cdecl");
F_create_tuple= dll.api("F_create_tuple","void(pointer& T, int length)");
F_create_tuple_i= dll.api("F_create_tuple_i","void(pointer T, int val)");
F_create_tuple_s=dll.api("F_create_tuple_s","void(pointer T, string val)");
F_get_s=dll.api("F_get_s","string(pointer T, int index)");
F_set_s=dll.api("F_set_s","void(pointer T, string val,int index)");
F_get_i=dll.api("F_get_i","int(pointer T, int index)");
var ctup = raw.buffer(1000);
F_create_tuple(ctup,5);
//console.varDump(ctup)
//F_create_tuple_i(ctup,5);
//F_create_tuple_s(ctup,"abcde");
console.varDump(ctup)
F_set_s(ctup,"abc",0);
F_set_s(ctup,"def",1);
F_set_s(ctup,"ghi",2);
F_set_s(ctup,"jkl",3);
F_set_s(ctup,"mnu",4);
var ret = F_get_s(ctup,2);
console.varDump(ret)
var ret = F_get_s(ctup,1);
console.varDump(ret)
F_set_s(ctup,"hahabb",1);
var ret = F_get_s(ctup,1);
console.varDump(ret)
var ret = F_get_s(ctup,4);
console.varDump(ret)
console.pause(true);
import console
console.open()
import com;
var HsystemX = com.CreateObject("{6ebd90de-d219-11d2-ade5-0000c00f4ef9}")
var que = com.Variant("processor_num");
var ret = HsystemX.GetSystem( que );
console.varDump(ret)
var que = com.Variant("version");
var ret = HsystemX.GetSystem( que );
console.varDump(ret)
var info //= com.Variant();
var que = com.Variant("processor_num");
var HOperatorSetX = com.CreateObject("{6ebd90e2-d219-11d2-ade5-0000c00f4ef9}")
var ret2 = HOperatorSetX.GetSystem( que ,null);
console.varDump(ret2)
console.pause(true);import com.activeX;
//注册控件
com.activeX.regsvr32("\res\halconx.dll")
//调用控件
mainForm.button4.oncommand = function(id,event){
var filepath = com.Variant("res/double_circle.png");
var Image = HOperatorSetX.ReadImage(null,filepath);
console.varDump(Image)
var ww,ll = HOperatorSetX.GetImageSize(Image,null,null);
console.varDump(ww)
console.varDump(ll)
}halcon的com控件必须要注册才能使用, 用com.lite()不行.
import console
console.open()
//import com.activeX;
import com.lite;
import com;
var comdll = com.lite("\res\halconx.dll");
comdll.registerServer();
//注册控件
//com.activeX.regsvr32("\res\halconx.dll")
//调用控件
mainForm.button.oncommand = function(id,event){
HOperatorSetX = com.CreateObject("{6ebd90e2-d219-11d2-ade5-0000c00f4ef9}")
console.varDump(HOperatorSetX)
var filepath = com.Variant("res/double_circle.png");
var Image = HOperatorSetX.ReadImage(filepath);
//console.varDump(Image)
var ww,ll = HOperatorSetX.GetImageSize(Image);
console.varDump(ww)
console.varDump(ll)
}
mainForm.button2.oncommand = function(id,event){
HImageX = com.CreateObject("{6EBD90E7-D219-11D2-ADE5-0000C00F4EF9}")
var filepath = com.Variant("res/double_circle.png");
HImageX.ReadImage(filepath);
var ww,ll = HImageX.GetImageSize(null,null);
console.varDump(ww)
console.varDump(ll)
}登录后方可回帖


http://www.mvtec.com/doc/halcon/13/en/tuple_type.html