IPType.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /*****************************************************************************
  2. * IPType.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/libhalcon
  6. * Description: Types for image processing and language interfaces
  7. *
  8. * (c) 1996-2020 by MVTec Software GmbH
  9. * www.mvtec.com
  10. *
  11. *****************************************************************************/
  12. #ifndef IPTYPE_H
  13. #define IPTYPE_H
  14. #ifndef HC_NO_STRUCT_MEMBER_ALIGNMENT
  15. /* sets the struct member alignment to avoid problems if
  16. * the settings of the user differ to those of the HALCON
  17. * version. (8 is the default alignment, generally) */
  18. # pragma pack(push, 8)
  19. #endif
  20. #if !defined(HC_LARGE_IMAGES)
  21. typedef int32_t HIMGDIM; /* Image dimension, e.g., width and height */
  22. typedef int16_t HIMGCOOR; /* Image coordinates, e.g, row and column */
  23. typedef int32_t HLINCOOR; /* Linearized image coordinates */
  24. typedef int32_t HIMGCNT; /* Number of pixels, e.g., area or buffer size */
  25. typedef int32_t HITEMCNT; /* Number of elements (contours or runlengths) */
  26. typedef float HSUBCOOR; /* Sub-pixel precise coordinates */
  27. typedef float HSUBATTR; /* Sub-pixel precise attributes of contours */
  28. #else
  29. typedef int32_t HIMGDIM;
  30. typedef int32_t HIMGCOOR;
  31. typedef INT4_8 HLINCOOR;
  32. typedef INT4_8 HIMGCNT;
  33. typedef INT4_8 HITEMCNT;
  34. typedef double HSUBCOOR;
  35. typedef double HSUBATTR;
  36. #endif
  37. /****************************************************************************/
  38. /* Types for images */
  39. /****************************************************************************/
  40. typedef void* (*HImageAllocProc)(size_t size);
  41. typedef void (*HImageFreeProc)(void* mem);
  42. typedef struct
  43. {
  44. float re; /* real part */
  45. float im; /* imaginary part */
  46. } HComplexPixel;
  47. typedef struct
  48. {
  49. int16_t* p; /* pointer to gray vales */
  50. int8_t num_bits; /* number of used bits */
  51. } HInt2Pixel;
  52. typedef struct
  53. {
  54. uint16_t* p; /* pointer to gray vales */
  55. int8_t num_bits; /* number of used bits */
  56. } HUInt2Pixel;
  57. typedef struct
  58. {
  59. float* row; /* row direction */
  60. float* col; /* column direction */
  61. int32_t kind; /* VF_ABSOLUTE or VF_RELATIVE */
  62. } HVFPixel;
  63. typedef union
  64. {
  65. uint8_t* b; /* 0..255 (BYTE_IMAGE) */
  66. uint8_t* z; /* 0..255 mod 256 (CYCLIC_IMAGE) */
  67. uint8_t* d; /* orientation 0..180 (DIR_IMAGE) */
  68. int8_t* i; /* -127..126 (INT1_IMAGE) */
  69. int32_t* l; /* 4 byte integer (LONG_IMAGE) */
  70. int64_t* i8; /* 8 byte integer (INT8_IMAGE) */
  71. float* f; /* 4 byte real (FLOAT_IMAGE) */
  72. HVFPixel vf; /* vector field (VF_IMAGE) */
  73. HComplexPixel* c; /* complex image (COMPLEX_IMAGE) */
  74. HInt2Pixel s; /* 2 bytes with sign (INT2_IMAGE) */
  75. HUInt2Pixel u; /* 2 bytes without sign (UINT2_IMAGE) */
  76. } HPixelImage;
  77. typedef struct
  78. {
  79. int kind; /* pixel type */
  80. HPixelImage pixel; /* pixel data */
  81. HIMGDIM width; /* image width */
  82. HIMGDIM height; /* image height */
  83. HImageFreeProc free_proc; /* function for deallocating image data */
  84. bool free; /* free image data when deleting image */
  85. /* time of creation of image */
  86. uint16_t msec; /* milliseconds 0..999 */
  87. uint8_t sec; /* seconds 0..59 */
  88. uint8_t min; /* minutes 0.59 */
  89. uint8_t hour; /* 0..23 */
  90. uint8_t day; /* 1..31 */
  91. uint16_t yday; /* 1..366 */
  92. uint8_t mon; /* 1..12 */
  93. uint16_t year; /* 19xx */
  94. } Himage;
  95. /* Information file for HALCON image file format (.exp) */
  96. typedef struct
  97. {
  98. int32_t width; /* width of image */
  99. int32_t kind; /* Pixel type */
  100. int32_t height; /* height of image */
  101. char info[1000 - 4]; /* for further use */
  102. } Himage_exp;
  103. /* Information header for HALCON image file format */
  104. typedef struct
  105. {
  106. int32_t version_number; /* version number of the ima file format */
  107. int32_t num_images; /* number of images in file */
  108. bool is_msb_first; /* is most significant bit first (byte order) */
  109. } Himage_hobj_file_header;
  110. /* Information header for HALCON image file format - for each image */
  111. typedef struct
  112. {
  113. int32_t width; /* width of image */
  114. int32_t height; /* height of image */
  115. int32_t num_channels; /* channels in image */
  116. } Himage_hobj_image_header;
  117. typedef uint8_t* Hbits; /* Binary image */
  118. /****************************************************************************/
  119. /* Regionen */
  120. /****************************************************************************/
  121. /* Index range for coordinates of run length regions */
  122. #define MAX_COORD (MAX_FORMAT - 1) /* 2^EXP - 1; EXP=XL? 30: 15 */
  123. /*---------------------------------------------------------------------------*
  124. * Note: We limit MIN_COORD to -2^EXP + 1, instead of -2^EXP, in order to
  125. * ensure that the maximal region dimension
  126. * (MAX_COORD - MIN_COORD + 1) stays below/equal to INT32_MAX in XL:
  127. *
  128. * DIM_MAX = [2^30 - 1] - [-2^30 + 1] + 1 = 2^31 - 1 = INT32_MAX
  129. *---------------------------------------------------------------------------*/
  130. #define MIN_COORD (-MAX_COORD) /* -2^EXP + 1; EXP=XL? 30: 15 */
  131. /* Data type for a single run of a region encoded with runlength encoding */
  132. typedef struct
  133. {
  134. HIMGCOOR l; /* line number (row) of run */
  135. HIMGCOOR cb; /* column index of beginning of run */
  136. HIMGCOOR ce; /* column index of ending of run */
  137. } Hrun;
  138. /* vertical run */
  139. typedef struct
  140. {
  141. HIMGCOOR c; /* column index of run */
  142. HIMGCOOR lb; /* row index of beginning of run */
  143. HIMGCOOR le; /* row index of ending of run */
  144. } Hvrun;
  145. #define SHAPE_RECTANGLE1 (uint8_t)1
  146. #define SHAPE_RECTANGLE2 (uint8_t)2
  147. #define SHAPE_CIRCLE (uint8_t)3
  148. #define SHAPE_ELLIPSE (uint8_t)4
  149. /* Bit-array to check if a feature of a region was calculated */
  150. typedef struct
  151. {
  152. unsigned int shape : 1;
  153. unsigned int is_convex : 1;
  154. unsigned int is_filled : 1;
  155. unsigned int is_connected4 : 1;
  156. unsigned int is_connected8 : 1;
  157. unsigned int is_thin : 1;
  158. unsigned int circularity : 1;
  159. unsigned int compactness : 1;
  160. unsigned int contlength : 1;
  161. unsigned int convexity : 1;
  162. unsigned int phi : 1;
  163. unsigned int elliptic_axis : 1; /* ra, rb */
  164. unsigned int elliptic_shape : 1; /* ra_, rb_ */
  165. unsigned int excentricity : 1; /* anisometry,bulkiness,str_faktor*/
  166. unsigned int moments : 1; /* m11, m20, m02, ia, ib */
  167. unsigned int center_area : 1; /* row, col, area */
  168. unsigned int smallest_rectangle1 : 1; /* row1,col1,row2,col2 */
  169. unsigned int smallest_rectangle2 : 1; /* row_rect, col_rect, phi_rect, */
  170. /* length1, length2 */
  171. unsigned int smallest_circle : 1; /* row_circle, col_circle, radius */
  172. unsigned int min_max_chord : 1; /* longest/shortest run */
  173. unsigned int min_max_chord_gap : 1; /* longest/shortest run (holes) */
  174. unsigned int rectangularity : 1;
  175. } HFeatureFlags;
  176. /* Shape feature caching inside the region structure */
  177. typedef struct
  178. {
  179. union
  180. {
  181. HFeatureFlags single;
  182. long all; /* if possible use 64 bits! */
  183. } def;
  184. uint8_t shape; /* SHAPE_* */
  185. bool is_convex;
  186. bool is_filled;
  187. bool is_connected4;
  188. bool is_connected8;
  189. bool is_thin; /* one pixel thin */
  190. double circularity;
  191. double compactness;
  192. double contlength;
  193. double convexity;
  194. double phi;
  195. double ra, rb; /* elliptic_axis */
  196. double ra_, rb_; /* elliptic_shape */
  197. double anisometry, bulkiness, structure_factor;
  198. double m11, m20, m02, ia, ib;
  199. double row, col;
  200. HIMGCNT area;
  201. HIMGCOOR row1, col1, row2, col2;
  202. double row_rect, col_rect, phi_rect, length1, length2;
  203. double row_circle, col_circle, radius;
  204. HIMGCOOR min_chord, max_chord;
  205. HIMGCOOR min_chord_gap, max_chord_gap;
  206. double rectangularity;
  207. } HRegFeature;
  208. typedef struct
  209. {
  210. bool is_compl; /* region is complement */
  211. HITEMCNT num; /* number of runs */
  212. HITEMCNT num_max; /* maximum number of runs */
  213. HRegFeature feature; /* already processed features */
  214. Hrun* rl; /* pointer on array of run lengths */
  215. } Hrlregion;
  216. /* vertical runlength encoding */
  217. typedef struct
  218. {
  219. bool is_compl; /* region is complement */
  220. HITEMCNT num; /* number of runs */
  221. HITEMCNT num_max; /* maximum number of runs */
  222. HRegFeature feature; /* already processed features */
  223. Hvrun* rc; /* array of runs */
  224. } Hvrlregion;
  225. /* Data structure for fast single pixel access for Hrlregion regions */
  226. typedef struct
  227. {
  228. HIMGCOOR min, max; /* Min/Max row index */
  229. Hrun* rl; /* pointer to runs of the region */
  230. HITEMCNT* first; /* array of index values (row begin) */
  231. HITEMCNT* last; /* array of index values (row end) */
  232. bool* no_row; /* is there this row available? */
  233. } Hrlaccess;
  234. /* Data structure for a multichannel image */
  235. typedef struct
  236. {
  237. Himage* channels; /* Channels of the multichannel image */
  238. Hrlregion* region; /* Domain of the multichannel image */
  239. int num_channels; /* Number of channels of the multichannel image */
  240. } HMultiChannelImage;
  241. /****************************************
  242. *
  243. ****************************************/
  244. /* simple contour with long coordinates and variable allocation length */
  245. typedef struct
  246. {
  247. HIMGCOOR* row; /* row values */
  248. HIMGCOOR* col; /* columns values */
  249. HITEMCNT num; /* length of contour (number of points) */
  250. HITEMCNT max_num; /* allocated points of contour */
  251. } Hcontvar;
  252. /* simple contour with float coordinates and variable allocation length */
  253. typedef struct
  254. {
  255. HSUBCOOR* row; /* row values */
  256. HSUBCOOR* col; /* columns values */
  257. HITEMCNT num; /* length of contour (number of points) */
  258. HITEMCNT max_num; /* allocated points of contour */
  259. } Hfcontvar;
  260. /* Countour as chain code */
  261. typedef struct
  262. {
  263. HIMGCOOR l, c; /* Start point (row,column) */
  264. uint8_t* cc; /* array of chain code */
  265. HITEMCNT num; /* length of contour (number of points) */
  266. } Hchain_code;
  267. /* line (start and end point) */
  268. typedef struct
  269. {
  270. HSUBCOOR row1, col1; /* Start point */
  271. HSUBCOOR row2, col2; /* End point */
  272. } Hline;
  273. /* Array of lines */
  274. typedef struct
  275. {
  276. HITEMCNT num;
  277. Hline* line;
  278. } Hlines;
  279. /****************************************************************************/
  280. /* Distribution */
  281. /****************************************************************************/
  282. #define HISTO_LEN 256
  283. typedef HIMGCNT Hhisto_abs[HISTO_LEN];
  284. typedef double Hhisto_rel[HISTO_LEN];
  285. #define MAX_DISTR (2 * 256 + 1)
  286. #define NULL_DISTR 256
  287. /****************************************************************************/
  288. /* Misc. image processing */
  289. /****************************************************************************/
  290. /* Convolution (Convol and FFT) */
  291. typedef struct
  292. {
  293. int32_t f;
  294. int32_t* gk;
  295. int32_t num_max;
  296. } Hconv_mask_s;
  297. /* 2 dimensional convolution masks */
  298. typedef struct
  299. {
  300. HIMGCOOR min_row, max_row;
  301. HIMGCOOR min_col, max_col;
  302. int32_t norm;
  303. int32_t num;
  304. HIMGCOOR row[MAX_CONVOL];
  305. HIMGCOOR col[MAX_CONVOL];
  306. HLINCOOR koor[MAX_CONVOL];
  307. int32_t m[MAX_CONVOL];
  308. } Hconv_mask_2;
  309. /* 1 dimensional convolution masks */
  310. typedef struct
  311. {
  312. HIMGCOOR min_col, max_col;
  313. int32_t norm;
  314. int32_t num;
  315. HIMGCOOR col[MAX_CONVOL];
  316. int32_t m[MAX_CONVOL];
  317. } Hconv_mask_1;
  318. /* Color (name plus RGB values) */
  319. typedef struct
  320. {
  321. uint8_t red;
  322. uint8_t green;
  323. uint8_t blue;
  324. char name[MAX_COLOR_NAME_LENGTH];
  325. } Hcolor;
  326. /****************************************************************************/
  327. /* Extended Line Description (XLD) */
  328. /****************************************************************************/
  329. /****************************************************************************/
  330. /* XLD-Object Contour */
  331. /****************************************************************************/
  332. typedef enum cont_class
  333. {
  334. cont_unknown, /* unknown */
  335. cont_no_junc, /* neither start nor end point points are junctions */
  336. cont_start_junc, /* start point is a junction */
  337. cont_end_junc, /* end point is a junction */
  338. cont_both_junc, /* both start and end point are junctions */
  339. cont_closed /* closed contour */
  340. } Hcont_class;
  341. typedef struct cont_attrib
  342. {
  343. char* name; /* name of the attribute */
  344. HSUBATTR* val; /* value of the attribute (per point) */
  345. } Hcont_attrib;
  346. typedef struct cont_global_attrib
  347. {
  348. char* name; /* name of the global attribute */
  349. HSUBATTR val; /* value of the attribute (per contour) */
  350. } Hcont_global_attrib;
  351. typedef struct cont_type
  352. {
  353. HITEMCNT num; /* number of points along the contour */
  354. HSUBCOOR* row; /* points / row indices (y coordinates) */
  355. HSUBCOOR* col; /* points / column indices (x coord.) */
  356. Hcont_class cont_class; /* contour class */
  357. int32_t num_attrib; /* number of additional attributes */
  358. Hcont_attrib* attribs; /* additional attributes (for each point) */
  359. int32_t num_global; /* number of additional global attributes */
  360. Hcont_global_attrib* global; /* additional attributes (per contour) */
  361. int32_t h; /* auxiliary (temporary) */
  362. } Hcont;
  363. /****************************************************************************/
  364. /* XLD-Objects: polygons */
  365. /****************************************************************************/
  366. typedef struct lin_seg_type
  367. {
  368. HSUBCOOR row, col; /* control points of the polygon */
  369. HSUBATTR length; /* length of the line from the cur. to the next point */
  370. HSUBATTR phi; /* orientation (rad) of this line */
  371. Hkey ref; /* data base key of the underlying contour */
  372. HITEMCNT first; /* index of the first point of the underlying contour */
  373. HITEMCNT last; /* index of the last contour point */
  374. } Hline_seg;
  375. typedef struct poly_type
  376. {
  377. HITEMCNT num_line; /* number of lines */
  378. HITEMCNT len_line; /* maximum number of lines (size of the array lines) */
  379. Hline_seg* lines; /* control points of the polygon */
  380. } Hpoly;
  381. /****************************************************************************/
  382. /* XLD-Objects: parallels */
  383. /****************************************************************************/
  384. typedef struct para_poly_type
  385. {
  386. Hkey poly1; /* Pointer to 1st polygon of the relation (P1) */
  387. Hkey poly2; /* Pointer to 2nd polygon of the relation (P2) */
  388. HITEMCNT first1; /* Index of the start line segm. of the parallel in P1 */
  389. HITEMCNT last1; /* Index of the end line segment of the parallel in P1 */
  390. HITEMCNT first2; /* Index of the start line segm. of the parallel in P2 */
  391. HITEMCNT last2; /* Index of the end line segment of the parallel in P2 */
  392. double quality; /* Measure of the degree of parallelism of the polygons*/
  393. } Hpara_poly;
  394. /****************************************************************************/
  395. /* XLD-Objects parallel object borders */
  396. /****************************************************************************/
  397. typedef struct mod_para_type
  398. {
  399. Hkey poly1; /* Pointer to 1st polygon of the relation (P1) */
  400. Hkey poly2; /* Pointer to 2nd polygon of the relation (P2) */
  401. HITEMCNT first1; /* Index of the start line segm. of the parallel in P1 */
  402. HITEMCNT last1; /* Index of the end line segment of the parallel in P1 */
  403. HITEMCNT first2; /* Index of the start line segm. of the parallel in P2 */
  404. HITEMCNT last2; /* Index of the end line segment of the parallel in P2 */
  405. HSUBATTR first1_dist; /* Half distance of the first line of P1 to P2 */
  406. HSUBATTR last1_dist; /* Half distance of the last line of P1 to P2 */
  407. HSUBATTR first2_dist; /* Half distance of the first line of P2 to P1 */
  408. HSUBATTR last2_dist; /* Half distance of the last line of P2 to P1 */
  409. int16_t dir1; /* Position of P1 relative to P2: */
  410. /* dir1 = 1: P2 is to the right of P1 */
  411. /* dir1 = -1: P2 is to the left of P1 */
  412. int16_t dir2; /* Position of P2 relative to P1: */
  413. /* dir2 = 1: P1 is to the right of P2 */
  414. /* dir2 = -1: P1 is to the left of P2 */
  415. } Hmod_para;
  416. /****************************************************************************/
  417. /* XLD-Objects Extended object borders */
  418. /****************************************************************************/
  419. typedef struct ext_para_type
  420. {
  421. Hkey poly1; /* Pointer to 1st polygon of the relation (P1) */
  422. Hkey poly2; /* Pointer to 2nd polygon of the relation (P2) */
  423. HITEMCNT first1; /* Index of the start line segm. of the parallel in P1 */
  424. HITEMCNT last1; /* Index of the end line segment of the parallel in P1 */
  425. HITEMCNT first2; /* Index of the start line segm. of the parallel in P2 */
  426. HITEMCNT last2; /* Index of the end line segment of the parallel in P2 */
  427. } Hext_para;
  428. /****************************************************************************/
  429. /* Homogeneous coordiantes: Hhom_mat_[23]d / Hproj_mat_[23]d */
  430. /****************************************************************************/
  431. typedef double Hhom_mat_2d[2][3];
  432. typedef double (
  433. *H_RESTRICT pHhom_mat_2d)[3]; /* pointer type variant of Hhom_mat_2d */
  434. typedef double (*puHhom_mat_2d)
  435. [3]; /* unrestricted pointer type variant of Hhom_mat_2d */
  436. typedef double Hhom_mat_3d[3][4];
  437. typedef double (
  438. *H_RESTRICT pHhom_mat_3d)[4]; /* pointer type variant of Hhom_mat_3d */
  439. typedef double (*puHhom_mat_3d)
  440. [4]; /* unrestricted pointer type variant of Hhom_mat_3d */
  441. typedef double Hproj_mat_2d[3][3];
  442. typedef double (
  443. *H_RESTRICT pHproj_mat_2d)[3]; /* pointer type variant of Hproj_mat_2d */
  444. typedef double (*puHproj_mat_2d)
  445. [3]; /* unrestricted pointer type variant of Hproj_mat_2d */
  446. typedef double Hproj_mat_3d[4][4];
  447. typedef double (
  448. *H_RESTRICT pHproj_mat_3d)[4]; /* pointer type variant of Hproj_mat_3d */
  449. typedef double (*puHproj_mat_3d)
  450. [4]; /* unrestricted pointer type variant of Hproj_mat_3d */
  451. /****************************************************************************/
  452. /* 1D-Functions */
  453. /****************************************************************************/
  454. typedef struct
  455. {
  456. int32_t num; /* Number of elements in x and y */
  457. float* x; /* Array of the x-values of the function (always set) */
  458. float* y; /* Array of the y-values of the function */
  459. float xmin; /* Minimum x value (always set) */
  460. float xmax; /* Maximum x value (always set) */
  461. float xdist; /* Distance of x-values if they are equidistant */
  462. bool is_equidist; /* Are the x-values equidistant? */
  463. } Hfunction_1d;
  464. /****************************************************************************/
  465. /* Parameter passing (inside library and for language interfaces) */
  466. /****************************************************************************/
  467. typedef union
  468. {
  469. INT4_8* l; /* 4-8 Byte integer */
  470. double* f; /* 8 Byte real */
  471. char* s; /* Pointer to string */
  472. } DPHpar; /* For HALCON/C */
  473. typedef union
  474. {
  475. INT4_8 l; /* 4-8 Byte integer */
  476. double f; /* 8 Byte real */
  477. char* s; /* Pointer to string */
  478. } DVHpar; /* For HALCON/C */
  479. /****************************************************************************/
  480. /* Type for callback function for HALCON low level error messages */
  481. /****************************************************************************/
  482. #ifndef _WIN32
  483. # define __stdcall
  484. #endif
  485. typedef void(__stdcall* HLowLevelErrorCallbackProc)(const char* err);
  486. #ifndef HC_NO_STRUCT_MEMBER_ALIGNMENT
  487. # pragma pack(pop) /* unset struct member alignment */
  488. #endif
  489. #endif