-
Notifications
You must be signed in to change notification settings - Fork 16
/
OpenCV.pas
2975 lines (2403 loc) · 107 KB
/
OpenCV.pas
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
(*********************************************************************
* *
* Borland Delphi 4,5,6,7 API for *
* Intel Open Source Computer Vision Library *
* *
* *
* Portions created by Intel Corporation are *
* Copyright (C) 2000, Intel Corporation, all rights reserved. *
* *
* The original files are: CV.h, CVTypes.h, highgui.h *
* *
* *
* The original Pascal code is: OpenCV.pas, released 29 May 2003. *
* *
* The initial developer of the Pascal code is Vladimir Vasilyev *
* home page : http://www.nextnow.com *
* email : [email protected] *
* *
* Contributors: Andrey Klimov *
*********************************************************************
* Expanded version to use many other functions *
* G. De Sanctis - 9/2005 *
* 1/2012 - "$define V2" use OpenCV 2.3 Dll, else use old OpenCV 1 *
* style Dll *
* 5/2012 - added types CvChar and PCvChar to force AnsiChar type *
* (8 bit characters) in Delphi XE2 *
* 9/2012 - added symbols for use in FreePascal with MSEGui or *
* Lazarus *
* 9/2012 - added symbols for use in Linux with FreePascal *
* *
* 3/2016 - J.P "$define V3" use OpenCV 3.0 Dll *
* disable MSEGUI to use with Lazarus *
* 4/2016 - zbyna several fixes for fpc 64 bit. compiler *
* - added remainig utilities from HighGUI_DLL *
* - fix possibility to use "$define V2" in case of camera *
* incompatibility ( lifecam 6000HD ... ) *
* - fix for 'Not a 24 bit color iplImage!' *
* in IplImage2Bitmap *
*********************************************************************
* *
* *
* The contents of this file are used with permission, subject to *
* the Mozilla Public License Version 1.1 (the "License"); you may *
* not use this file except in compliance with the License. You may *
* obtain a copy of the License at *
* http://www.mozilla.org/MPL/MPL-1.1.html *
* *
* Software distributed under the License is distributed on an *
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or *
* implied. See the License for the specific language governing *
* rights and limitations under the License. *
* *
*********************************************************************)
unit OpenCV;
{set here the OpenCV version}
{$define V2}
{If you use Freepascal with MSEGUI define the same symbol,
else if you use Lazarus do not define MSEGUI symbol}
{$ifdef FPC}
{$mode delphi}
// {$define MSEGUI}
{$ifdef LCL}
{$define LAZARUS}
{$endif}
{$endif}
{$A+,Z+}
{$ASSERTIONS on}
interface
uses
{$ifdef MSWINDOWS}
Windows,
{$endif}
{$ifdef FPC}
{$ifdef LAZARUS}
Graphics, FPImage, IntfGraphics,
{$endif}
{$else}
Graphics,
{$endif}
Sysutils,Math,
IPL;
const
{$ifdef MSWINDOWS}
{$ifdef V3}
cvDLL = 'opencv_world300.dll';
videoDLL = 'opencv_world300.dll';
calibDLL = 'opencv_world300.dll';
HighGUI_DLL = 'opencv_world300.dll';
cxCore = 'opencv_world300.dll';
cvCam = 'opencv_world300.dll';
{$else}
{$ifdef V2}
cvDLL = 'opencv_imgproc2412.dll';
videoDLL = 'opencv_video2412.dll';
calibDLL = 'opencv_calib3d2412.dll';
HighGUI_DLL = 'opencv_highgui2412.dll';
cxCore = 'opencv_core2412.dll';
{$else}
cvDLL = 'CV100.DLL';
videoDLL = 'CV100.DLL';
calibDLL = 'CV100.DLL';
HighGUI_DLL = 'HighGUI100.DLL';
cxCore = 'CXCORE100.DLL';
cvCam = 'CVCAM100.DLL';
{$endif}
{$endif}
{$endif}
{$ifdef LINUX}
{$ifdef V2}
cvDLL = 'libcv.so.2.1';
videoDLL = 'libcv.so.2.1';
calibDLL = 'libcv.so.2.1';
HighGUI_DLL = 'libhighgui.so.2.1';
cxCore = 'libcxcore.so.2.1';
{$else}
cvDLL = '???';
videoDLL = '???';
calibDLL = '???';
HighGUI_DLL = '???';
cxCore = '???';
cvCam = '???';
{$endif}
{$endif}
CV_32F = 5;
//CV_32FC1 = CV_32F + 0*8;
CV_MAT_TYPE_MASK = 511;
CV_MAT_MAGIC_VAL = $42420000;
CV_MAT_CONT_FLAG_SHIFT = 14;
CV_MAT_CONT_FLAG = 1 shl CV_MAT_CONT_FLAG_SHIFT;
CV_MAT_CN_MASK = 3 shl 3;
CV_MAT_DEPTH_MASK = 7;
CV_RODRIGUES_M2V = 0;
CV_RODRIGUES_V2M = 1;
CV_LU = 0;
CV_SVD = 1;
{ Constants for color conversion }
CV_BGR2BGRA =0;
CV_RGB2RGBA =CV_BGR2BGRA;
CV_BGRA2BGR =1;
CV_RGBA2RGB =CV_BGRA2BGR;
CV_BGR2RGBA =2;
CV_RGB2BGRA =CV_BGR2RGBA;
CV_RGBA2BGR =3;
CV_BGRA2RGB =CV_RGBA2BGR;
CV_BGR2RGB =4;
CV_RGB2BGR =CV_BGR2RGB;
CV_BGRA2RGBA =5;
CV_RGBA2BGRA =CV_BGRA2RGBA;
CV_BGR2GRAY =6;
CV_RGB2GRAY =7;
CV_GRAY2BGR =8;
CV_GRAY2RGB =CV_GRAY2BGR;
CV_GRAY2BGRA =9;
CV_GRAY2RGBA =CV_GRAY2BGRA;
CV_BGRA2GRAY =10;
CV_RGBA2GRAY =11;
CV_BGR2BGR565 =12;
CV_RGB2BGR565 =13;
CV_BGR5652BGR =14;
CV_BGR5652RGB =15;
CV_BGRA2BGR565=16;
CV_RGBA2BGR565=17;
CV_BGR5652BGRA=18;
CV_BGR5652RGBA=19;
CV_GRAY2BGR565=20;
CV_BGR5652GRAY=21;
CV_BGR2BGR555 =22;
CV_RGB2BGR555 =23;
CV_BGR5552BGR =24;
CV_BGR5552RGB =25;
CV_BGRA2BGR555=26;
CV_RGBA2BGR555=27;
CV_BGR5552BGRA=28;
CV_BGR5552RGBA=29;
CV_GRAY2BGR555=30;
CV_BGR5552GRAY=31;
CV_BGR2XYZ =32;
CV_RGB2XYZ =33;
CV_XYZ2BGR =34;
CV_XYZ2RGB =35;
CV_BGR2YCrCb =36;
CV_RGB2YCrCb =37;
CV_YCrCb2BGR =38;
CV_YCrCb2RGB =39;
CV_BGR2HSV =40;
CV_RGB2HSV =41;
CV_BGR2Lab =44;
CV_RGB2Lab =45;
CV_BayerBG2BGR=46;
CV_BayerGB2BGR=47;
CV_BayerRG2BGR=48;
CV_BayerGR2BGR=49;
CV_BayerBG2RGB=CV_BayerRG2BGR;
CV_BayerGB2RGB=CV_BayerGR2BGR;
CV_BayerRG2RGB=CV_BayerBG2BGR;
CV_BayerGR2RGB=CV_BayerGB2BGR;
CV_BGR2Luv =50;
CV_RGB2Luv =51;
CV_BGR2HLS =52;
CV_RGB2HLS =53;
CV_HSV2BGR =54;
CV_HSV2RGB =55;
CV_Lab2BGR =56;
CV_Lab2RGB =57;
CV_Luv2BGR =58;
CV_Luv2RGB =59;
CV_HLS2BGR =60;
CV_HLS2RGB =61;
CV_FILLED = -(1);
CV_AA = 16;
type
// Delphi XE2 fix
CvChar = AnsiChar;
PCvChar = PAnsiChar;
TpCVCharArray = array [0 .. 0] of pCVChar; // by Zbyna
ppCVChar = ^TpCVCharArray; // by zbyna
//--------------
UCHAR = {$IFDEF WINDOWS} Windows.UCHAR {$ELSE} Byte {$ENDIF};
PUCHAR = {$IFDEF WINDOWS} Windows.PUCHAR {$ELSE} ^Byte {$ENDIF};
PINT = {$IFDEF WINDOWS} Windows.PINT {$ELSE} ^integer {$ENDIF};
PCvVect32f = PSingle;
TCvVect32fArr=array of Single;
PCvMatr32f = PSingle;
TCvMatr32fArr=array of Single;
TIntegerArr=array of Integer;
CvSize = record
width : longint;
height : longint;
end;
TCvSize = CvSize;
PCvSize = ^TCvSize;
CvPoint2D32f = record
x : Single;
y : Single;
end;
TCvPoint2D32f = CvPoint2D32f;
PCvPoint2D32f = ^TCvPoint2D32f;
TCvPoint2D32fArr=array of TCvPoint2D32f;
CvPoint3D32f = record
x : Single;
y : Single;
z : Single;
end;
TCvPoint3D32f = CvPoint3D32f;
PCvPoint3D32f = ^TCvPoint3D32f;
TCvPoint3D32fArr=array of TCvPoint3D32f;
TMatData = record
ptr: PUCHAR;
end;
CvMat = record
type_ : Integer;
step : Integer;
refcount : PInteger;
hdr_refcount: {$ifdef CPU64}int64{$else}integer{$endif};
data : TMatData;
rows : Integer;
cols : Integer;
end;
TCvMat = CvMat;
PCvMat = ^TCvMat;
P2PCvMat = ^PCvMat;
{ CvArr* is used to pass arbitrary array-like data structures
into the functions where the particular
array type is recognized at runtime }
// CvArr = void;
PCvArr = Pointer;
P2PCvArr = ^PCvArr;
//****************************************************************************************\
//* Multi-dimensional dense array (CvMatND) *
//****************************************************************************************/
const
CV_MATND_MAGIC_VAL = $42430000;
CV_TYPE_NAME_MATND = 'opencv-nd-matrix';
CV_MAX_DIM = 32;
CV_MAX_DIM_HEAP = 1 shl 16;
type
CvMatND = record
_type : longint;
dims : longint;
refcount : ^longint;
data : record
case longint of
0 : ( ptr : ^uchar );
1 : ( fl : ^double );
2 : ( db : ^double );
3 : ( i : ^longint );
4 : ( s : ^smallint );
end;
dim : array[0..(CV_MAX_DIM)-1] of record
size : longint;
step : longint;
end;
end;
{***************************************************************************************\
* Histogram *
\*************************************************************************************** }
type
CvHistType = longint;
const
CV_HIST_MAGIC_VAL = $42450000;
CV_HIST_UNIFORM_FLAG = 1 shl 10;
{ indicates whether bin ranges are set already or not }
CV_HIST_RANGES_FLAG = 1 shl 11;
CV_HIST_ARRAY = 0;
CV_HIST_SPARSE = 1;
CV_HIST_TREE = CV_HIST_SPARSE;
{ should be used as a parameter only,
it turns to CV_HIST_UNIFORM_FLAG of hist->type }
CV_HIST_UNIFORM = 1;
{ for uniform histograms }
{ for non-uniform histograms }
{ embedded matrix header for array histograms }
type
CvHistogram = record
_type : longint;
bins : PCvArr;
thresh : array[0..(CV_MAX_DIM)-1] of array[0..1] of float;
thresh2 : P2Pfloat;
mat : CvMatND;
end;
PCvHistogram = ^CvHistogram;
P2PCvHistogram = ^PCvHistogram;
//******************************** Memory storage ****************************************/
Type
PCvMemBlock = ^TCvMemBlock;
CvMemBlock = Record
prev : PCvMemBlock;
next : PCvMemBlock;
end;
TCvMemBlock = CvMemBlock;
Const CV_STORAGE_MAGIC_VAL = $42890000;
Type
PCvMemStorage = ^TCvMemStorage;
CvMemStorage = Record
signature : longint;
bottom : PCvMemBlock; //* first allocated block */
top : PCvMemBlock; //* current memory block - top of the stack */
parent : PCvMemStorage; //* borrows new blocks from */
block_size: longint; //* block size */
free_space: longint; //* free space in the current block */
end;
TCvMemStorage = CvMemStorage;
{************************************ CvScalar **************************************** }
CvScalar = record
val : array[0..3] of double;
end;
PCvScalar = ^CvScalar;
{************************************** CvRect **************************************** }
type
CvRect = record
x : longint;
y : longint;
width : longint;
height : longint;
end;
{************************************ CvSlice *****************************************}
type
CvSlice = record
start_index: longint;
end_index : longint;
end;
const
CV_WHOLE_SEQ_END_INDEX = $3fffffff;
var
CV_WHOLE_SEQ: cvSlice;
{********************************** Sequence ****************************************** }
{ previous sequence block }
{ next sequence block }
{ index of the first element in the block +
sequence->first->start_index }
{ number of elements in the block }
{ pointer to the first element of the block }
type
PCvSeqBlock = ^CvSeqBlock;
CvSeqBlock = record
prev : PCvSeqBlock;
next : PCvSeqBlock;
start_index : longint;
count : longint;
data : puchar;
end;
PCvSeq = ^CvSeq;
P2PCvSeq = ^PCvSeq;
CvSeq = record
flags : longint;
header_size : longint;
h_prev : PCvSeq;
h_next : PCvSeq;
v_prev : PCvSeq;
v_next : PCvSeq;
total : longint;
elem_size : longint;
block_max : Puchar;
ptr : Puchar;
delta_elems : longint;
storage : PCvMemStorage;
free_blocks : PCvSeqBlock;
first : PCvSeqBlock;
end;
PCvContour = ^CvContour;
CvContour = record
flags: longint; //* micsellaneous flags */
header_size: longint; //* size of sequence header */
h_prev: Pcvseq; //* previous sequence */
h_next: Pcvseq; //* next sequence */
v_prev: Pcvseq; //* 2nd previous sequence */
v_next: Pcvseq; //* 2nd next sequence */
total: longint; //* total number of elements */
elem_size: longint; //* size of sequence element in bytes */
block_max: PuChar; //* maximal bound of the last block */
ptr: PuChar; //* current write pointer */
delta_elems: longint; //* how many elements allocated when the seq grows */
storage: PCvMemStorage ; //* where the seq is stored */
free_blocks: PCvSeqBlock; //* free blocks list */
first: PCvSeqBlock; //* pointer to the first sequence block */
rect: CvRect ;
color: longint;
reserved: array [0..2] of longint;
end;
{*************************** Connected Component ************************************* }
{ area of the connected component }
{ average color of the connected component }
{ ROI of the component }
{ optional component boundary
(the contour might have child contours corresponding to the holes) }
CvConnectedComp = record
area : double;
value : CvScalar;
rect : CvRect;
contour : PCvSeq;
end;
PCvConnectedComp = ^CvConnectedComp;
{****************************** CvPoint and variants ********************************** }
type
CvPoint = record
x : longint;
y : longint;
end;
PCvPoint = ^CvPoint;
CvPoint2D64f = record
x : double;
y : double;
end;
CvPoint3D64f = record
x : double;
y : double;
z : double;
end;
CvSize2D32f = record
width : float;
height : float;
end;
{ center of the box }
{ box width and length }
{ angle between the horizontal axis
and the first side (i.e. length) in radians }
CvBox2D = record
center : CvPoint2D32f;
size : CvSize2D32f;
angle : float;
end;
PCvBox2D = ^CvBox2D;
{ Line iterator state }
{ pointer to the current point }
{ Bresenham algorithm state }
CvLineIterator = record
ptr : ^uchar;
err : longint;
plus_delta : longint;
minus_delta : longint;
plus_step : longint;
minus_step : longint;
end;
//*********************************** CvTermCriteria *************************************/
Const
CV_TERMCRIT_ITER = 1;
CV_TERMCRIT_NUMB = CV_TERMCRIT_ITER;
CV_TERMCRIT_EPS = 2;
Type
CvTermCriteria = Record
type_ : integer; { may be combination of CV_TERMCRIT_ITER, CV_TERMCRIT_EPS }
maxIter : integer;
epsilon : double;
end;
TCvTermCriteria = CvTermCriteria;
{\*********************************** CvTermCriteria *************************************}
Procedure cvRodrigues2( rotMatrix : PCVMAT;
rotVector : PCVMAT;
jacobian : PCVMAT;
convType : Integer ); cdecl ;
{ Initializes CvMat header }
const
CV_AUTOSTEP = $7fffffff;
Function cvInitMatHeader( mat: PCvMat; rows, cols,
type_: integer; data: pointer = 0;
step: integer = CV_AUTOSTEP ): PCvMat; cdecl;
{ Allocates and initalizes CvMat header }
Function cvCreateMatHeader(rows, cols, type_: integer ): PCvMat; cdecl;
{ Attaches user data to the array header. The step is reffered to
the pre-last dimension. That is, all the planes of the array
must be joint (w/o gaps) }
Procedure cvSetData(arr: PCvArr; data: pointer; step: integer ); cdecl;
{ Allocates array data }
Procedure cvCreateData( arr : PCvArr ); cdecl;
{ Releases array data }
Procedure cvReleaseData(arr : PCvArr ); cdecl;
const
CV_CN_SHIFT = 3;
CV_8U =0;
CV_8S =1;
CV_16U =2;
CV_16S =3;
CV_32S =4;
CV_64F =6;
var
// CV_8UC3 CV_MAKETYPE(CV_8U,3)
CV_8UC3 : longint;
{ Allocates and initializes CvMat header and allocates data }
Function cvCreateMat( rows, cols, _type: integer ): PCvMat ; cdecl;
{ Releases CvMat header and deallocates matrix data
(reference counting is used for data) }
Procedure cvReleaseMat( mat: P2PCvMat ); cdecl;
{ Selects row span of the input array: arr(start_row:delta_row:end_row,:)
(end_row is not included into the span). }
Function cvGetRows( const arr: PCvArr; submat: PCvMat;
start_row, end_row: integer;
delta_row: integer = 1 ): PCvMat; cdecl;
Function cvInvert( const A : PCvArr; B : PCvArr; method : integer ) : double; cdecl;
Function cvPseudoInverse( const src : PCvArr; dst : PCvArr ) : double;
// Before OpenCV version 1.0
// Procedure cvMultiplyAcc( const A,B,C : PCvArr; D : PCvArr ); cdecl;
Procedure cvMultiplyAcc( const A,B,C : PCvArr; D : PCvArr ); cdecl;
Procedure cvMul( const A,B,C : PCvArr; scale: double=1.0); cdecl;
Procedure cvMatMul( A,B,D : PCvArr );
// Finds sum of array elements
Function cvSum( arr : PCvArr ): CvScalar; cdecl;
// Calculates number of non-zero pixels
Function cvCountNonZero( arr: PCvArr ): integer; cdecl;
// Subtracts one array from another one
Procedure cvSub( src1, src2, dst: PCvArr; mask: PCvArr = 0 ); cdecl;
// dst(mask) = src1(mask) + src2(mask) */
Procedure cvAdd( src1, src2, dst: PCvArr;
mask: PCvArr = 0); cdecl;
// dst(mask) = src(mask) + value */
Procedure cvAddS( src: PCvArr; value : CvScalar; dst: PCvArr;
mask: PCvArr = 0); cdecl;
const
CV_CMP_EQ = 0;
CV_CMP_GT = 1;
CV_CMP_GE = 2;
CV_CMP_LT = 3;
CV_CMP_LE = 4;
CV_CMP_NE = 5;
// dst(idx) = src1(idx) _cmp_op_ src2(idx) */
Procedure cvCmp( const src1, src2: PCvArr;
dst: PCvArr; cmp_op: integer ); cdecl;
// Calculates mean and standard deviation of pixel values */
Procedure cvAvgSdv( arr: PCvArr; mean, std_dev: PCvScalar;
mask: PCvArr = 0 ); cdecl;
Function cvAvg( arr: PCvarr; mask: PCvarr = nil): cvscalar; cdecl;
//* Finds global minimum, maximum and their positions */
Procedure cvMinMaxLoc( arr: PCvarr; min_val, max_val: Pdouble;
var min_loc: Cvpoint;
var max_loc: Cvpoint;
mask: PCvarr = nil ); cdecl;
const
CV_DXT_FORWARD =0;
CV_DXT_INVERSE =1;
CV_DXT_SCALE =2; //* divide result by size of array */
CV_DXT_INV_SCALE = 3;//(CV_DXT_INVERSE + CV_DXT_SCALE)
CV_DXT_INVERSE_SCALE=CV_DXT_INV_SCALE;
CV_DXT_ROWS =4; //* transform each row individually */
CV_DXT_MUL_CONJ =8; //* conjugate the second argument of cvMulSpectrums */
{ Discrete Fourier Transform:
complex->complex,
real->ccs (forward),
ccs->real (inverse) }
Procedure cvDFT( const src, dst: PCvArr; flags: integer;
nonzero_rows: integer = 0 ); cdecl;
{ Returns optimal DFT size for a given vector size. }
Function cvGetOptimalDFTSize( size0: integer ): integer;
//* Does cartesian->polar coordinates conversion.
// Either of output components (magnitude or angle) is optional */
Procedure cvCartToPolar( x, y: PCvArr;
magnitude: PCvArr; angle: PCvArr = 0;
angle_in_degrees: integer = 0); cdecl;
//* Does polar->cartesian coordinates conversion.
// Either of output components (magnitude or angle) is optional.
// If magnitude is missing it is assumed to be all 1's */
Procedure cvPolarToCart( magnitude, angle: PCvArr;
x, y: PCvArr;
angle_in_degrees: integer = 0); cdecl;
// Calculates the natural logarithm of every array elementҳ absolute value.
Procedure cvLog( const src: PCvArr; dst: PCvArr ); cdecl;
// types of array norm */
const
CV_C = 1;
CV_L1 = 2;
CV_L2 = 4;
CV_NORM_MASK = 7;
CV_RELATIVE = 8;
CV_DIFF = 16;
CV_MINMAX = 32;
CV_DIFF_C =(CV_DIFF or CV_C);
CV_DIFF_L1 =(CV_DIFF or CV_L1);
CV_DIFF_L2 =(CV_DIFF or CV_L2);
CV_RELATIVE_C =(CV_RELATIVE or CV_C);
CV_RELATIVE_L1 =(CV_RELATIVE or CV_L1);
CV_RELATIVE_L2 =(CV_RELATIVE or CV_L2);
Function cvNorm( arr1: PCvarr; arr2: PCvarr=nil; norm_type: Longint=CV_L2; mask: PCvarr=nil ): double;
const
CV_32FC1 = 5;
CV_32FC2 = 13;
CV_32FC3 = 21;
CV_32SC1 = 4;
CV_32SC2 = 12;
CV_32SC3 = 20;
Function cvMat_( rows, cols, type_: Integer; data : Pointer ):TCvMat;
Function cvmGet( const mat : PCvMat; i, j : integer): Single;
Procedure cvmSet( mat : PCvMat; i, j : integer; val: Single);
Function cvSize_( width, height : integer ) : TcvSize;
//* simple API for reading/writing data */
Procedure cvSave( filename: PCvChar; struct_ptr: pointer;
name: PCvChar = nil;
comment: PCvChar = nil;
attributes: pointer = nil); cdecl;
// attributes: cvattrlist = nil); cdecl;
Function cvLoad( filename: PCvChar;
memstorage: PCvMemStorage = nil;
name: PCvChar = nil;
real_name: PCvChar = nil ): pointer; cdecl;
{ load image from file
iscolor: >0 - output image is always color,
0 - output image is always grayscale,
<0 - output image is color or grayscale dependending on the file }
type
TCvLoadImageIsColor = ( CV_LOAD_IMAGE_GRAYSCALE = 0, CV_LOAD_IMAGE_COLOR = 1, CV_LOAD_IMAGE_UNCHANGED = -1);
Function cvLoadImage( const filename : PCvChar; iscolor : TCvLoadImageIsColor=CV_LOAD_IMAGE_COLOR) : PIplImage; cdecl;
Function cvSaveImage( const filename : PCvChar; const image : Pointer) : integer; cdecl;
{ <malloc> wrapper.
If there is no enough memory, the function
(as well as other OpenCV functions that call cvAlloc)
raises an error. }
Function cvAlloc( size: longint ): pointer; cdecl;
{ <free> wrapper.
Here and further all the memory releasing functions
(that all call cvFree) take double pointer in order to
to clear pointer to the data after releasing it.
Passing pointer to NULL pointer is Ok: nothing happens in this case
}
Procedure cvFree( ptr: PPointer); cdecl;
Procedure cvRelease(struct_ptr: PPointer ); cdecl;
{ Allocates and initializes IplImage header }
Function cvCreateImageHeader( size : TCvSize; depth, channels : integer ) : PIplImage; cdecl;
{ Releases (i.e. deallocates) IPL image header : void cvReleaseImageHeader( IplImage** image );}
Procedure cvReleaseImageHeader( var image : PIplImage ); cdecl;
{ Releases IPL image header and data }
Procedure cvReleaseImage( var image : PIplImage ); cdecl;
{ Creates a copy of IPL image (widthStep may differ). }
Function cvCloneImage( const image : PIplImage ) : PIplImage; cdecl;
{ Makes a new matrix from <rect> subrectangle of input array.
No data is copied }
Function cvGetSubRect(arr: PCvArr; submat: PCvMat; rect: CvRect ): PCvMat; cdecl;
{ Converts input array from one color space to another. }
Procedure cvCvtColor( const src : PCvArr; dst : PCvArr; colorCvtCode : integer ); cdecl;
{ Const for cvResize }
type TcvResizeInterpolation = (
CV_INTER_NN = 0,
CV_INTER_LINEAR = 1,
CV_INTER_CUBIC = 2,
CV_INTER_AREA = 3 );
{ Resizes image (input array is resized to fit the destination array) }
Procedure cvResize( const src : PCvArr; dst : PCvArr;
interpolation: TcvResizeInterpolation = CV_INTER_LINEAR ); cdecl;
{ Creates new memory storage.
block_size == 0 means that default, somewhat optimal size, is used (currently, it is 64K). }
Function cvCreateMemStorage( block_size : integer =0) : PCvMemStorage; cdecl;
{ Releases memory storage. All the children of a parent must be released before
the parent. A child storage returns all the blocks to parent when it is released }
Procedure cvReleaseMemStorage( var storage : PCvMemStorage ); cdecl;
{ Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos)
to reuse memory allocated for the storage - cvClearSeq,cvClearSet ...
do not free any memory.
A child storage returns all the blocks to the parent when it is cleared }
Procedure cvClearMemStorage( storage: PCvMemStorage );
{ Detects corners on a chess-board - "brand" OpenCV calibration pattern }
{ only in OpenCV V1 }
{$ifndef V3 AND $ifndef V2}
Function cvFindChessBoardCornerGuesses( const arr : Pointer;
thresh : Pointer;
storage : PCvMemStorage;
etalon_size : TCvSize;
corners : PCvPoint2D32f;
corner_count : PInteger ) : integer; cdecl;
{$endif}
{ Adjust corner position using some sort of gradient search }
Procedure cvFindCornerSubPix( const src : Pointer;
corners : PCvPoint2D32f;
count : integer;
win : TCvSize;
zero_zone : TCvSize;
criteria : TCvTermCriteria ); cdecl;
//cvCreateSeq
{ Creates new empty sequence that will reside in the specified storage }
Function cvCreateSeq( seq_flags, header_size,
elem_size: longint; storage: PCvMemStorage ): PCvSeq; cdecl;
//cvGetSeqElem
{ Retrives pointer to specified sequence element.
Negative indices are supported and mean counting from the end
(e.g -1 means the last sequence element) }
Function cvGetSeqElem( seq: PCvSeq; index: longint ): PCvChar; cdecl;
{-----------------------------------------------}
{Delphi procedure to convert a OCV iplImage to a Delphi bitmap}
procedure IplImage2Bitmap(iplImg: PIplImage; var bitmap: TBitmap);
{Delphi procedure to convert a Delphi bitmap to a OCV iplImage}
procedure Bitmap2IplImage(iplImg: PIplImage; bitmap: TBitmap);
{Delphi procedure to convert a OCV 32 bit iplImage to a 8 bit image}
procedure IplImage32FTo8Bit(Img32, Img8: PIplImage);
{functions/procedures not in DLL, written in this unit}
function cvScalar_(val0:double; val1:double; val2:double; val3:double):CvScalar;
function cvScalarAll(val0123:double):CvScalar;
function cvFloor(value: double): longint;
function cvRound(value:double):longint;
function cvPoint_( x, y: longint ): CvPoint;
function cvPointFrom32f_( point: CvPoint2D32f ): CvPoint;
function cvPointTo32f_(point: CvPoint ): CvPoint2D32f;
function cvTermCriteria_( type_: longint; max_iter: longint; epsilon: double ): CvTermCriteria;
function CV_RGB(r,g,b : longint) : CvScalar;
procedure cvEllipseBox(img:PCvArr; box:CvBox2D; color:CvScalar; thickness:longint;
line_type:longint; shift:longint);
function cvRect_( x, y, width, height: longint ): CvRect;
procedure CV_SWAP(var a, b, t: pointer);
function cvGetSize(arr: PIplImage):CvSize;
function cvSlice_(start, end_: longint ): CvSlice;
function cvContourPerimeter( contour: PCvSeq ): double;
procedure cvCalcBackProject(image:P2PIplImage; dst:PCvArr; hist:PCvHistogram);
procedure cvCalcHist(image:P2PIplImage; hist:PCvHistogram; accumulate:longint; mask:PCvArr);
function cvQueryHistValue2D(hist:CvHistogram; idx0:longint; idx1:longint):double;
{-----------------------------------------------}
{ Creates IPL image (header and data) }
function cvCreateImage(size:CvSize; depth:longint; channels:longint):PIplImage;
cdecl;
{ Copies source array to destination array }
procedure cvCopy(src:PCvArr; dst:PCvArr; mask:PCvArr); cdecl;
{ dst(idx) = ~src(idx) }
procedure cvNot( src, dst:PCvArr); cdecl;
{ dst(idx) = lower <= src(idx) < upper }
procedure cvInRangeS(src:PCvArr; lower:CvScalar; upper:CvScalar; dst:PCvArr);
cdecl;
{ Creates new histogram }
function cvCreateHist(dims:longint; sizes:Plongint; _type:longint; ranges:P2Pfloat;
uniform:longint): PCvHistogram; cdecl;
{ Releases histogram }
procedure cvReleaseHist(hist: P2PCvHistogram); cdecl;
{ Calculates array histogram }
procedure cvCalcArrHist(arr:P2PCvArr; hist:PCvHistogram; accumulate:longint; mask:PCvArr);
cdecl;
{ Finds indices and values of minimum and maximum histogram bins }
procedure cvGetMinMaxHistValue(hist:PCvHistogram; min_value:PFloat;
max_value:PFloat; min_idx:Plongint; max_idx:Plongint); cdecl;
{ Calculates back project }
procedure cvCalcArrBackProject(image:P2PCvArr; dst:PCvArr; hist:PCvHistogram);
cdecl;
{ equalizes histogram of 8-bit single-channel image }
procedure cvEqualizeHist( src, dst:PCvArr ); cdecl;
{ Set array elements to value }
procedure cvSet( arr: PCvArr; value: CvScalar; const mask:PCvArr=nil ); cdecl;
{ Clears all the array elements (sets them to 0) }
procedure cvSetZero(arr:PCvArr); cdecl;
procedure cvZero(arr:PCvArr); cdecl;
{ Sets image ROI (region of interest) (COI is not changed) }
procedure cvSetImageROI(image:PIplImage; rect:CvRect); cdecl;
{ Sets a Channel Of Interest (only a few functions support COI) -
use cvCopy to extract the selected channel and/or put it back }
procedure cvSetImageCOI( image: PIplImage; coi: longint ); cdecl;
{ Resets image ROI and COI }
procedure cvResetImageROI(image:PIplImage); cdecl;
{ Performs linear transformation on every source array element:
dst(x,y,c) = scale*src(x,y,c)+shift.
Arbitrary combination of input and output array depths are allowed
(number of channels must be the same), thus the function can be used
for type conversion }
procedure cvConvertScale(src:PCvArr; dst:PCvArr; scale:double; shift:double);
cdecl;
{ Splits a multi-channel array into the set of single-channel arrays or
extracts particular [color] plane }
procedure cvSplit(src:PCvArr; dst0:PCvArr; dst1:PCvArr; dst2:PCvArr; dst3:PCvArr);
cdecl;
{ Merge until 3 single-channel arrays into a multi-channel array }
procedure cvMerge(src0:PCvArr; src1:PCvArr; src2:PCvArr; src3:PCvArr; dst:PCvArr);
cdecl;