/
imlib.h
1359 lines (1189 loc) · 51.5 KB
/
imlib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the OpenMV project.
*
* Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
* Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
*
* This work is licensed under the MIT license, see the file LICENSE for details.
*
* Image processing library.
*/
#ifndef __IMLIB_H__
#define __IMLIB_H__
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <math.h>
#include <arm_math.h>
#include <ff.h>
#include "fb_alloc.h"
#include "umm_malloc.h"
#include "xalloc.h"
#include "array.h"
#include "fmath.h"
#include "collections.h"
#include "imlib_config.h"
#include "omv_boardconfig.h"
#ifndef M_PI
#define M_PI 3.14159265f
#define M_PI_2 1.57079632f
#define M_PI_4 0.78539816f
#endif
#define IM_LOG2_2(x) (((x) & 0x2ULL) ? ( 2 ) : 1) // NO ({ ... }) !
#define IM_LOG2_4(x) (((x) & 0xCULL) ? ( 2 + IM_LOG2_2((x) >> 2)) : IM_LOG2_2(x)) // NO ({ ... }) !
#define IM_LOG2_8(x) (((x) & 0xF0ULL) ? ( 4 + IM_LOG2_4((x) >> 4)) : IM_LOG2_4(x)) // NO ({ ... }) !
#define IM_LOG2_16(x) (((x) & 0xFF00ULL) ? ( 8 + IM_LOG2_8((x) >> 8)) : IM_LOG2_8(x)) // NO ({ ... }) !
#define IM_LOG2_32(x) (((x) & 0xFFFF0000ULL) ? (16 + IM_LOG2_16((x) >> 16)) : IM_LOG2_16(x)) // NO ({ ... }) !
#define IM_LOG2(x) (((x) & 0xFFFFFFFF00000000ULL) ? (32 + IM_LOG2_32((x) >> 32)) : IM_LOG2_32(x)) // NO ({ ... }) !
#define IM_MAX(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
#define IM_MIN(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
#define IM_DIV(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _b ? (_a / _b) : 0; })
#define IM_MOD(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _b ? (_a % _b) : 0; })
#define INT8_T_BITS (sizeof(int8_t) * 8)
#define INT8_T_MASK (INT8_T_BITS - 1)
#define INT8_T_SHIFT IM_LOG2(INT8_T_MASK)
#define INT16_T_BITS (sizeof(int16_t) * 8)
#define INT16_T_MASK (INT16_T_BITS - 1)
#define INT16_T_SHIFT IM_LOG2(INT16_T_MASK)
#define INT32_T_BITS (sizeof(int32_t) * 8)
#define INT32_T_MASK (INT32_T_BITS - 1)
#define INT32_T_SHIFT IM_LOG2(INT32_T_MASK)
#define INT64_T_BITS (sizeof(int64_t) * 8)
#define INT64_T_MASK (INT64_T_BITS - 1)
#define INT64_T_SHIFT IM_LOG2(INT64_T_MASK)
#define UINT8_T_BITS (sizeof(uint8_t) * 8)
#define UINT8_T_MASK (UINT8_T_BITS - 1)
#define UINT8_T_SHIFT IM_LOG2(UINT8_T_MASK)
#define UINT16_T_BITS (sizeof(uint16_t) * 8)
#define UINT16_T_MASK (UINT16_T_BITS - 1)
#define UINT16_T_SHIFT IM_LOG2(UINT16_T_MASK)
#define UINT32_T_BITS (sizeof(uint32_t) * 8)
#define UINT32_T_MASK (UINT32_T_BITS - 1)
#define UINT32_T_SHIFT IM_LOG2(UINT32_T_MASK)
#define UINT64_T_BITS (sizeof(uint64_t) * 8)
#define UINT64_T_MASK (UINT64_T_BITS - 1)
#define UINT64_T_SHIFT IM_LOG2(UINT64_T_MASK)
#define IM_DEG2RAD(x) (((x)*M_PI)/180)
#define IM_RAD2DEG(x) (((x)*180)/M_PI)
/////////////////
// Point Stuff //
/////////////////
typedef struct point {
int16_t x;
int16_t y;
} point_t;
void point_init(point_t *ptr, int x, int y);
void point_copy(point_t *dst, point_t *src);
bool point_equal_fast(point_t *ptr0, point_t *ptr1);
int point_quadrance(point_t *ptr0, point_t *ptr1);
void point_rotate(int x, int y, float r, int center_x, int center_y, int16_t *new_x, int16_t *new_y);
void point_min_area_rectangle(point_t *corners, point_t *new_corners, int corners_len);
////////////////
// Line Stuff //
////////////////
typedef struct line {
int16_t x1;
int16_t y1;
int16_t x2;
int16_t y2;
} line_t;
bool lb_clip_line(line_t *l, int x, int y, int w, int h);
/////////////////////
// Rectangle Stuff //
/////////////////////
typedef struct rectangle {
int16_t x;
int16_t y;
int16_t w;
int16_t h;
} rectangle_t;
void rectangle_init(rectangle_t *ptr, int x, int y, int w, int h);
void rectangle_copy(rectangle_t *dst, rectangle_t *src);
bool rectangle_equal_fast(rectangle_t *ptr0, rectangle_t *ptr1);
bool rectangle_overlap(rectangle_t *ptr0, rectangle_t *ptr1);
void rectangle_intersected(rectangle_t *dst, rectangle_t *src);
void rectangle_united(rectangle_t *dst, rectangle_t *src);
/////////////////
// Color Stuff //
/////////////////
typedef struct color_thresholds_list_lnk_data
{
uint8_t LMin, LMax; // or grayscale
int8_t AMin, AMax;
int8_t BMin, BMax;
}
color_thresholds_list_lnk_data_t;
#define COLOR_THRESHOLD_BINARY(pixel, threshold, invert) \
({ \
__typeof__ (pixel) _pixel = (pixel); \
__typeof__ (threshold) _threshold = (threshold); \
__typeof__ (invert) _invert = (invert); \
((_threshold->LMin <= _pixel) && (_pixel <= _threshold->LMax)) ^ _invert; \
})
#define COLOR_THRESHOLD_GRAYSCALE(pixel, threshold, invert) \
({ \
__typeof__ (pixel) _pixel = (pixel); \
__typeof__ (threshold) _threshold = (threshold); \
__typeof__ (invert) _invert = (invert); \
((_threshold->LMin <= _pixel) && (_pixel <= _threshold->LMax)) ^ _invert; \
})
#define COLOR_THRESHOLD_RGB565(pixel, threshold, invert) \
({ \
__typeof__ (pixel) _pixel = (pixel); \
__typeof__ (threshold) _threshold = (threshold); \
__typeof__ (invert) _invert = (invert); \
uint8_t _l = COLOR_RGB565_TO_L(_pixel); \
int8_t _a = COLOR_RGB565_TO_A(_pixel); \
int8_t _b = COLOR_RGB565_TO_B(_pixel); \
((_threshold->LMin <= _l) && (_l <= _threshold->LMax) && \
(_threshold->AMin <= _a) && (_a <= _threshold->AMax) && \
(_threshold->BMin <= _b) && (_b <= _threshold->BMax)) ^ _invert; \
})
#define COLOR_BOUND_BINARY(pixel0, pixel1, threshold) \
({ \
__typeof__ (pixel0) _pixel0 = (pixel0); \
__typeof__ (pixel1) _pixel1 = (pixel1); \
__typeof__ (threshold) _threshold = (threshold); \
(abs(_pixel0 - _pixel1) <= _threshold); \
})
#define COLOR_BOUND_GRAYSCALE(pixel0, pixel1, threshold) \
({ \
__typeof__ (pixel0) _pixel0 = (pixel0); \
__typeof__ (pixel1) _pixel1 = (pixel1); \
__typeof__ (threshold) _threshold = (threshold); \
(abs(_pixel0 - _pixel1) <= _threshold); \
})
#define COLOR_BOUND_RGB565(pixel0, pixel1, threshold) \
({ \
__typeof__ (pixel0) _pixel0 = (pixel0); \
__typeof__ (pixel1) _pixel1 = (pixel1); \
__typeof__ (threshold) _threshold = (threshold); \
(abs(COLOR_RGB565_TO_R5(_pixel0) - COLOR_RGB565_TO_R5(_pixel1)) <= COLOR_RGB565_TO_R5(_threshold)) && \
(abs(COLOR_RGB565_TO_G6(_pixel0) - COLOR_RGB565_TO_G6(_pixel1)) <= COLOR_RGB565_TO_G6(_threshold)) && \
(abs(COLOR_RGB565_TO_B5(_pixel0) - COLOR_RGB565_TO_B5(_pixel1)) <= COLOR_RGB565_TO_B5(_threshold)); \
})
#define COLOR_BINARY_MIN 0
#define COLOR_BINARY_MAX 1
#define COLOR_GRAYSCALE_BINARY_MIN 0x00
#define COLOR_GRAYSCALE_BINARY_MAX 0xFF
#define COLOR_RGB565_BINARY_MIN 0x0000
#define COLOR_RGB565_BINARY_MAX 0xFFFF
#define COLOR_GRAYSCALE_MIN 0
#define COLOR_GRAYSCALE_MAX 255
#define COLOR_R5_MIN 0
#define COLOR_R5_MAX 31
#define COLOR_G6_MIN 0
#define COLOR_G6_MAX 63
#define COLOR_B5_MIN 0
#define COLOR_B5_MAX 31
#define COLOR_R8_MIN 0
#define COLOR_R8_MAX 255
#define COLOR_G8_MIN 0
#define COLOR_G8_MAX 255
#define COLOR_B8_MIN 0
#define COLOR_B8_MAX 255
#define COLOR_L_MIN 0
#define COLOR_L_MAX 100
#define COLOR_A_MIN -128
#define COLOR_A_MAX 127
#define COLOR_B_MIN -128
#define COLOR_B_MAX 127
#define COLOR_Y_MIN 0
#define COLOR_Y_MAX 255
#define COLOR_U_MIN -128
#define COLOR_U_MAX 127
#define COLOR_V_MIN -128
#define COLOR_V_MAX 127
// RGB565 Stuff //
#define COLOR_RGB565_TO_R5(pixel) (((pixel) >> 11) & 0x1F)
#define COLOR_RGB565_TO_R8(pixel) \
({ \
__typeof__ (pixel) __pixel = (pixel); \
__pixel = (__pixel >> 8) & 0xF8; \
__pixel | (__pixel >> 5); \
})
#define COLOR_RGB565_TO_G6(pixel) (((pixel) >> 5) & 0x3F)
#define COLOR_RGB565_TO_G8(pixel) \
({ \
__typeof__ (pixel) __pixel = (pixel); \
__pixel = (__pixel >> 3) & 0xFC; \
__pixel | (__pixel >> 6); \
})
#define COLOR_RGB565_TO_B5(pixel) ((pixel) & 0x1F)
#define COLOR_RGB565_TO_B8(pixel) \
({ \
__typeof__ (pixel) __pixel = (pixel); \
__pixel = (__pixel << 3) & 0xF8; \
__pixel | (__pixel >> 5); \
})
#define COLOR_R5_G6_B5_TO_RGB565(r5, g6, b5) (((r5) << 11) | ((g6) << 5) | (b5))
#define COLOR_R8_G8_B8_TO_RGB565(r8, g8, b8) ((((r8) & 0xF8) << 8) | (((g8) & 0xFC) << 3) | ((b8) >> 3))
#define COLOR_RGB888_TO_Y(r8, g8, b8) ((((r8) * 38) + ((g8) * 75) + ((b8) * 15)) >> 7) // 0.299R + 0.587G + 0.114B
#define COLOR_RGB565_TO_Y(rgb565) \
({ \
__typeof__ (rgb565) __rgb565 = (rgb565); \
int r = COLOR_RGB565_TO_R8(__rgb565); \
int g = COLOR_RGB565_TO_G8(__rgb565); \
int b = COLOR_RGB565_TO_B8(__rgb565); \
COLOR_RGB888_TO_Y(r, g, b); \
})
#define COLOR_Y_TO_RGB888(pixel) ((pixel) * 0x010101)
#define COLOR_Y_TO_RGB565(pixel) \
({ \
__typeof__ (pixel) __pixel = (pixel); \
int __rb_pixel = (__pixel >> 3) & 0x1F; \
(__rb_pixel * 0x0801) + ((__pixel << 3) & 0x7E0); \
})
#define COLOR_RGB888_TO_U(r8, g8, b8) ((((r8) * -21) - ((g8) * 43) + ((b8) * 64)) >> 7) // -0.168736R - 0.331264G + 0.5B
#define COLOR_RGB565_TO_U(rgb565) \
({ \
__typeof__ (rgb565) __rgb565 = (rgb565); \
int r = COLOR_RGB565_TO_R8(__rgb565); \
int g = COLOR_RGB565_TO_G8(__rgb565); \
int b = COLOR_RGB565_TO_B8(__rgb565); \
COLOR_RGB888_TO_U(r, g, b); \
})
#define COLOR_RGB888_TO_V(r8, g8, b8) ((((r8) * 64) - ((g8) * 54) - ((b8) * 10)) >> 7) // 0.5R - 0.418688G - 0.081312B
#define COLOR_RGB565_TO_V(rgb565) \
({ \
__typeof__ (rgb565) __rgb565 = (rgb565); \
int r = COLOR_RGB565_TO_R8(__rgb565); \
int g = COLOR_RGB565_TO_G8(__rgb565); \
int b = COLOR_RGB565_TO_B8(__rgb565); \
COLOR_RGB888_TO_V(r, g, b); \
})
extern const int8_t lab_table[196608/2];
#ifdef IMLIB_ENABLE_LAB_LUT
#define COLOR_RGB565_TO_L(pixel) lab_table[((pixel>>1) * 3) + 0]
#define COLOR_RGB565_TO_A(pixel) lab_table[((pixel>>1) * 3) + 1]
#define COLOR_RGB565_TO_B(pixel) lab_table[((pixel>>1) * 3) + 2]
#else
#define COLOR_RGB565_TO_L(pixel) imlib_rgb565_to_l(pixel)
#define COLOR_RGB565_TO_A(pixel) imlib_rgb565_to_a(pixel)
#define COLOR_RGB565_TO_B(pixel) imlib_rgb565_to_b(pixel)
#endif
#define COLOR_LAB_TO_RGB565(l, a, b) imlib_lab_to_rgb(l, a, b)
#define COLOR_YUV_TO_RGB565(y, u, v) imlib_yuv_to_rgb((y) + 128, u, v)
#define COLOR_BINARY_TO_GRAYSCALE(pixel) ((pixel) * COLOR_GRAYSCALE_MAX)
#define COLOR_BINARY_TO_RGB565(pixel) COLOR_YUV_TO_RGB565(((pixel) ? 127 : -128), 0, 0)
#define COLOR_RGB565_TO_BINARY(pixel) (COLOR_RGB565_TO_Y(pixel) > (((COLOR_Y_MAX - COLOR_Y_MIN) / 2) + COLOR_Y_MIN))
#define COLOR_RGB565_TO_GRAYSCALE(pixel) COLOR_RGB565_TO_Y(pixel)
#define COLOR_GRAYSCALE_TO_BINARY(pixel) ((pixel) > (((COLOR_GRAYSCALE_MAX - COLOR_GRAYSCALE_MIN) / 2) + COLOR_GRAYSCALE_MIN))
#define COLOR_GRAYSCALE_TO_RGB565(pixel) COLOR_YUV_TO_RGB565(((pixel) - 128), 0, 0)
typedef enum {
COLOR_PALETTE_RAINBOW,
COLOR_PALETTE_IRONBOW
} color_palette_t;
// Color palette LUTs
extern const uint16_t rainbow_table[256];
extern const uint16_t ironbow_table[256];
/////////////////
// Image Stuff //
/////////////////
// Pixel format IDs.
typedef enum {
PIXFORMAT_ID_BINARY = 1,
PIXFORMAT_ID_GRAY = 2,
PIXFORMAT_ID_RGB565 = 3,
PIXFORMAT_ID_BAYER = 4,
PIXFORMAT_ID_YUV422 = 5,
PIXFORMAT_ID_JPEG = 6,
PIXFORMAT_ID_PNG = 7,
PIXFORMAT_ID_ARGB8 = 8,
/* Note: Update PIXFORMAT_IS_VALID when adding new formats */
} pixformat_id_t;
// Pixel sub-format IDs.
typedef enum {
SUBFORMAT_ID_GRAY8 = 0,
SUBFORMAT_ID_GRAY16 = 1,
SUBFORMAT_ID_BGGR = 0, // !!! Note: Make sure bayer sub-formats don't !!!
SUBFORMAT_ID_GBRG = 1, // !!! overflow the sensor.hw_flags.bayer field !!!
SUBFORMAT_ID_GRBG = 2,
SUBFORMAT_ID_RGGB = 3,
SUBFORMAT_ID_YUV422 = 0,
SUBFORMAT_ID_YVU422 = 1,
/* Note: Update PIXFORMAT_IS_VALID when adding new formats */
} subformat_id_t;
// Pixel format Byte Per Pixel.
typedef enum {
PIXFORMAT_BPP_BINARY = 0,
PIXFORMAT_BPP_GRAY8 = 1,
PIXFORMAT_BPP_GRAY16 = 2,
PIXFORMAT_BPP_RGB565 = 2,
PIXFORMAT_BPP_BAYER = 1,
PIXFORMAT_BPP_YUV422 = 2,
PIXFORMAT_BPP_ARGB8 = 4,
/* Note: Update PIXFORMAT_IS_VALID when adding new formats */
} pixformat_bpp_t;
// Pixel format flags.
#define PIXFORMAT_FLAGS_Y (1 << 28) // YUV format.
#define PIXFORMAT_FLAGS_M (1 << 27) // Mutable format.
#define PIXFORMAT_FLAGS_C (1 << 26) // Colored format.
#define PIXFORMAT_FLAGS_J (1 << 25) // Compressed format (JPEG/PNG).
#define PIXFORMAT_FLAGS_R (1 << 24) // RAW/Bayer format.
#define PIXFORMAT_FLAGS_CY (PIXFORMAT_FLAGS_C | PIXFORMAT_FLAGS_Y)
#define PIXFORMAT_FLAGS_CM (PIXFORMAT_FLAGS_C | PIXFORMAT_FLAGS_M)
#define PIXFORMAT_FLAGS_CR (PIXFORMAT_FLAGS_C | PIXFORMAT_FLAGS_R)
#define PIXFORMAT_FLAGS_CJ (PIXFORMAT_FLAGS_C | PIXFORMAT_FLAGS_J)
#define IMLIB_IMAGE_MAX_SIZE(x) ((x) & 0xFFFFFFFF)
// Each pixel format encodes flags, pixel format id and bpp as follows:
// 31......29 28 27 26 25 24 23..........16 15...........8 7.............0
// <RESERVED> YF MF CF JF RF <PIXFORMAT_ID> <SUBFORMAT_ID> <BYTES_PER_PIX>
// NOTE: Bit 31-30 must Not be used for pixformat_t to be used as mp_int_t.
typedef enum {
PIXFORMAT_INVALID = (0x00000000U),
PIXFORMAT_BINARY = (PIXFORMAT_FLAGS_M | (PIXFORMAT_ID_BINARY << 16) | (0 << 8) | PIXFORMAT_BPP_BINARY ),
PIXFORMAT_GRAYSCALE = (PIXFORMAT_FLAGS_M | (PIXFORMAT_ID_GRAY << 16) | (SUBFORMAT_ID_GRAY8 << 8) | PIXFORMAT_BPP_GRAY8 ),
PIXFORMAT_RGB565 = (PIXFORMAT_FLAGS_CM | (PIXFORMAT_ID_RGB565 << 16) | (0 << 8) | PIXFORMAT_BPP_RGB565 ),
PIXFORMAT_ARGB8 = (PIXFORMAT_FLAGS_CM | (PIXFORMAT_ID_ARGB8 << 16) | (0 << 8) | PIXFORMAT_BPP_ARGB8 ),
PIXFORMAT_BAYER = (PIXFORMAT_FLAGS_CR | (PIXFORMAT_ID_BAYER << 16) | (SUBFORMAT_ID_BGGR << 8) | PIXFORMAT_BPP_BAYER ),
PIXFORMAT_BAYER_BGGR = (PIXFORMAT_FLAGS_CR | (PIXFORMAT_ID_BAYER << 16) | (SUBFORMAT_ID_BGGR << 8) | PIXFORMAT_BPP_BAYER ),
PIXFORMAT_BAYER_GBRG = (PIXFORMAT_FLAGS_CR | (PIXFORMAT_ID_BAYER << 16) | (SUBFORMAT_ID_GBRG << 8) | PIXFORMAT_BPP_BAYER ),
PIXFORMAT_BAYER_GRBG = (PIXFORMAT_FLAGS_CR | (PIXFORMAT_ID_BAYER << 16) | (SUBFORMAT_ID_GRBG << 8) | PIXFORMAT_BPP_BAYER ),
PIXFORMAT_BAYER_RGGB = (PIXFORMAT_FLAGS_CR | (PIXFORMAT_ID_BAYER << 16) | (SUBFORMAT_ID_RGGB << 8) | PIXFORMAT_BPP_BAYER ),
PIXFORMAT_YUV = (PIXFORMAT_FLAGS_CY | (PIXFORMAT_ID_YUV422 << 16) | (SUBFORMAT_ID_YUV422 << 8) | PIXFORMAT_BPP_YUV422 ),
PIXFORMAT_YUV422 = (PIXFORMAT_FLAGS_CY | (PIXFORMAT_ID_YUV422 << 16) | (SUBFORMAT_ID_YUV422 << 8) | PIXFORMAT_BPP_YUV422 ),
PIXFORMAT_YVU422 = (PIXFORMAT_FLAGS_CY | (PIXFORMAT_ID_YUV422 << 16) | (SUBFORMAT_ID_YVU422 << 8) | PIXFORMAT_BPP_YUV422 ),
PIXFORMAT_JPEG = (PIXFORMAT_FLAGS_CJ | (PIXFORMAT_ID_JPEG << 16) | (0 << 8) | 0 ),
PIXFORMAT_PNG = (PIXFORMAT_FLAGS_CJ | (PIXFORMAT_ID_PNG << 16) | (0 << 8) | 0 ),
PIXFORMAT_LAST = (0xFFFFFFFFU),
} pixformat_t;
#define PIXFORMAT_MUTABLE_ANY \
PIXFORMAT_BINARY: \
case PIXFORMAT_GRAYSCALE: \
case PIXFORMAT_RGB565: \
case PIXFORMAT_ARGB8 \
#define PIXFORMAT_BAYER_ANY \
PIXFORMAT_BAYER_BGGR: \
case PIXFORMAT_BAYER_GBRG: \
case PIXFORMAT_BAYER_GRBG: \
case PIXFORMAT_BAYER_RGGB \
#define PIXFORMAT_YUV_ANY \
PIXFORMAT_YUV422: \
case PIXFORMAT_YVU422 \
#define PIXFORMAT_COMPRESSED_ANY \
PIXFORMAT_JPEG: \
case PIXFORMAT_PNG \
#define IMLIB_PIXFORMAT_IS_VALID(x) \
((x == PIXFORMAT_BINARY) \
|| (x == PIXFORMAT_GRAYSCALE) \
|| (x == PIXFORMAT_RGB565) \
|| (x == PIXFORMAT_ARGB8) \
|| (x == PIXFORMAT_BAYER_BGGR) \
|| (x == PIXFORMAT_BAYER_GBRG) \
|| (x == PIXFORMAT_BAYER_GRBG) \
|| (x == PIXFORMAT_BAYER_RGGB) \
|| (x == PIXFORMAT_YUV422) \
|| (x == PIXFORMAT_YVU422) \
|| (x == PIXFORMAT_JPEG) \
|| (x == PIXFORMAT_PNG)) \
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define PIXFORMAT_STRUCT \
struct { \
union { \
struct { \
uint32_t bpp :8; \
uint32_t subfmt_id :8; \
uint32_t pixfmt_id :8; \
uint32_t is_bayer :1; \
uint32_t is_compressed :1; \
uint32_t is_color :1; \
uint32_t is_mutable :1; \
uint32_t is_yuv :1; \
uint32_t /*reserved*/ :3; \
}; \
uint32_t pixfmt; \
}; \
uint32_t size; /* for compressed images */ \
}
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define PIXFORMAT_STRUCT \
struct { \
union { \
struct { \
uint32_t /*reserved*/ :3; \
uint32_t is_yuv :1; \
uint32_t is_mutable :1; \
uint32_t is_color :1; \
uint32_t is_compressed :1; \
uint32_t is_bayer :1; \
uint32_t pixfmt_id :8; \
uint32_t subfmt_id :8; \
uint32_t bpp :8; \
}; \
uint32_t pixfmt; \
}; \
uint32_t size; /* for compressed images */ \
}
#else
#error "Byte order is not defined."
#endif
typedef struct image {
uint32_t w;
uint32_t h;
PIXFORMAT_STRUCT;
union {
uint8_t *pixels;
uint8_t *data;
};
} image_t;
void image_init(image_t *ptr, int w, int h, pixformat_t pixfmt, uint32_t size, void *pixels);
void image_copy(image_t *dst, image_t *src);
size_t image_size(image_t *ptr);
bool image_get_mask_pixel(image_t *ptr, int x, int y);
#define IMAGE_BINARY_LINE_LEN(image) (((image)->w + UINT32_T_MASK) >> UINT32_T_SHIFT)
#define IMAGE_BINARY_LINE_LEN_BYTES(image) (IMAGE_BINARY_LINE_LEN(image) * sizeof(uint32_t))
#define IMAGE_GRAYSCALE_LINE_LEN(image) ((image)->w)
#define IMAGE_GRAYSCALE_LINE_LEN_BYTES(image) (IMAGE_GRAYSCALE_LINE_LEN(image) * sizeof(uint8_t))
#define IMAGE_RGB565_LINE_LEN(image) ((image)->w)
#define IMAGE_RGB565_LINE_LEN_BYTES(image) (IMAGE_RGB565_LINE_LEN(image) * sizeof(uint16_t))
#define IMAGE_GET_BINARY_PIXEL(image, x, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
(((uint32_t *) _image->data)[(((_image->w + UINT32_T_MASK) >> UINT32_T_SHIFT) * _y) + (_x >> UINT32_T_SHIFT)] >> (_x & UINT32_T_MASK)) & 1; \
})
#define IMAGE_PUT_BINARY_PIXEL(image, x, y, v) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (v) _v = (v); \
size_t _i = (((_image->w + UINT32_T_MASK) >> UINT32_T_SHIFT) * _y) + (_x >> UINT32_T_SHIFT); \
size_t _j = _x & UINT32_T_MASK; \
((uint32_t *) _image->data)[_i] = (((uint32_t *) _image->data)[_i] & (~(1 << _j))) | ((_v & 1) << _j); \
})
#define IMAGE_CLEAR_BINARY_PIXEL(image, x, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint32_t *) _image->data)[(((_image->w + UINT32_T_MASK) >> UINT32_T_SHIFT) * _y) + (_x >> UINT32_T_SHIFT)] &= ~(1 << (_x & UINT32_T_MASK)); \
})
#define IMAGE_SET_BINARY_PIXEL(image, x, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint32_t *) _image->data)[(((_image->w + UINT32_T_MASK) >> UINT32_T_SHIFT) * _y) + (_x >> UINT32_T_SHIFT)] |= 1 << (_x & UINT32_T_MASK); \
})
#define IMAGE_GET_GRAYSCALE_PIXEL(image, x, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint8_t *) _image->data)[(_image->w * _y) + _x]; \
})
#define IMAGE_PUT_GRAYSCALE_PIXEL(image, x, y, v) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (v) _v = (v); \
((uint8_t *) _image->data)[(_image->w * _y) + _x] = _v; \
})
#define IMAGE_GET_RGB565_PIXEL(image, x, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint16_t *) _image->data)[(_image->w * _y) + _x]; \
})
#define IMAGE_PUT_RGB565_PIXEL(image, x, y, v) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (v) _v = (v); \
((uint16_t *) _image->data)[(_image->w * _y) + _x] = _v; \
})
#define IMAGE_GET_YUV_PIXEL(image, x, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint16_t *) _image->data)[(_image->w * _y) + _x]; \
})
#define IMAGE_PUT_YUV_PIXEL(image, x, y, v) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (v) _v = (v); \
((uint16_t *) _image->data)[(_image->w * _y) + _x] = _v; \
})
#define IMAGE_GET_BAYER_PIXEL(image, x, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint8_t *) _image->data)[(_image->w * _y) + _x]; \
})
#define IMAGE_PUT_BAYER_PIXEL(image, x, y, v) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (v) _v = (v); \
((uint8_t *) _image->data)[(_image->w * _y) + _x] = _v; \
})
// Fast Stuff //
#define IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(image, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (y) _y = (y); \
((uint32_t *) _image->data) + (((_image->w + UINT32_T_MASK) >> UINT32_T_SHIFT) * _y); \
})
#define IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x) \
({ \
__typeof__ (row_ptr) _row_ptr = (row_ptr); \
__typeof__ (x) _x = (x); \
(_row_ptr[_x >> UINT32_T_SHIFT] >> (_x & UINT32_T_MASK)) & 1; \
})
#define IMAGE_PUT_BINARY_PIXEL_FAST(row_ptr, x, v) \
({ \
__typeof__ (row_ptr) _row_ptr = (row_ptr); \
__typeof__ (x) _x = (x); \
__typeof__ (v) _v = (v); \
size_t _i = _x >> UINT32_T_SHIFT; \
size_t _j = _x & UINT32_T_MASK; \
_row_ptr[_i] = (_row_ptr[_i] & (~(1 << _j))) | ((_v & 1) << _j); \
})
#define IMAGE_CLEAR_BINARY_PIXEL_FAST(row_ptr, x) \
({ \
__typeof__ (row_ptr) _row_ptr = (row_ptr); \
__typeof__ (x) _x = (x); \
_row_ptr[_x >> UINT32_T_SHIFT] &= ~(1 << (_x & UINT32_T_MASK)); \
})
#define IMAGE_SET_BINARY_PIXEL_FAST(row_ptr, x) \
({ \
__typeof__ (row_ptr) _row_ptr = (row_ptr); \
__typeof__ (x) _x = (x); \
_row_ptr[_x >> UINT32_T_SHIFT] |= 1 << (_x & UINT32_T_MASK); \
})
#define IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(image, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (y) _y = (y); \
((uint8_t *) _image->data) + (_image->w * _y); \
})
#define IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x) \
({ \
__typeof__ (row_ptr) _row_ptr = (row_ptr); \
__typeof__ (x) _x = (x); \
_row_ptr[_x]; \
})
#define IMAGE_PUT_GRAYSCALE_PIXEL_FAST(row_ptr, x, v) \
({ \
__typeof__ (row_ptr) _row_ptr = (row_ptr); \
__typeof__ (x) _x = (x); \
__typeof__ (v) _v = (v); \
_row_ptr[_x] = _v; \
})
#define IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(image, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (y) _y = (y); \
((uint16_t *) _image->data) + (_image->w * _y); \
})
#define IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x) \
({ \
__typeof__ (row_ptr) _row_ptr = (row_ptr); \
__typeof__ (x) _x = (x); \
_row_ptr[_x]; \
})
#define IMAGE_PUT_RGB565_PIXEL_FAST(row_ptr, x, v) \
({ \
__typeof__ (row_ptr) _row_ptr = (row_ptr); \
__typeof__ (x) _x = (x); \
__typeof__ (v) _v = (v); \
_row_ptr[_x] = _v; \
})
#define IMAGE_COMPUTE_BAYER_PIXEL_ROW_PTR(image, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (y) _y = (y); \
((uint8_t *) _image->data) + (_image->w * _y); \
})
#define IMAGE_COMPUTE_YUV_PIXEL_ROW_PTR(image, y) \
({ \
__typeof__ (image) _image = (image); \
__typeof__ (y) _y = (y); \
((uint16_t *) _image->data) + (_image->w * _y); \
})
// Old Image Macros - Will be refactor and removed. But, only after making sure through testing new macros work.
// Image kernels
extern const int8_t kernel_gauss_3[9];
extern const int8_t kernel_gauss_5[25];
extern const int kernel_laplacian_3[9];
extern const int kernel_high_pass_3[9];
// Grayscale maxes
#define IM_MAX_GS (255)
#define IM_IS_BINARY(img) ((img)->pixfmt == PIXFORMAT_BINARY)
#define IM_IS_GS(img) ((img)->pixfmt == PIXFORMAT_GRAYSCALE)
#define IM_IS_RGB565(img) ((img)->pixfmt == PIXFORMAT_RGB565)
#define IM_IS_BAYER(img) ((img)->is_bayer)
#define IM_IS_JPEG(img) ((img)->pixfmt == PIXFORMAT_JPEG)
#define IM_X_INSIDE(img, x) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
(0<=_x)&&(_x<_img->w); })
#define IM_Y_INSIDE(img, y) \
({ __typeof__ (img) _img = (img); \
__typeof__ (y) _y = (y); \
(0<=_y)&&(_y<_img->h); })
#define IM_GET_GS_PIXEL(img, x, y) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint8_t*)_img->pixels)[(_y*_img->w)+_x]; })
#define IM_GET_RGB565_PIXEL(img, x, y) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
((uint16_t*)_img->pixels)[(_y*_img->w)+_x]; })
#define IM_SET_GS_PIXEL(img, x, y, p) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (p) _p = (p); \
((uint8_t*)_img->pixels)[(_y*_img->w)+_x]=_p; })
#define IM_SET_RGB565_PIXEL(img, x, y, p) \
({ __typeof__ (img) _img = (img); \
__typeof__ (x) _x = (x); \
__typeof__ (y) _y = (y); \
__typeof__ (p) _p = (p); \
((uint16_t*)_img->pixels)[(_y*_img->w)+_x]=_p; })
#define IM_EQUAL(img0, img1) \
({ __typeof__ (img0) _img0 = (img0); \
__typeof__ (img1) _img1 = (img1); \
(_img0->w==_img1->w)&&(_img0->h==_img1->h)&&(_img0->pixfmt=_img1->pixfmt); })
#define IM_TO_GS_PIXEL(img, x, y) \
(img->bpp == 1 ? img->pixels[((y)*img->w)+(x)] : COLOR_RGB565_TO_Y(((uint16_t*)img->pixels)[((y)*img->w)+(x)]) )
typedef struct simple_color {
uint8_t G; // Gray
union {
int8_t L; // LAB L
uint8_t red; // RGB888 Red
};
union {
int8_t A; // LAB A
uint8_t green; // RGB888 Green
};
union {
int8_t B; // LAB B
uint8_t blue; // RGB888 Blue
};
} simple_color_t;
typedef struct integral_image {
int w;
int h;
uint32_t *data;
} i_image_t;
typedef struct {
int w;
int h;
int y_offs;
int x_ratio;
int y_ratio;
uint32_t **data;
uint32_t **swap;
} mw_image_t;
typedef struct _vector {
float x;
float y;
float m;
uint16_t cx,cy;
} vec_t;
typedef struct cluster {
int x, y, w, h;
array_t *points;
} cluster_t;
// Return the distance between a cluster centroid and some object.
typedef float (*cluster_dist_t)(int cx, int cy, void *obj);
/* Keypoint */
typedef struct kp {
uint16_t x;
uint16_t y;
uint16_t score;
uint16_t octave;
uint16_t angle;
uint16_t matched;
uint8_t desc[32];
} kp_t;
typedef struct size {
int w;
int h;
} wsize_t;
/* Haar cascade struct */
typedef struct cascade {
int std; // Image standard deviation.
int step; // Image scanning factor.
float threshold; // Detection threshold.
float scale_factor; // Image scaling factor.
int n_stages; // Number of stages in the cascade.
int n_features; // Number of features in the cascade.
int n_rectangles; // Number of rectangles in the cascade.
struct size window; // Detection window size.
struct image *img; // Grayscale image.
mw_image_t *sum; // Integral image.
mw_image_t *ssq; // Squared integral image.
uint8_t *stages_array; // Number of features per stage.
int16_t *stages_thresh_array; // Stages thresholds.
int16_t *tree_thresh_array; // Features threshold (1 per feature).
int16_t *alpha1_array; // Alpha1 array (1 per feature).
int16_t *alpha2_array; // Alpha2 array (1 per feature).
int8_t *num_rectangles_array; // Number of rectangles per features (1 per feature).
int8_t *weights_array; // Rectangles weights (1 per rectangle).
int8_t *rectangles_array; // Rectangles array.
} cascade_t;
typedef struct bmp_read_settings {
int32_t bmp_w;
int32_t bmp_h;
uint16_t bmp_bpp;
uint32_t bmp_fmt;
uint32_t bmp_row_bytes;
} bmp_read_settings_t;
typedef struct ppm_read_settings {
uint8_t read_int_c;
bool read_int_c_valid;
uint8_t ppm_fmt;
} ppm_read_settings_t;
typedef struct jpg_read_settings {
int32_t jpg_w;
int32_t jpg_h;
int32_t jpg_size;
} jpg_read_settings_t;
typedef struct png_read_settings {
int32_t png_w;
int32_t png_h;
int32_t png_size;
} png_read_settings_t;
typedef enum save_image_format {
FORMAT_DONT_CARE,
FORMAT_BMP,
FORMAT_PNM,
FORMAT_JPG,
FORMAT_PNG,
FORMAT_RAW,
} save_image_format_t;
typedef struct img_read_settings {
union {
bmp_read_settings_t bmp_rs;
ppm_read_settings_t ppm_rs;
jpg_read_settings_t jpg_rs;
png_read_settings_t png_rs;
};
save_image_format_t format;
} img_read_settings_t;
typedef void (*line_op_t)(image_t*, int, void*, void*, bool);
typedef void (*flood_fill_call_back_t)(image_t *, int, int, int, void *);
typedef enum descriptor_type {
DESC_LBP,
DESC_ORB,
} descriptor_t;
typedef enum edge_detector_type {
EDGE_CANNY,
EDGE_SIMPLE,
} edge_detector_t;
typedef enum template_match {
SEARCH_EX, // Exhaustive search
SEARCH_DS, // Diamond search
} template_match_t;
typedef enum jpeg_subsample {
JPEG_SUBSAMPLE_1x1 = 0x11, // 1x1 chroma subsampling (No subsampling)
JPEG_SUBSAMPLE_2x1 = 0x21, // 2x2 chroma subsampling
JPEG_SUBSAMPLE_2x2 = 0x22, // 2x2 chroma subsampling
} jpeg_subsample_t;
typedef enum corner_detector_type {
CORNER_FAST,
CORNER_AGAST
} corner_detector_t;
typedef struct histogram {
int LBinCount;
float *LBins;
int ABinCount;
float *ABins;
int BBinCount;
float *BBins;
} histogram_t;
typedef struct percentile {
uint8_t LValue;
int8_t AValue;
int8_t BValue;
} percentile_t;
typedef struct threshold {
uint8_t LValue;
int8_t AValue;
int8_t BValue;
} threshold_t;
typedef struct statistics {
uint8_t LMean, LMedian, LMode, LSTDev, LMin, LMax, LLQ, LUQ;
int8_t AMean, AMedian, AMode, ASTDev, AMin, AMax, ALQ, AUQ;
int8_t BMean, BMedian, BMode, BSTDev, BMin, BMax, BLQ, BUQ;
} statistics_t;
#define FIND_BLOBS_CORNERS_RESOLUTION 20 // multiple of 4
#define FIND_BLOBS_ANGLE_RESOLUTION (360 / FIND_BLOBS_CORNERS_RESOLUTION)
typedef struct find_blobs_list_lnk_data {
point_t corners[FIND_BLOBS_CORNERS_RESOLUTION];
rectangle_t rect;
uint32_t pixels, perimeter, code, count;
float centroid_x, centroid_y, rotation, roundness;
uint16_t x_hist_bins_count, y_hist_bins_count, *x_hist_bins, *y_hist_bins;
float centroid_x_acc, centroid_y_acc, rotation_acc_x, rotation_acc_y, roundness_acc;
} find_blobs_list_lnk_data_t;
typedef struct find_lines_list_lnk_data {
line_t line;
uint32_t magnitude;
int16_t theta, rho;
} find_lines_list_lnk_data_t;
typedef struct find_circles_list_lnk_data {
point_t p;
uint16_t r, magnitude;
} find_circles_list_lnk_data_t;
typedef struct find_rects_list_lnk_data {
point_t corners[4];
rectangle_t rect;
uint32_t magnitude;
} find_rects_list_lnk_data_t;
typedef struct find_qrcodes_list_lnk_data {
point_t corners[4];
rectangle_t rect;
size_t payload_len;
char *payload;
uint8_t version, ecc_level, mask, data_type;
uint32_t eci;
} find_qrcodes_list_lnk_data_t;
typedef enum apriltag_families {
TAG16H5 = 1,