-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcore.dart
1259 lines (1169 loc) · 39.2 KB
/
core.dart
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
// ignore_for_file: non_constant_identifier_names
library cv;
import 'dart:ffi' as ffi;
import 'package:ffi/ffi.dart';
import 'rng.dart';
import 'scalar.dart';
import 'base.dart';
import 'point.dart';
import 'mat_type.dart';
import 'mat.dart';
import 'termcriteria.dart';
import 'vec.dart';
import '../constants.g.dart';
import '../opencv.g.dart' as cvg;
/// get version
String openCvVersion() {
return using<String>((arena) {
final p = arena<ffi.Pointer<ffi.Char>>();
cvRun(() => CFFI.openCVVersion(p));
return p.value.cast<Utf8>().toDartString();
});
}
/// Returns full configuration time cmake output.
///
/// Returned value is raw cmake output including version control system revision, compiler version, compiler flags, enabled modules and third party libraries, etc. Output format depends on target architecture.
String getBuildInformation() {
return using<String>((arena) {
final p = arena<ffi.Pointer<ffi.Char>>();
cvRun(() => CFFI.getBuildInfo(p));
return p.value.cast<Utf8>().toDartString();
});
}
/// AbsDiff calculates the per-element absolute difference between two arrays
/// or between an array and a scalar.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6fef31bc8c4071cbc114a758a2b79c14
Mat absDiff(Mat src1, Mat src2, [Mat? dst]) {
return cvRunArena<Mat>((arena) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_AbsDiff(src1.ref, src2.ref, dst!.ref));
return dst!;
});
}
/// Add calculates the per-element sum of two arrays or an array and a scalar.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga10ac1bfb180e2cfda1701d06c24fdbd6
Mat add(Mat src1, Mat src2, [Mat? dst]) {
return cvRunArena<Mat>((arena) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Add(src1.ref, src2.ref, dst!.ref));
return dst!;
});
}
/// AddWeighted calculates the weighted sum of two arrays.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gafafb2513349db3bcff51f54ee5592a19
Mat addWeighted(
InputArray src1,
double alpha,
InputArray src2,
double beta,
double gamma, {
OutputArray? dst,
int dtype = -1, // TODO: Add this
}) {
dst ??= Mat.empty();
cvRun(
() => CFFI.Mat_AddWeighted(
src1.ref,
alpha,
src2.ref,
beta,
gamma,
dst!.ref,
// dtype,
),
);
return dst;
}
/// BitwiseAnd computes bitwise conjunction of the two arrays (dst = src1 & src2).
/// Calculates the per-element bit-wise conjunction of two arrays
/// or an array and a scalar.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga60b4d04b251ba5eb1392c34425497e14
Mat bitwiseAND(
InputArray src1,
InputArray src2, {
OutputArray? dst,
InputArray? mask,
}) {
dst ??= Mat.empty();
if (mask == null) {
cvRun(() => CFFI.Mat_BitwiseAnd(src1.ref, src2.ref, dst!.ref));
} else {
cvRun(() => CFFI.Mat_BitwiseAndWithMask(src1.ref, src2.ref, dst!.ref, mask.ref));
}
return dst;
}
/// BitwiseNot inverts every bit of an array.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga0002cf8b418479f4cb49a75442baee2f
Mat bitwiseNOT(InputArray src, {OutputArray? dst, InputArray? mask}) {
dst ??= Mat.empty();
if (mask == null) {
cvRun(() => CFFI.Mat_BitwiseNot(src.ref, dst!.ref));
} else {
cvRun(() => CFFI.Mat_BitwiseNotWithMask(src.ref, dst!.ref, mask.ref));
}
return dst;
}
/// BitwiseOr calculates the per-element bit-wise disjunction of two arrays
/// or an array and a scalar.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gab85523db362a4e26ff0c703793a719b4
Mat bitwiseOR(
InputArray src1,
InputArray src2, {
OutputArray? dst,
InputArray? mask,
}) {
dst ??= Mat.empty();
if (mask == null) {
cvRun(() => CFFI.Mat_BitwiseOr(src1.ref, src2.ref, dst!.ref));
} else {
cvRun(() => CFFI.Mat_BitwiseOrWithMask(src1.ref, src2.ref, dst!.ref, mask.ref));
}
return dst;
}
/// BitwiseXor calculates the per-element bit-wise "exclusive or" operation
/// on two arrays or an array and a scalar.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga84b2d8188ce506593dcc3f8cd00e8e2c
Mat bitwiseXOR(
InputArray src1,
InputArray src2, {
OutputArray? dst,
InputArray? mask,
}) {
dst ??= Mat.empty();
if (mask == null) {
cvRun(() => CFFI.Mat_BitwiseXor(src1.ref, src2.ref, dst!.ref));
} else {
cvRun(() => CFFI.Mat_BitwiseXorWithMask(src1.ref, src2.ref, dst!.ref, mask.ref));
}
return dst;
}
/// BatchDistance is a naive nearest neighbor finder.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4ba778a1c57f83233b1d851c83f5a622
(Mat dist, Mat nidx) batchDistance(
InputArray src1,
InputArray src2,
int dtype, {
OutputArray? dist,
OutputArray? nidx,
int normType = NORM_L2,
int K = 0,
InputArray? mask,
int update = 0,
bool crosscheck = false,
}) {
dist ??= Mat.empty();
nidx ??= Mat.empty();
mask ??= Mat.empty();
cvRun(
() => CFFI.Mat_BatchDistance(
src1.ref,
src2.ref,
dist!.ref,
dtype,
nidx!.ref,
normType,
K,
mask!.ref,
update,
crosscheck,
),
);
return (dist, nidx);
}
/// BorderInterpolate computes the source location of an extrapolated pixel.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga247f571aa6244827d3d798f13892da58
int borderInterpolate(int p, int len, int borderType) {
return cvRunArena<int>((arena) {
final ptr = arena<ffi.Int>();
cvRun(() => CFFI.Mat_BorderInterpolate(p, len, borderType, ptr));
return ptr.value;
});
}
/// CalcCovarMatrix calculates the covariance matrix of a set of vectors.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga017122d912af19d7d0d2cccc2d63819f
(Mat covar, Mat mean) calcCovarMatrix(
InputArray samples,
InputOutputArray mean,
int flags, {
OutputArray? covar,
int ctype = MatType.CV_64F,
}) {
covar ??= Mat.empty();
cvRun(
() => CFFI.Mat_CalcCovarMatrix(
samples.ref,
covar!.ref,
mean.ref,
flags,
ctype,
),
);
return (covar, mean);
}
/// CartToPolar calculates the magnitude and angle of 2D vectors.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gac5f92f48ec32cacf5275969c33ee837d
(Mat magnitude, Mat angle) cartToPolar(
InputArray x,
InputArray y, {
OutputArray? magnitude,
OutputArray? angle,
bool angleInDegrees = false,
}) {
magnitude ??= Mat.empty();
angle ??= Mat.empty();
cvRun(
() => CFFI.Mat_CartToPolar(
x.ref,
y.ref,
magnitude!.ref,
angle!.ref,
angleInDegrees,
),
);
return (magnitude, angle);
}
/// CheckRange checks every element of an input array for invalid values.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga2bd19d89cae59361416736f87e3c7a64
(bool, Point) checkRange(
InputArray a, {
bool quiet = true,
double minVal = -CV_F64_MAX,
double maxVal = CV_F64_MAX,
}) {
return cvRunArena<(bool, Point)>((arena) {
final pos = arena<cvg.Point>();
final rval = arena<ffi.Bool>();
cvRun(() => CFFI.Mat_CheckRange(a.ref, quiet, pos, minVal, maxVal, rval));
return (rval.value, Point.fromNative(pos.ref));
});
}
/// Compare performs the per-element comparison of two arrays
/// or an array and scalar value.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga303cfb72acf8cbb36d884650c09a3a97
Mat compare(InputArray src1, InputArray src2, int cmpop, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Compare(src1.ref, src2.ref, dst!.ref, cmpop));
return dst;
}
/// CountNonZero counts non-zero array elements.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa4b89393263bb4d604e0fe5986723914
int countNonZero(Mat src) {
return cvRunArena<int>((arena) {
final p = arena<ffi.Int>();
CFFI.Mat_CountNonZero(src.ref, p);
return p.value;
});
}
/// CompleteSymm copies the lower or the upper half of a square matrix to its another half.
///
/// For further details, please see:
/// https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga6847337c0c55769e115a70e0f011b5ca
Mat completeSymm(InputOutputArray m, {bool lowerToUpper = false}) {
cvRun(() => CFFI.Mat_CompleteSymm(m.ref, lowerToUpper));
return m;
}
/// ConvertScaleAbs scales, calculates absolute values, and converts the result to 8-bit.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga3460e9c9f37b563ab9dd550c4d8c4e7d
Mat convertScaleAbs(
InputArray src, {
OutputArray? dst,
double alpha = 1,
double beta = 0,
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_ConvertScaleAbs(src.ref, dst!.ref, alpha, beta));
return dst;
}
/// CopyMakeBorder forms a border around an image (applies padding).
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga2ac1049c2c3dd25c2b41bffe17658a36
Mat copyMakeBorder(
InputArray src,
int top,
int bottom,
int left,
int right,
int borderType, {
OutputArray? dst,
Scalar? value,
}) {
dst ??= Mat.empty();
value ??= Scalar.default_();
cvRun(
() => CFFI.Mat_CopyMakeBorder(
src.ref,
dst!.ref,
top,
bottom,
left,
right,
borderType,
value!.ref,
),
);
return dst;
}
/// DCT performs a forward or inverse discrete Cosine transform of 1D or 2D array.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga85aad4d668c01fbd64825f589e3696d4
Mat dct(InputArray src, {OutputArray? dst, int flags = 0}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_DCT(src.ref, dst!.ref, flags));
return dst;
}
/// Determinant returns the determinant of a square floating-point matrix.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaf802bd9ca3e07b8b6170645ef0611d0c
double determinant(InputArray mtx) {
return cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(() => CFFI.Mat_Determinant(mtx.ref, p));
return p.value;
});
}
/// DFT performs a forward or inverse Discrete Fourier Transform (DFT)
/// of a 1D or 2D floating-point array.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gadd6cf9baf2b8b704a11b5f04aaf4f39d
Mat dft(
InputArray src, {
OutputArray? dst,
int flags = 0,
int nonzeroRows = 0, // TODO: add
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_DFT(src.ref, dst!.ref, flags));
return dst;
}
/// Divide performs the per-element division
/// on two arrays or an array and a scalar.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6db555d30115642fedae0cda05604874
Mat divide(
InputArray src1,
InputArray src2, {
OutputArray? dst,
double scale = 1,
int dtype = -1,
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Divide(src1.ref, src2.ref, dst!.ref));
return dst;
}
/// Eigen calculates eigenvalues and eigenvectors of a symmetric matrix.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga9fa0d58657f60eaa6c71f6fbb40456e3
(bool ret, Mat eigenvalues, Mat eigenvectors) eigen(
InputArray src, {
OutputArray? eigenvalues,
OutputArray? eigenvectors,
}) {
eigenvalues ??= Mat.empty();
eigenvectors ??= Mat.empty();
final ret = cvRunArena<bool>((arena) {
final p = arena<ffi.Bool>();
cvRun(() => CFFI.Mat_Eigen(src.ref, eigenvalues!.ref, eigenvectors!.ref, p));
return p.value;
});
return (ret, eigenvalues, eigenvectors);
}
/// EigenNonSymmetric calculates eigenvalues and eigenvectors of a non-symmetric matrix (real eigenvalues only).
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaf51987e03cac8d171fbd2b327cf966f6
(Mat eigenvalues, Mat eigenvectors) eigenNonSymmetric(
InputArray src, {
OutputArray? eigenvalues,
OutputArray? eigenvectors,
}) {
eigenvalues ??= Mat.empty();
eigenvectors ??= Mat.empty();
cvRun(() => CFFI.Mat_EigenNonSymmetric(src.ref, eigenvalues!.ref, eigenvectors!.ref));
return (eigenvalues, eigenvectors);
}
/// PCACompute performs PCA.
///
/// The computed eigenvalues are sorted from the largest to the smallest and the corresponding
/// eigenvectors are stored as eigenvectors rows.
///
/// Note: Calling with maxComponents == 0 (opencv default) will cause all components to be retained.
///
/// For further details, please see:
/// https://docs.opencv.org/4.x/d2/de8/group__core__array.html#ga27a565b31d820b05dcbcd47112176b6e
(Mat mean, Mat eigenvalues, Mat eigenvectors) PCACompute(
InputArray data,
InputOutputArray mean, {
OutputArray? eigenvectors,
OutputArray? eigenvalues,
int maxComponents = 0,
}) {
eigenvalues ??= Mat.empty();
eigenvectors ??= Mat.empty();
CFFI.Mat_PCACompute(data.ref, mean.ref, eigenvectors.ref, eigenvalues.ref, maxComponents);
return (mean, eigenvalues, eigenvectors);
}
/// Exp calculates the exponent of every array element.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga3e10108e2162c338f1b848af619f39e5
Mat exp(InputArray src, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Exp(src.ref, dst!.ref));
return dst;
}
/// ExtractChannel extracts a single channel from src (coi is 0-based index).
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gacc6158574aa1f0281878c955bcf35642
Mat extractChannel(InputArray src, int coi, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_ExtractChannel(src.ref, dst!.ref, coi));
return dst;
}
/// FindNonZero returns the list of locations of non-zero pixels.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaed7df59a3539b4cc0fe5c9c8d7586190
Mat findNonZero(InputArray src, {OutputArray? idx}) {
idx ??= Mat.empty();
cvRun(() => CFFI.Mat_FindNonZero(src.ref, idx!.ref));
return idx;
}
/// Flip flips a 2D array around horizontal(0), vertical(1), or both axes(-1).
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaca7be533e3dac7feb70fc60635adf441
Mat flip(InputArray src, int flipCode, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Flip(src.ref, dst!.ref, flipCode));
return dst;
}
/// Gemm performs generalized matrix multiplication.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gacb6e64071dffe36434e1e7ee79e7cb35
Mat gemm(
InputArray src1,
InputArray src2,
double alpha,
InputArray src3,
double beta, {
OutputArray? dst,
int flags = 0,
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Gemm(src1.ref, src2.ref, alpha, src3.ref, beta, dst!.ref, flags));
return dst;
}
/// GetOptimalDFTSize returns the optimal Discrete Fourier Transform (DFT) size
/// for a given vector size.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6577a2e59968936ae02eb2edde5de299
int getOptimalDFTSize(int vecsize) {
return cvRunArena<int>((arena) {
final p = arena<ffi.Int>();
cvRun(() => CFFI.Mat_GetOptimalDFTSize(vecsize, p));
return p.value;
});
}
/// Hconcat applies horizontal concatenation to given matrices.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaab5ceee39e0580f879df645a872c6bf7
Mat hconcat(InputArray src1, InputArray src2, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Hconcat(src1.ref, src2.ref, dst!.ref));
return dst;
}
/// Vconcat applies vertical concatenation to given matrices.
///
/// For further details, please see:
/// https://docs.opencv.org/4.x/d2/de8/group__core__array.html#gaad07cede730cdde64b90e987aad179b8
Mat vconcat(InputArray src1, InputArray src2, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Vconcat(src1.ref, src2.ref, dst!.ref));
return dst;
}
/// Rotate rotates a 2D array in multiples of 90 degrees
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4ad01c0978b0ce64baa246811deeac24
Mat rotate(InputArray src, int rotateCode, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Rotate(src.ref, dst!.ref, rotateCode));
return dst;
}
/// IDCT calculates the inverse Discrete Cosine Transform of a 1D or 2D array.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga77b168d84e564c50228b69730a227ef2
Mat idct(
InputArray src, {
OutputArray? dst,
int flags = 0,
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Idct(src.ref, dst!.ref, flags));
return dst;
}
/// IDFT calculates the inverse Discrete Fourier Transform of a 1D or 2D array.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gaa708aa2d2e57a508f968eb0f69aa5ff1
Mat idft(
InputArray src, {
OutputArray? dst,
int flags = 0,
int nonzeroRows = 0,
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Idft(src.ref, dst!.ref, flags, nonzeroRows));
return dst;
}
/// InRange checks if array elements lie between the elements of two Mat arrays.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga48af0ab51e36436c5d04340e036ce981
Mat inRange(
InputArray src,
InputArray lowerb,
InputArray upperb, {
OutputArray? dst,
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_InRange(src.ref, lowerb.ref, upperb.ref, dst!.ref));
return dst;
}
/// InRangeWithScalar checks if array elements lie between the elements of two Scalars
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga48af0ab51e36436c5d04340e036ce981
Mat inRangebyScalar(
InputArray src,
Scalar lowerb,
Scalar upperb, {
OutputArray? dst,
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_InRangeWithScalar(src.ref, lowerb.ref, upperb.ref, dst!.ref));
return dst;
}
/// InsertChannel inserts a single channel to dst (coi is 0-based index)
/// (it replaces channel i with another in dst).
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga1d4bd886d35b00ec0b764cb4ce6eb515
Mat insertChannel(InputArray src, InputOutputArray dst, int coi) {
cvRun(() => CFFI.Mat_InsertChannel(src.ref, dst.ref, coi));
return dst;
}
/// Invert finds the inverse or pseudo-inverse of a matrix.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gad278044679d4ecf20f7622cc151aaaa2
(double rval, Mat dst) invert(
InputArray src, {
OutputArray? dst,
int flags = DECOMP_LU,
}) {
dst ??= Mat.empty();
final rval = cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(() => CFFI.Mat_Invert(src.ref, dst!.ref, flags, p));
return p.value;
});
return (rval, dst);
}
/// KMeans finds centers of clusters and groups input samples around the clusters.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d5/d38/group__core__cluster.html#ga9a34dc06c6ec9460e90860f15bcd2f88
(double rval, Mat bestLabels, Mat centers) kmeans(
InputArray data,
int K,
InputOutputArray bestLabels,
TermCriteria criteria,
int attempts,
int flags, {
OutputArray? centers,
}) {
centers ??= Mat.empty();
final rval = cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(
() => CFFI.KMeans(data.ref, K, bestLabels.ref, criteria.toNativePtr(arena).ref, attempts,
flags, centers!.ref, p),
);
return p.value;
});
return (rval, bestLabels, centers);
}
/// KMeansPoints finds centers of clusters and groups input samples around the clusters.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d5/d38/group__core__cluster.html#ga9a34dc06c6ec9460e90860f15bcd2f88
(double rval, Mat bestLabels, Mat centers) kmeansByPoints(
VecPoint2f pts,
int K,
InputOutputArray bestLabels,
TermCriteria criteria,
int attempts,
int flags, {
OutputArray? centers,
}) {
centers ??= Mat.empty();
final rval = cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(
() => CFFI.KMeansPoints(pts.ref, K, bestLabels.ref, criteria.toNativePtr(arena).ref, attempts,
flags, centers!.ref, p),
);
return p.value;
});
return (rval, bestLabels, centers);
}
/// Log calculates the natural logarithm of every array element.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga937ecdce4679a77168730830a955bea7
Mat log(InputArray src, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Log(src.ref, dst!.ref));
return dst;
}
/// Performs a look-up table transform of an array. Support CV_8U, CV_8S, CV_16U, CV_16S
///
/// The function LUT fills the output array with values from the look-up table. Indices of the entries
/// are taken from the input array. That is, the function processes each element of src as follows:
///
/// $\texttt{dst} (I) \leftarrow \texttt{lut(src(I) + d)}$
///
/// where
///
/// $d = \fork{0}{if \(\texttt{src}\) has depth \(\texttt{CV_8U}\)}{128}{if \(\texttt{src}\) has depth \(\texttt{CV_8S}\)}$
///
/// [src] input array of 8-bit elements.
/// [lut] look-up table of 256 elements; in case of multi-channel input array, the table should
/// either have a single channel (in this case the same table is used for all channels) or the same
/// number of channels as in the input array.
///
/// [dst] output array of the same size and number of channels as src, and the same depth as lut.
///
/// see also: [convertScaleAbs]
///
/// https://docs.opencv.org/4.x/d2/de8/group__core__array.html#gab55b8d062b7f5587720ede032d34156f
Mat LUT(InputArray src, InputArray lut, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.LUT(src.ref, lut.ref, dst!.ref));
return dst;
}
/// Magnitude calculates the magnitude of 2D vectors.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga6d3b097586bca4409873d64a90fe64c3
Mat magnitude(InputArray x, InputArray y, {OutputArray? magnitude}) {
magnitude ??= Mat.empty();
cvRun(() => CFFI.Mat_Magnitude(x.ref, y.ref, magnitude!.ref));
return magnitude;
}
/// Max calculates per-element maximum of two arrays or an array and a scalar.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gacc40fa15eac0fb83f8ca70b7cc0b588d
Mat max(InputArray src1, InputArray src2, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Max(src1.ref, src2.ref, dst!.ref));
return dst;
}
/// MeanStdDev calculates a mean and standard deviation of array elements.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga846c858f4004d59493d7c6a4354b301d
(Scalar mean, Scalar stddev) meanStdDev(InputArray src, {InputArray? mask}) {
return cvRunArena<(Scalar, Scalar)>((arena) {
final mean = arena<cvg.Scalar>();
final stddev = arena<cvg.Scalar>();
mask == null
? cvRun(() => CFFI.Mat_MeanStdDev(src.ref, mean, stddev))
: cvRun(() => CFFI.Mat_MeanStdDevWithMask(src.ref, mean, stddev, mask.ref));
return (Scalar.fromNative(mean.ref), Scalar.fromNative(stddev.ref));
});
}
/// Merge creates one multi-channel array out of several single-channel ones.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7d7b4d6c6ee504b30a20b1680029c7b4
Mat merge(VecMat mv, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Merge(mv.ref, dst!.ref));
return dst;
}
/// Min calculates per-element minimum of two arrays or an array and a scalar.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga9af368f182ee76d0463d0d8d5330b764
Mat min(InputArray src1, InputArray src2, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_Min(src1.ref, src2.ref, dst!.ref));
return dst;
}
/// MinMaxIdx finds the global minimum and maximum in an array.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7622c466c628a75d9ed008b42250a73f
(double minVal, double maxVal, int minIdx, int maxIdx) minMaxIdx(
InputArray src, {
InputArray? mask,
}) {
return using<(double, double, int, int)>((arena) {
final minValP = arena<ffi.Double>();
final maxValP = arena<ffi.Double>();
final minIdxP = arena<ffi.Int>();
final maxIdxP = arena<ffi.Int>();
cvRun(() => CFFI.Mat_MinMaxIdx(src.ref, minValP, maxValP, minIdxP, maxIdxP));
return (minValP.value, maxValP.value, minIdxP.value, maxIdxP.value);
});
}
/// MinMaxLoc finds the global minimum and maximum in an array.
///
/// For further details, please see:
/// https://docs.opencv.org/trunk/d2/de8/group__core__array.html#gab473bf2eb6d14ff97e89b355dac20707
(double minVal, double maxVal, Point minLoc, Point maxLoc) minMaxLoc(InputArray src,
{InputArray? mask}) {
return using<(double, double, Point, Point)>((arena) {
final minValP = arena<ffi.Double>();
final maxValP = arena<ffi.Double>();
final minLocP = arena<cvg.Point>();
final maxLocP = arena<cvg.Point>();
cvRun(() => CFFI.Mat_MinMaxLoc(src.ref, minValP, maxValP, minLocP, maxLocP));
return (
minValP.value,
maxValP.value,
Point.fromNative(minLocP.ref),
Point.fromNative(maxLocP.ref)
);
});
}
/// Copies specified channels from input arrays to the specified channels of output arrays.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga51d768c270a1cdd3497255017c4504be
VecMat mixChannels(VecMat src, VecMat dst, VecInt fromTo) {
return cvRunArena<VecMat>((arena) {
cvRun(() => CFFI.Mat_MixChannels(src.ref, dst.ref, fromTo.ref));
return dst;
});
}
/// Mulspectrums performs the per-element multiplication of two Fourier spectrums.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga3ab38646463c59bf0ce962a9d51db64f
Mat mulSpectrums(
InputArray a,
InputArray b,
int flags, {
OutputArray? c,
bool conjB = false,
}) {
c ??= Mat.empty();
cvRun(() => CFFI.Mat_MulSpectrums(a.ref, b.ref, c!.ref, flags));
return c;
}
/// Multiply calculates the per-element scaled product of two arrays.
/// Both input arrays must be of the same size and the same type.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga979d898a58d7f61c53003e162e7ad89f
Mat multiply(
InputArray src1,
InputArray src2, {
OutputArray? dst,
double scale = 1,
int dtype = -1,
}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_MultiplyWithParams(src1.ref, src2.ref, dst!.ref, scale, dtype));
return dst;
}
/// Normalize normalizes the norm or value range of an array.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga87eef7ee3970f86906d69a92cbf064bd
Mat normalize(
InputArray src,
InputOutputArray dst, {
double alpha = 1,
double beta = 0,
int normType = NORM_L2,
// TODO
// int dtype = -1,
// InputArray? mask,
}) {
cvRun(() => CFFI.Mat_Normalize(src.ref, dst.ref, alpha, beta, normType));
return dst;
}
/// Norm calculates the absolute norm of an array.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7c331fb8dd951707e184ef4e3f21dd33
double norm(
InputArray src1, {
int normType = NORM_L2,
InputArray? mask,
}) {
return cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(() => CFFI.Norm(src1.ref, normType, p));
return p.value;
});
}
/// Norm calculates the absolute difference/relative norm of two arrays.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga7c331fb8dd951707e184ef4e3f21dd33
double norm1(
InputArray src1,
InputArray src2, {
int normType = NORM_L2,
// InputArray? mask,
}) {
return cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(() => CFFI.NormWithMats(src1.ref, src2.ref, normType, p));
return p.value;
});
}
/// PerspectiveTransform performs the perspective matrix transformation of vectors.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gad327659ac03e5fd6894b90025e6900a7
Mat perspectiveTransform(InputArray src, InputArray m, {OutputArray? dst}) {
dst ??= Mat.empty();
cvRun(() => CFFI.Mat_PerspectiveTransform(src.ref, dst!.ref, m.ref));
return dst;
}
/// Solve solves one or more linear systems or least-squares problems.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga12b43690dbd31fed96f213eefead2373
(bool ret, Mat dst) solve(
InputArray src1,
InputArray src2, {
OutputArray? dst,
int flags = DECOMP_LU,
}) {
dst ??= Mat.empty();
final rval = cvRunArena<bool>((arena) {
final p = arena<ffi.Bool>();
cvRun(() => CFFI.Mat_Solve(src1.ref, src2.ref, dst!.ref, flags, p));
return p.value;
});
return (rval, dst);
}
/// SolveCubic finds the real roots of a cubic equation.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga1c3b0b925b085b6e96931ee309e6a1da
(int rval, Mat roots) solveCubic(InputArray coeffs, {OutputArray? roots}) {
roots ??= Mat.empty();
final rval = cvRunArena<int>((arena) {
final p = arena<ffi.Int>();
cvRun(() => CFFI.Mat_SolveCubic(coeffs.ref, roots!.ref, p));
return p.value;
});
return (rval, roots);
}
/// SolvePoly finds the real or complex roots of a polynomial equation.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#gac2f5e953016fabcdf793d762f4ec5dce
(double rval, Mat roots) solvePoly(
InputArray coeffs, {
OutputArray? roots,
int maxIters = 300,
}) {
roots ??= Mat.empty();
final rval = cvRunArena<double>((arena) {
final p = arena<ffi.Double>();
cvRun(() => CFFI.Mat_SolvePoly(coeffs.ref, roots!.ref, maxIters, p));
return p.value;
});
return (rval, roots);
}
/// Reduce reduces a matrix to a vector.
///
/// For further details, please see:
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga4b78072a303f29d9031d56e5638da78e