-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcxtypes.h
1791 lines (1436 loc) · 51.8 KB
/
cxtypes.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
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_CORE_TYPES_H__
#define __OPENCV_CORE_TYPES_H__
#if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300
#define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
#endif
#ifndef SKIP_INCLUDES
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#if !defined _MSC_VER && !defined __BORLANDC__
#include <stdint.h>
#endif
#if defined __ICL
#define CV_ICC __ICL
#elif defined __ICC
#define CV_ICC __ICC
#elif defined __ECL
#define CV_ICC __ECL
#elif defined __ECC
#define CV_ICC __ECC
#elif defined __INTEL_COMPILER
#define CV_ICC __INTEL_COMPILER
#endif
#if (_MSC_VER >= 1400 && defined _M_X64) || (__GNUC__ >= 4 && defined __x86_64__)
#if defined WIN64
#include <intrin.h>
#endif
#include <emmintrin.h>
#endif
#if defined __BORLANDC__
#include <fastmath.h>
#else
#include <math.h>
#endif
#ifdef HAVE_IPL
#ifndef __IPL_H__
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
#include <ipl.h>
#else
#include <ipl/ipl.h>
#endif
#endif
#elif defined __IPL_H__
#define HAVE_IPL
#endif
#endif // SKIP_INCLUDES
#if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
#define CV_CDECL __cdecl
#define CV_STDCALL __stdcall
#else
#define CV_CDECL
#define CV_STDCALL
#endif
#ifndef CV_EXTERN_C
#ifdef __cplusplus
#define CV_EXTERN_C extern "C"
#define CV_DEFAULT(val) = val
#else
#define CV_EXTERN_C
#define CV_DEFAULT(val)
#endif
#endif
#ifndef CV_EXTERN_C_FUNCPTR
#ifdef __cplusplus
#define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
#else
#define CV_EXTERN_C_FUNCPTR(x) typedef x
#endif
#endif
#ifndef CV_INLINE
#if defined __cplusplus
#define CV_INLINE inline
#elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined WINCE) && !defined __GNUC__
#define CV_INLINE __inline
#else
#define CV_INLINE static
#endif
#endif /* CV_INLINE */
#if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined WINCE) && defined CVAPI_EXPORTS
#define CV_EXPORTS __declspec(dllexport)
#else
#define CV_EXPORTS
#endif
#ifndef CVAPI
#define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
#endif
#if defined _MSC_VER || defined __BORLANDC__
typedef __int64 int64;
typedef unsigned __int64 uint64;
#else
typedef int64_t int64;
typedef uint64_t uint64;
#endif
#ifndef HAVE_IPL
typedef unsigned char uchar;
typedef unsigned short ushort;
#endif
typedef signed char schar;
/* CvArr* is used to pass arbitrary
* array-like data structures
* into functions where the particular
* array type is recognized at runtime:
*/
typedef void CvArr;
typedef union Cv32suf
{
int i;
unsigned u;
float f;
}
Cv32suf;
typedef union Cv64suf
{
int64 i;
uint64 u;
double f;
}
Cv64suf;
/****************************************************************************************\
* Common macros and inline functions *
\****************************************************************************************/
#define CV_PI 3.1415926535897932384626433832795
#define CV_LOG2 0.69314718055994530941723212145818
#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
#ifndef MIN
#define MIN(a,b) ((a) > (b) ? (b) : (a))
#endif
#ifndef MAX
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#endif
/* min & max without jumps */
#define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
#define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
/* absolute value without jumps */
#ifndef __cplusplus
#define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
#else
#define CV_IABS(a) abs(a)
#endif
#define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
#define CV_SIGN(a) CV_CMP((a),0)
CV_INLINE int cvRound( double value )
{
#if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && !defined __APPLE__)
__m128d t = _mm_set_sd( value );
return _mm_cvtsd_si32(t);
#elif defined _MSC_VER && defined _M_IX86
int t;
__asm
{
fld value;
fistp t;
}
return t;
#elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__
return (int)lrint(value);
#else
// while this is not IEEE754-compliant rounding, it's usually a good enough approximation
return (int)(value + (value >= 0 ? 0.5 : -0.5));
#endif
}
CV_INLINE int cvFloor( double value )
{
#ifdef __GNUC__
int i = (int)value;
return i - (i > value);
#elif defined _MSC_VER && defined _M_X64
__m128d t = _mm_set_sd( value );
int i = _mm_cvtsd_si32(t);
return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i)));
#else
int i = cvRound(value);
Cv32suf diff;
diff.f = (float)(value - i);
return i - (diff.i < 0);
#endif
}
CV_INLINE int cvCeil( double value )
{
#ifdef __GNUC__
int i = (int)value;
return i + (i < value);
#elif defined _MSC_VER && defined _M_X64
__m128d t = _mm_set_sd( value );
int i = _mm_cvtsd_si32(t);
return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t));
#else
int i = cvRound(value);
Cv32suf diff;
diff.f = (float)(i - value);
return i + (diff.i < 0);
#endif
}
#define cvInvSqrt(value) ((float)(1./sqrt(value)))
#define cvSqrt(value) ((float)sqrt(value))
CV_INLINE int cvIsNaN( double value )
{
#if 1/*defined _MSC_VER || defined __BORLANDC__
return _isnan(value);
#elif defined __GNUC__
return isnan(value);
#else*/
Cv64suf ieee754;
ieee754.f = value;
return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) +
((unsigned)ieee754.u != 0) > 0x7ff00000;
#endif
}
CV_INLINE int cvIsInf( double value )
{
#if 1/*defined _MSC_VER || defined __BORLANDC__
return !_finite(value);
#elif defined __GNUC__
return isinf(value);
#else*/
Cv64suf ieee754;
ieee754.f = value;
return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
(unsigned)ieee754.u == 0;
#endif
}
/*************** Random number generation *******************/
typedef uint64 CvRNG;
CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
{
CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1;
return rng;
}
/* Return random 32-bit unsigned integer: */
CV_INLINE unsigned cvRandInt( CvRNG* rng )
{
uint64 temp = *rng;
temp = (uint64)(unsigned)temp*4164903690U + (temp >> 32);
*rng = temp;
return (unsigned)temp;
}
/* Returns random floating-point number between 0 and 1: */
CV_INLINE double cvRandReal( CvRNG* rng )
{
return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */;
}
/****************************************************************************************\
* Image type (IplImage) *
\****************************************************************************************/
#ifndef HAVE_IPL
/*
* The following definitions (until #endif)
* is an extract from IPL headers.
* Copyright (c) 1995 Intel Corporation.
*/
#define IPL_DEPTH_SIGN 0x80000000
#define IPL_DEPTH_1U 1
#define IPL_DEPTH_8U 8
#define IPL_DEPTH_16U 16
#define IPL_DEPTH_32F 32
#define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)
#define IPL_DATA_ORDER_PIXEL 0
#define IPL_DATA_ORDER_PLANE 1
#define IPL_ORIGIN_TL 0
#define IPL_ORIGIN_BL 1
#define IPL_ALIGN_4BYTES 4
#define IPL_ALIGN_8BYTES 8
#define IPL_ALIGN_16BYTES 16
#define IPL_ALIGN_32BYTES 32
#define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES
#define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES
#define IPL_BORDER_CONSTANT 0
#define IPL_BORDER_REPLICATE 1
#define IPL_BORDER_REFLECT 2
#define IPL_BORDER_WRAP 3
typedef struct _IplImage
{
int nSize; /* sizeof(IplImage) */
int ID; /* version (=0)*/
int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */
int alphaChannel; /* Ignored by OpenCV */
int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,
IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */
char colorModel[4]; /* Ignored by OpenCV */
char channelSeq[4]; /* ditto */
int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels.
cvCreateImage can only create interleaved images */
int origin; /* 0 - top-left origin,
1 - bottom-left origin (Windows bitmaps style). */
int align; /* Alignment of image rows (4 or 8).
OpenCV ignores it and uses widthStep instead. */
int width; /* Image width in pixels. */
int height; /* Image height in pixels. */
struct _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */
struct _IplImage *maskROI; /* Must be NULL. */
void *imageId; /* " " */
struct _IplTileInfo *tileInfo; /* " " */
int imageSize; /* Image data size in bytes
(==image->height*image->widthStep
in case of interleaved data)*/
char *imageData; /* Pointer to aligned image data. */
int widthStep; /* Size of aligned image row in bytes. */
int BorderMode[4]; /* Ignored by OpenCV. */
int BorderConst[4]; /* Ditto. */
char *imageDataOrigin; /* Pointer to very origin of image data
(not necessarily aligned) -
needed for correct deallocation */
}
IplImage;
typedef struct _IplTileInfo IplTileInfo;
typedef struct _IplROI
{
int coi; /* 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/
int xOffset;
int yOffset;
int width;
int height;
}
IplROI;
typedef struct _IplConvKernel
{
int nCols;
int nRows;
int anchorX;
int anchorY;
int *values;
int nShiftR;
}
IplConvKernel;
typedef struct _IplConvKernelFP
{
int nCols;
int nRows;
int anchorX;
int anchorY;
float *values;
}
IplConvKernelFP;
#define IPL_IMAGE_HEADER 1
#define IPL_IMAGE_DATA 2
#define IPL_IMAGE_ROI 4
#endif/*HAVE_IPL*/
/* extra border mode */
#define IPL_BORDER_REFLECT_101 4
#define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage))
#define CV_TYPE_NAME_IMAGE "opencv-image"
#define CV_IS_IMAGE_HDR(img) \
((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage))
#define CV_IS_IMAGE(img) \
(CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL)
/* for storing double-precision
floating point data in IplImage's */
#define IPL_DEPTH_64F 64
/* get reference to pixel at (col,row),
for multi-channel images (col) should be multiplied by number of channels */
#define CV_IMAGE_ELEM( image, elemtype, row, col ) \
(((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])
/****************************************************************************************\
* Matrix type (CvMat) *
\****************************************************************************************/
#define CV_CN_MAX 64
#define CV_CN_SHIFT 3
#define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
#define CV_8U 0
#define CV_8S 1
#define CV_16U 2
#define CV_16S 3
#define CV_32S 4
#define CV_32F 5
#define CV_64F 6
#define CV_USRTYPE1 7
#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
#define CV_MAKE_TYPE CV_MAKETYPE
#define CV_8UC1 CV_MAKETYPE(CV_8U,1)
#define CV_8UC2 CV_MAKETYPE(CV_8U,2)
#define CV_8UC3 CV_MAKETYPE(CV_8U,3)
#define CV_8UC4 CV_MAKETYPE(CV_8U,4)
#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
#define CV_8SC1 CV_MAKETYPE(CV_8S,1)
#define CV_8SC2 CV_MAKETYPE(CV_8S,2)
#define CV_8SC3 CV_MAKETYPE(CV_8S,3)
#define CV_8SC4 CV_MAKETYPE(CV_8S,4)
#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
#define CV_16UC1 CV_MAKETYPE(CV_16U,1)
#define CV_16UC2 CV_MAKETYPE(CV_16U,2)
#define CV_16UC3 CV_MAKETYPE(CV_16U,3)
#define CV_16UC4 CV_MAKETYPE(CV_16U,4)
#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
#define CV_16SC1 CV_MAKETYPE(CV_16S,1)
#define CV_16SC2 CV_MAKETYPE(CV_16S,2)
#define CV_16SC3 CV_MAKETYPE(CV_16S,3)
#define CV_16SC4 CV_MAKETYPE(CV_16S,4)
#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
#define CV_32SC1 CV_MAKETYPE(CV_32S,1)
#define CV_32SC2 CV_MAKETYPE(CV_32S,2)
#define CV_32SC3 CV_MAKETYPE(CV_32S,3)
#define CV_32SC4 CV_MAKETYPE(CV_32S,4)
#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
#define CV_32FC1 CV_MAKETYPE(CV_32F,1)
#define CV_32FC2 CV_MAKETYPE(CV_32F,2)
#define CV_32FC3 CV_MAKETYPE(CV_32F,3)
#define CV_32FC4 CV_MAKETYPE(CV_32F,4)
#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
#define CV_64FC1 CV_MAKETYPE(CV_64F,1)
#define CV_64FC2 CV_MAKETYPE(CV_64F,2)
#define CV_64FC3 CV_MAKETYPE(CV_64F,3)
#define CV_64FC4 CV_MAKETYPE(CV_64F,4)
#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
#define CV_AUTO_STEP 0x7fffffff
#define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff )
#define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
#define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
#define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
#define CV_MAT_CONT_FLAG_SHIFT 14
#define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
#define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
#define CV_IS_CONT_MAT CV_IS_MAT_CONT
#define CV_MAT_TEMP_FLAG_SHIFT 15
#define CV_MAT_TEMP_FLAG (1 << CV_MAT_TEMP_FLAG_SHIFT)
#define CV_IS_TEMP_MAT(flags) ((flags) & CV_MAT_TEMP_FLAG)
#define CV_MAGIC_MASK 0xFFFF0000
#define CV_MAT_MAGIC_VAL 0x42420000
#define CV_TYPE_NAME_MAT "opencv-matrix"
typedef struct CvMat
{
int type;
int step;
/* for internal use only */
int* refcount;
int hdr_refcount;
union
{
uchar* ptr;
short* s;
int* i;
float* fl;
double* db;
} data;
#ifdef __cplusplus
union
{
int rows;
int height;
};
union
{
int cols;
int width;
};
#else
int rows;
int cols;
#endif
}
CvMat;
#define CV_IS_MAT_HDR(mat) \
((mat) != NULL && \
(((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \
((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0)
#define CV_IS_MAT(mat) \
(CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL)
#define CV_IS_MASK_ARR(mat) \
(((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0)
#define CV_ARE_TYPES_EQ(mat1, mat2) \
((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0)
#define CV_ARE_CNS_EQ(mat1, mat2) \
((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0)
#define CV_ARE_DEPTHS_EQ(mat1, mat2) \
((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0)
#define CV_ARE_SIZES_EQ(mat1, mat2) \
((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols)
#define CV_IS_MAT_CONST(mat) \
(((mat)->rows|(mat)->cols) == 1)
/* Size of each channel item,
0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
#define CV_ELEM_SIZE1(type) \
((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
/* 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
#define CV_ELEM_SIZE(type) \
(CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
#define IPL2CV_DEPTH(depth) \
((((CV_8U)+(CV_16U<<4)+(CV_32F<<8)+(CV_64F<<16)+(CV_8S<<20)+ \
(CV_16S<<24)+(CV_32S<<28)) >> ((((depth) & 0xF0) >> 2) + \
(((depth) & IPL_DEPTH_SIGN) ? 20 : 0))) & 15)
/* Inline constructor. No data is allocated internally!!!
* (Use together with cvCreateData, or use cvCreateMat instead to
* get a matrix with allocated data):
*/
CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL))
{
CvMat m;
assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F );
type = CV_MAT_TYPE(type);
m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type;
m.cols = cols;
m.rows = rows;
m.step = m.cols*CV_ELEM_SIZE(type);
m.data.ptr = (uchar*)data;
m.refcount = NULL;
m.hdr_refcount = 0;
return m;
}
#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
(assert( (unsigned)(row) < (unsigned)(mat).rows && \
(unsigned)(col) < (unsigned)(mat).cols ), \
(mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
#define CV_MAT_ELEM_PTR( mat, row, col ) \
CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) )
#define CV_MAT_ELEM( mat, elemtype, row, col ) \
(*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
CV_INLINE double cvmGet( const CvMat* mat, int row, int col )
{
int type;
type = CV_MAT_TYPE(mat->type);
assert( (unsigned)row < (unsigned)mat->rows &&
(unsigned)col < (unsigned)mat->cols );
if( type == CV_32FC1 )
return ((float*)(mat->data.ptr + (size_t)mat->step*row))[col];
else
{
assert( type == CV_64FC1 );
return ((double*)(mat->data.ptr + (size_t)mat->step*row))[col];
}
}
CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value )
{
int type;
type = CV_MAT_TYPE(mat->type);
assert( (unsigned)row < (unsigned)mat->rows &&
(unsigned)col < (unsigned)mat->cols );
if( type == CV_32FC1 )
((float*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value;
else
{
assert( type == CV_64FC1 );
((double*)(mat->data.ptr + (size_t)mat->step*row))[col] = (double)value;
}
}
CV_INLINE int cvIplDepth( int type )
{
int depth = CV_MAT_DEPTH(type);
return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S ||
depth == CV_32S ? IPL_DEPTH_SIGN : 0);
}
/****************************************************************************************\
* Multi-dimensional dense array (CvMatND) *
\****************************************************************************************/
#define CV_MATND_MAGIC_VAL 0x42430000
#define CV_TYPE_NAME_MATND "opencv-nd-matrix"
#define CV_MAX_DIM 32
#define CV_MAX_DIM_HEAP (1 << 16)
typedef struct CvMatND
{
int type;
int dims;
int* refcount;
int hdr_refcount;
union
{
uchar* ptr;
float* fl;
double* db;
int* i;
short* s;
} data;
struct
{
int size;
int step;
}
dim[CV_MAX_DIM];
}
CvMatND;
#define CV_IS_MATND_HDR(mat) \
((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
#define CV_IS_MATND(mat) \
(CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL)
/****************************************************************************************\
* Multi-dimensional sparse array (CvSparseMat) *
\****************************************************************************************/
#define CV_SPARSE_MAT_MAGIC_VAL 0x42440000
#define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix"
struct CvSet;
typedef struct CvSparseMat
{
int type;
int dims;
int* refcount;
int hdr_refcount;
struct CvSet* heap;
void** hashtable;
int hashsize;
int valoffset;
int idxoffset;
int size[CV_MAX_DIM];
}
CvSparseMat;
#define CV_IS_SPARSE_MAT_HDR(mat) \
((mat) != NULL && \
(((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL)
#define CV_IS_SPARSE_MAT(mat) \
CV_IS_SPARSE_MAT_HDR(mat)
/**************** iteration through a sparse array *****************/
typedef struct CvSparseNode
{
unsigned hashval;
struct CvSparseNode* next;
}
CvSparseNode;
typedef struct CvSparseMatIterator
{
CvSparseMat* mat;
CvSparseNode* node;
int curidx;
}
CvSparseMatIterator;
#define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset))
#define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset))
/****************************************************************************************\
* Histogram *
\****************************************************************************************/
typedef int CvHistType;
#define CV_HIST_MAGIC_VAL 0x42450000
#define CV_HIST_UNIFORM_FLAG (1 << 10)
/* indicates whether bin ranges are set already or not */
#define CV_HIST_RANGES_FLAG (1 << 11)
#define CV_HIST_ARRAY 0
#define CV_HIST_SPARSE 1
#define CV_HIST_TREE CV_HIST_SPARSE
/* should be used as a parameter only,
it turns to CV_HIST_UNIFORM_FLAG of hist->type */
#define CV_HIST_UNIFORM 1
typedef struct CvHistogram
{
int type;
CvArr* bins;
float thresh[CV_MAX_DIM][2]; /* For uniform histograms. */
float** thresh2; /* For non-uniform histograms. */
CvMatND mat; /* Embedded matrix header for array histograms. */
}
CvHistogram;
#define CV_IS_HIST( hist ) \
((hist) != NULL && \
(((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \
(hist)->bins != NULL)
#define CV_IS_UNIFORM_HIST( hist ) \
(((hist)->type & CV_HIST_UNIFORM_FLAG) != 0)
#define CV_IS_SPARSE_HIST( hist ) \
CV_IS_SPARSE_MAT((hist)->bins)
#define CV_HIST_HAS_RANGES( hist ) \
(((hist)->type & CV_HIST_RANGES_FLAG) != 0)
/****************************************************************************************\
* Other supplementary data type definitions *
\****************************************************************************************/
/*************************************** CvRect *****************************************/
typedef struct CvRect
{
int x;
int y;
int width;
int height;
}
CvRect;
CV_INLINE CvRect cvRect( int x, int y, int width, int height )
{
CvRect r;
r.x = x;
r.y = y;
r.width = width;
r.height = height;
return r;
}
CV_INLINE IplROI cvRectToROI( CvRect rect, int coi )
{
IplROI roi;
roi.xOffset = rect.x;
roi.yOffset = rect.y;
roi.width = rect.width;
roi.height = rect.height;
roi.coi = coi;
return roi;
}
CV_INLINE CvRect cvROIToRect( IplROI roi )
{
return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height );
}
/*********************************** CvTermCriteria *************************************/
#define CV_TERMCRIT_ITER 1
#define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER
#define CV_TERMCRIT_EPS 2
typedef struct CvTermCriteria
{
int type; /* may be combination of
CV_TERMCRIT_ITER
CV_TERMCRIT_EPS */
int max_iter;
double epsilon;
}
CvTermCriteria;
CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon )
{
CvTermCriteria t;
t.type = type;
t.max_iter = max_iter;
t.epsilon = (float)epsilon;
return t;
}
/******************************* CvPoint and variants ***********************************/
typedef struct CvPoint
{
int x;
int y;
}
CvPoint;
CV_INLINE CvPoint cvPoint( int x, int y )
{
CvPoint p;
p.x = x;
p.y = y;
return p;
}
typedef struct CvPoint2D32f
{
float x;
float y;
}
CvPoint2D32f;
CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
{
CvPoint2D32f p;
p.x = (float)x;
p.y = (float)y;
return p;
}
CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
{
return cvPoint2D32f( (float)point.x, (float)point.y );
}
CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point )
{
CvPoint ipt;
ipt.x = cvRound(point.x);
ipt.y = cvRound(point.y);
return ipt;
}
typedef struct CvPoint3D32f
{
float x;
float y;
float z;
}
CvPoint3D32f;
CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z )
{
CvPoint3D32f p;
p.x = (float)x;
p.y = (float)y;
p.z = (float)z;
return p;
}
typedef struct CvPoint2D64f
{
double x;
double y;
}
CvPoint2D64f;