1 /*
2 Copyright (c) 2019 Ferhat Kurtulmuş
3 Boost Software License - Version 1.0 - August 17th, 2003
4 Permission is hereby granted, free of charge, to any person or organization
5 obtaining a copy of the software and accompanying documentation covered by
6 this license (the "Software") to use, reproduce, display, distribute,
7 execute, and transmit the Software, and to prepare derivative works of the
8 Software, and to permit third-parties to whom the Software is furnished to
9 do so, all subject to the following:
10 The copyright notices in the Software and this entire statement, including
11 the above license grant, this restriction and the following disclaimer,
12 must be included in all copies of the Software, in whole or in part, and
13 all derivative works of the Software, unless such copies or derivative
14 works are solely in the form of machine-executable object code generated by
15 a source language processor.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
19 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
20 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24 
25 module opencvd.cvcore;
26 
27 import core.stdc.stdint;
28 import std.conv;
29 
30 struct Size {
31     int rows;
32     int cols;
33     alias height = rows;
34     alias width = cols;
35 }
36 
37 struct ByteArray {
38     ubyte* data;
39     int length;
40 }
41 
42 struct CStrings {
43     const char** strs;
44     int length;
45 }
46 
47 struct Scalar {
48     double val1;
49     double val2;
50     double val3;
51     double val4;
52     
53     static Scalar all(double val){
54         return Scalar(val,val,val,val);
55     }
56     
57     double opIndex(int i){
58         return [val1, val2, val3, val4][i];
59     }
60     
61     void opIndexAssign(double val, int i){
62         *[&val1, &val2, &val3, &val4][i] = val;
63     }
64 }
65 
66 alias Color = Scalar;
67 
68 struct Vec4f {
69     float val1;
70     float val2;
71     float val3;
72     float val4;
73     
74     static Vec4f all(float val){
75         return Vec4f(val,val,val,val);
76     }
77     
78     float opIndex(int i){
79         return [val1, val2, val3, val4][i];
80     }
81     
82     void opIndexAssign(float val, int i){
83         *[&val1, &val2, &val3, &val4][i] = val;
84     }
85 }
86 
87 struct Vec4fs {
88     Vec4f* vec4fs;
89     int length;
90     
91     Vec4f opIndex(int i){
92         return vec4fs[i];
93     }
94 }
95 
96 struct Vec3f {
97     float val1;
98     float val2;
99     float val3;
100     
101     static Vec3f all(float val){
102         return Vec3f(val,val,val);
103     }
104     
105     float opIndex(int i){
106         return [val1, val2, val3][i];
107     }
108     
109     void opIndexAssign(float val, int i){
110         *[&val1, &val2, &val3][i] = val;
111     }
112 }
113 
114 struct Vec3fs{
115     Vec3f* vec3fs;
116     int length;
117     
118     Vec3f opIndex(int i){
119         return vec3fs[i];
120     }
121 }
122 
123 struct Vec4i {
124     int val1;
125     int val2;
126     int val3;
127     int val4;
128     
129     static Vec4i all(int val){
130         return Vec4i(val,val,val,val);
131     }
132     
133     int opIndex(int i){
134         return [val1, val2, val3, val4][i];
135     }
136     
137     void opIndexAssign(int val, int i){
138         *[&val1, &val2, &val3, &val4][i] = val;
139     }
140 }
141 
142 struct Vec4is{
143     Vec4i* vec4is;
144     int length;
145     
146     Vec4i opIndex(int i){
147         return vec4is[i];
148     }
149 }
150 
151 struct Vec3i {
152     int val1;
153     int val2;
154     int val3;
155     
156     static Vec3i all(int val){
157         return Vec3i(val,val,val);
158     }
159     
160     int opIndex(int i){
161         return [val1, val2, val3][i];
162     }
163     
164     void opIndexAssign(int val, int i){
165         *[&val1, &val2, &val3][i] = val;
166     }
167 }
168 
169 struct Vec3is {
170     Vec3i* vec3is;
171     int length;
172     
173     Vec3i opIndex(int i){
174         return vec3is[i];
175     }
176 }
177 
178 struct Vec2f {
179     float val1;
180     float val2;
181     
182     static Vec2f all(float val){
183         return Vec2f(val,val);
184     }
185     
186     float opIndex(int i){
187         return [val1, val2][i];
188     }
189     
190     void opIndexAssign(float val, int i){
191         *[&val1, &val2][i] = val;
192     }
193     
194 }
195 
196 struct Vec2fs {
197     Vec2f* vec2fs;
198     int length;
199     
200     Vec2f opIndex(int i){
201         return vec2fs[i];
202     }
203 }
204 
205 struct Vec6f {
206     float val1;
207     float val2;
208     float val3;
209     float val4;
210     float val5;
211     float val6;
212     
213     static Vec6f all(float val){
214         return Vec6f(val,val,val,val,val,val);
215     }
216     
217     float opIndex(int i){
218         return [val1, val2, val3, val4, val5, val6][i];
219     }
220     
221     void opIndexAssign(float val, int i){
222         *[&val1, &val2, &val3, &val4, &val5, &val6][i] = val;
223     }
224 }
225 
226 struct Vec6fs {
227     Vec6f* vec6fs;
228     int length;
229     
230     Vec6f opIndex(int i){
231         return vec6fs[i];
232     }
233 }
234 
235 struct Hierarchy {
236     Scalar* scalars;
237     int length;
238     
239     Scalar opIndex(int i){
240         return scalars[i];
241     }
242 }
243 
244 alias Colors = Hierarchy;
245 
246 struct IntVector {
247     int* val;
248     int length;
249     
250     int opIndex(int i){
251         return val[i];
252     }
253 }
254 
255 struct FloatVector {
256     float* val;
257     int length;
258     
259     float opIndex(int i){
260         return val[i];
261     }
262 }
263 
264 struct Rect {
265     int x;
266     int y;
267     int width;
268     int height;
269 }
270 
271 bool contains(Rect r, Point p){
272     return Rect_Contains(r, p);
273 }
274 
275 struct Rects {
276     Rect* rects;
277     int length;
278     
279     Rect opIndex(int i){
280         return rects[i];
281     }
282 }
283 
284 struct RotatedRect {
285     Contour pts;
286     Rect boundingRect;
287     Point center;
288     Size size;
289     double angle;
290     
291     Point[] points(){
292         return pts.points[0..pts.length];
293     }
294 }
295 
296 struct Point {
297     int x;
298     int y;
299 
300     int opCmp(Point rhs) {
301         if (x < rhs.x) return -1;
302         if (rhs.x < x) return 1;
303         return 0;
304     }
305     
306     void toString(scope void delegate(const(char)[]) sink) const {
307         import std.format;
308         sink("(");
309         formattedWrite(sink, "%d", x);
310         sink(",");
311         formattedWrite(sink, "%d", y);
312         sink(")");
313     }
314     
315     Point2f asFloat(){
316         return Point2f(x.to!float, y.to!float);
317     }
318     
319     Point opMul(double a){
320         return Point((x*a).to!int,(y*a).to!int);
321     }
322 }
323 
324 struct Point2f {
325     float x;
326     float y;
327     
328     Point asInt(){
329         return Point(x.to!int, y.to!int);
330     }
331     
332     Point2f opMul(double a){
333         return Point2f(float(x*a),float(y*a));
334     }
335 }
336 
337 struct Point2fs {
338     Point2f* points;
339     int length;
340     
341     Point2f opIndex(int i){
342         return points[i];
343     }
344 }
345 
346 struct Point2fss {
347     Point2fs* point2fss;
348     int length;
349     
350     Point2fs opIndex(int i){
351         return point2fss[i];
352     }
353 }
354 
355 struct Points {
356     Point* points;
357     int length;
358     
359     Point opIndex(int i){
360         return points[i];
361     }
362 }
363 
364 struct Pointss {
365     Points* pointss;
366     int length;
367     
368     Points opIndex(int i){
369         return pointss[i];
370     }
371 }
372 
373 alias Contour = Points;
374 
375 Point[] asInt(Point2f[] ip){
376     
377     Point[] ret;
378     foreach(j; 0..ip.length){
379         Point p = Point(ip[j].x.to!int, ip[j].y.to!int);
380         ret ~= p;
381     }
382     return ret;
383 }
384 
385 Point[][] asInt(Point2f[][] pts){
386     
387     Point[][] ret;
388     foreach(i; 0..pts.length){
389         Point[] iip;
390         Point2f[] ip = pts[i];
391         foreach(j; 0..ip.length){
392             Point p = Point(ip[j].x.to!int, ip[j].y.to!int);
393             iip ~= p;
394         }
395         ret ~= iip;
396     }
397     return ret;
398 }
399 
400 Point2f[] asFloat(Point[] ip){
401     
402     Point2f[] ret;
403     foreach(j; 0..ip.length){
404         Point2f p = Point2f(ip[j].x.to!float, ip[j].y.to!float);
405         ret ~= p;
406     }
407     return ret;
408 }
409 
410 Point2f[][] asFloat(Point[][] pts){
411     
412     Point2f[][] ret;
413     foreach(i; 0..pts.length){
414         Point2f[] iip;
415         Point[] ip = pts[i];
416         foreach(j; 0..ip.length){
417             Point2f p = Point2f(ip[j].x.to!float, ip[j].y.to!float);
418             iip ~= p;
419         }
420         ret ~= iip;
421     }
422     return ret;
423 }
424 
425 struct Contours {
426     Contour* contours;
427     int length;
428     
429     Contour opIndex(int i){
430         return contours[i];
431     }
432 }
433 
434 struct KeyPoint {
435     double x;
436     double y;
437     double size;
438     double angle;
439     double response;
440     int octave;
441     int classID;
442 }
443 
444 struct KeyPoints {
445     KeyPoint* keypoints;
446     int length;
447     
448     KeyPoint opIndex(int i){
449         return keypoints[i];
450     }
451 }
452 
453 struct DMatch {
454     int queryIdx;
455     int trainIdx;
456     int imgIdx;
457     float distance;
458 }
459 
460 struct DMatches {
461     DMatch* dmatches;
462     int length;
463     
464     DMatch opIndex(int i){
465         return dmatches[i];
466     }
467 }
468 
469 struct MultiDMatches {
470     DMatches* dmatches;
471     int length;
472     
473     DMatches opIndex(int i){
474         return dmatches[i];
475     }
476 }
477 
478 struct Moment {
479     double m00;
480     double m10;
481     double m01;
482     double m20;
483     double m11;
484     double m02;
485     double m30;
486     double m21;
487     double m12;
488     double m03;
489 
490     double mu20;
491     double mu11;
492     double mu02;
493     double mu30;
494     double mu21;
495     double mu12;
496     double mu03;
497 
498     double nu20;
499     double nu11;
500     double nu02;
501     double nu30;
502     double nu21;
503     double nu12;
504     double nu03;
505 }
506 
507 struct Mat {
508     void* p;
509     
510     int rows() {return Mat_Rows(this);}
511     int cols() {return Mat_Cols(this);}
512     int type() {return Mat_Type(this);}
513     int channels(){return Mat_Channels(this);}
514     int step() {return Mat_Step(this);}
515     int height() {return rows();}
516     int width() {return cols();}
517     int total() {return Mat_Total(this);}
518     int flatLength() {return Mat_FlatLength(this);}
519     void* rawDataPtr() {return Mat_DataPtrNoCast(this);}
520     ubyte* ptr(int i) { return Mat_RowPtr(this, i);}
521     Scalar mean() {return Mat_Mean(this);}
522     Mat sqrt() {return Mat_Sqrt(this);}
523     
524     Mat opCall(Rect r){
525         return matFromRect(this, r);
526     }
527     
528     static Mat opCall(){
529         return newMat();
530     }
531     
532     static Mat opCall(int rows, int cols, int mt ){
533         return Mat_NewWithSize(rows, cols, mt);
534     }
535     
536     static Mat opCall( const Scalar ar, int type){
537         return Mat_NewFromScalar(ar, type);
538     }
539 
540     static Mat opCall(const Scalar ar, int rows, int cols, int type){
541         return Mat_NewWithSizeFromScalar(ar, rows, cols, type);
542     }
543 
544     static Mat opCall(int rows, int cols, int type, ByteArray buf){
545         return Mat_NewFromBytes(rows, cols, type, buf);
546     }
547 
548     static Mat opCall(Mat m, int rows, int cols, int type, int prows, int pcols){
549         return Mat_FromPtr(m, rows, cols, type, prows, pcols);
550     }
551 
552     static Mat opCall(int rows, int cols, int type, void* data){
553         return Mat_FromArrayPtr(rows, cols, type, data);
554     }
555     
556     static Mat opCall(Point[] points){
557         return newMatFromContour(points);
558     }
559     
560     void opAssign(Color c){
561         this.setTo(c);
562     }
563     
564     Mat opMul(ubyte a){
565         multiplyUChar(this, a);
566         return this;
567     }
568     
569     Mat opMul(int a){
570         Mat_MultiplyInt(this, a);
571         return this;
572     }
573     
574     Mat opMul(float a){
575         Mat_MultiplyFloat(this, a);
576         return this;
577     }
578     
579     Mat opBinary(string op)(float a){
580         static if (op == "/"){
581             Mat_MultiplyFloat(this, 1.0f/a);
582             return this;
583         }
584         else static if (op == "+"){
585             Mat_AddFloat(this, a);
586             return this;
587         }
588         else static if (op == "-"){
589             Mat_SubtractFloat(this, a);
590             return this;
591         }
592     }
593     
594     Mat opMul(double a){
595         Mat_MultiplyDouble(this, a);
596         return this;
597     }
598     
599     Mat opBinary(string op)(int a){
600         static if (op == "/"){
601             Mat_DivideInt(this, a);
602             return this;
603         }
604         else static if (op == "+"){
605             Mat_AddInt(this, a);
606             return this;
607         }
608         else static if (op == "-"){
609             Mat_SubtractInt(this, a);
610             return this;
611         }
612     }
613     
614     Mat opBinary(string op)(double a){
615         static if (op == "/"){
616             Mat_MultiplyDouble(this, 1.0/a);
617             return this;
618         }
619         else static if (op == "+"){
620             Mat_AddDouble(this, a);
621             return this;
622         }
623         else static if (op == "-"){
624             Mat_SubtractDouble(this, a);
625             return this;
626         }
627     }
628     
629     // so sad that the D does not support struct > 5
630     Mat EQInt(int a){
631         return Mat_EQInt(this, a);
632     }
633     
634     Mat GTInt(int a){
635         return Mat_GTInt(this, a);
636     }
637     
638     Mat GEInt(int a){
639         return Mat_GEInt(this, a);
640     }
641     
642     Mat LTInt(int a){
643         return Mat_LTInt(this, a);
644     }
645     
646     Mat LEInt(int a){
647         return Mat_LEInt(this, a);
648     }
649     Mat NEInt(int a){
650         return Mat_NEInt(this, a);
651     }
652     
653     Mat EQDouble(double a){
654         return Mat_EQDouble(this, a);
655     }
656     
657     Mat GTDouble(double a){
658         return Mat_GTDouble(this, a);
659     }
660     
661     Mat GEDouble(double a){
662         return Mat_GEDouble(this, a);
663     }
664     
665     Mat LTDouble(double a){
666         return Mat_LTDouble(this, a);
667     }
668     
669     Mat LEDouble(double a){
670         return Mat_LEDouble(this, a);
671     }
672     
673     Mat NEDouble(double a){
674         return Mat_NEDouble(this, a);
675     }
676     
677     Mat opBinary(string op)(Mat m){
678         static if (op == "+"){
679             add(this, m, this);
680         }
681         else static if (op == "-"){
682             matSubtract(this, m, this);
683         }
684         return this;
685     }
686     
687     Mat opBinary(string op)(Scalar s){
688         static if (op == "+"){
689             Mat_AddScalar(this, s);
690         }
691         else static if (op == "-"){
692             Mat_AddScalar(this, Scalar(-s.val1, -s.val2, -s.val3, -s.val4));
693         }
694         return this;
695     }
696     
697     Mat opMul(Mat m){
698         Mat_Multiply(this, m, this);
699         return this;
700     }
701     
702     string type2str(){
703         import std.conv;
704         import core.stdc.stdlib;
705         
706         auto chr = _type2str(type());
707         string stype = chr.to!string.dup;
708         free(chr);
709         return stype;
710     }
711 
712     ByteArray byteArray(){ // no reason to use this now. will be removed soon.
713         return Mat_DataPtr(this);
714     }
715 
716     // retuns d array. use it like: double[] myarray = mat.array!double;
717     T[] array(T)(){
718         T* ret = cast(T*)rawDataPtr();
719         return ret[0..flatLength()];
720     }
721     
722     Scalar opIndex(int row, int col){
723         return at(row, col);
724     }
725     
726     /* Setters */
727     void opIndexAssign(Scalar color, int row, int col){
728         Mat_SetColorAt(this, color, row, col);
729     }
730     
731     void setColorAt(Scalar color, int row, int col){
732         Mat_SetColorAt(this, color, row, col);
733     }
734     
735     
736     void setUCharAt(int row, int col, ubyte val){
737         assert((row < rows()) && (col < cols()), "index out of bounds!");
738         Mat_SetUChar(this, row, col, val);
739     }
740 
741     void setUChar3At( int x, int y, int z, ubyte val){
742         // assert((x < rows()) && (y < cols()) && (z < channels()), "index out of bounds!"); // ??
743         Mat_SetUChar3(this, x, y, z, val);
744     }
745 
746     void setSCharAt(int row, int col, byte val){
747         assert((row < rows()) && (col < cols()), "index out of bounds!");
748         Mat_SetSChar(this, row, col, val);
749     }
750 
751     void setSChar3At(int x, int y, int z, byte val){
752         Mat_SetSChar3(this, x, y, z, val);
753     }
754     
755     void setShortAt(int row, int col, short val){
756         assert((row < rows()) && (col < cols()), "index out of bounds!");
757         Mat_SetShort(this, row, col, val);    
758     }
759     
760     void setShort3At(int x, int y, int z, short val){
761         Mat_SetShort3(this, x, y, z, val);   
762     }
763     
764     void setIntAt(int row, int col, int val){
765         assert((row < rows()) && (col < cols()), "index out of bounds!");
766         Mat_SetInt(this, row, col, val);
767     }
768     
769     void setInt3At(int x, int y, int z, int val){
770         Mat_SetInt3(this, x, y, z, val);
771     }
772     
773     void setFloatAt(int row, int col, float val){
774         assert((row < rows()) && (col < cols()), "index out of bounds!");
775         Mat_SetFloat(this, row, col, val);
776     }
777     
778     void setFloat3At(int x, int y, int z, float val){
779         Mat_SetFloat3(this, x, y, z, val);
780     }
781     
782     void setDoubleAt(int row, int col, double val){
783         assert((row < rows()) && (col < cols()), "index out of bounds!");
784         Mat_SetDouble(this, row, col, val);
785     }
786 
787     void setDouble3At(int x, int y, int z, double val){
788         Mat_SetDouble3(this, x, y, z, val);
789     }
790 
791     /* Getters */
792     
793     T at(T)(int row, int col){
794         //assert(channels() == 1, "only single channel Mats are supported for at");
795         T* ret = cast(T*)rawDataPtr();
796         return ret[row * cols() + col];
797     }
798     
799     T at(T)(int flatInd){
800         assert(channels() == 1, "only single channel Mats are supported for at");
801         T* ret = cast(T*)rawDataPtr();
802         return ret[flatInd];
803     }
804     
805     Color at(int row, int col){
806         return Mat_ColorAt(this, row, col);
807     }
808     
809     ubyte getUCharAt(int row, int col){
810         assert((row < rows()) && (col < cols()), "index out of bounds!");
811         return Mat_GetUChar(this, row, col);
812     }
813 
814     ubyte getUChar3At(int x, int y, int z){
815         return Mat_GetUChar3(this, x, y, z);
816     }
817 
818     byte getSCharAt(int row, int col){
819         assert((row < rows()) && (col < cols()), "index out of bounds!");
820         return Mat_GetSChar(this, row, col);
821     }
822 
823     byte getSChar3At(int x, int y, int z){
824         return Mat_GetSChar3(this, x, y, z);
825     }
826 
827     short getShortAt(int row, int col){
828         assert((row < rows()) && (col < cols()), "index out of bounds!");
829         return Mat_GetShort(this, row, col);
830     }
831 
832     short getShort3At(int x, int y, int z){
833         return Mat_GetShort3(this, x, y, z);
834     }
835 
836     int getIntAt(int row, int col){
837         assert((row < rows()) && (col < cols()), "index out of bounds!");
838         return Mat_GetInt(this, row, col);
839     }
840 
841     int getInt3At(int x, int y, int z){
842         return Mat_GetInt3(this, x, y, z);
843     }
844 
845     float getFloatAt(int row, int col){
846         //assert((row < rows()) && (col < cols()), "index out of bounds!");
847         return Mat_GetFloat(this, row, col);
848     }
849 
850     float getFloat3At(int x, int y, int z){
851         return Mat_GetFloat3(this, x, y, z);
852     }
853 
854     double getDoubleAt(int row, int col){
855         assert((row < rows()) && (col < cols()), "index out of bounds!");
856         return Mat_GetDouble(this, row, col);
857     }
858 
859     double getDouble3At(int x, int y, int z){
860         return Mat_GetDouble3(this, x, y, z);
861     }
862     
863 }
864 
865 struct Mats {
866     Mat* mats;
867     int length;
868     
869     Mat opIndex(int i){
870         return mats[i];
871     }
872 }
873 
874 enum: int {
875     // MatChannels1 is a single channel Mat.
876     MatChannels1 = 0,
877 
878     // MatChannels2 is 2 channel Mat.
879     MatChannels2 = 8,
880 
881     // MatChannels3 is 3 channel Mat.
882     MatChannels3 = 16,
883 
884     // MatChannels4 is 4 channel Mat.
885     MatChannels4 = 24
886 }
887 
888 enum: int {
889     // CV8U is a Mat of 8-bit unsigned int
890     CV8U = 0,
891 
892     // CV8S is a Mat of 8-bit signed int
893     CV8S = 1,
894 
895     // CV16U is a Mat of 16-bit unsigned int
896     CV16U = 2,
897 
898     // CV16S is a Mat of 16-bit signed int
899     CV16S = 3,
900 
901     // CV16SC2 is a Mat of 16-bit signed int with 2 channels
902     CV16SC2 = CV16S + MatChannels2,
903 
904     // CV32S is a Mat of 32-bit signed int
905     CV32S = 4,
906 
907     // CV32F is a Mat of 32-bit float
908     CV32F = 5,
909 
910     // CV64F is a Mat of 64-bit float
911     CV64F = 6,
912 
913     // CV8UC1 is a Mat of 8-bit unsigned int with a single channel
914     CV8UC1 = CV8U + MatChannels1,
915 
916     // CV8UC2 is a Mat of 8-bit unsigned int with 2 channels
917     CV8UC2 = CV8U + MatChannels2,
918 
919     // MatTypeCV8UC3 is a Mat of 8-bit unsigned int with 3 channels
920     CV8UC3 = CV8U + MatChannels3,
921 
922     // MatTypeCV8UC4 is a Mat of 8-bit unsigned int with 4 channels
923     CV8UC4 = CV8U + MatChannels4
924 }
925 
926 alias MatType = int;
927 
928 extern (C) {
929     void Close_Vec6fs(Vec6fs vec6fs);
930     void Close_Vec4fs(Vec4fs vec4fs);
931     void Close_Vec3fs(Vec3fs vec3fs);
932     void Close_Vec2fs(Vec2fs vec2fs);
933     void Close_Vec4is(Vec4is vec4is);
934     void Close_Vec3is(Vec3is vec3is);
935     void Close_IntVector(IntVector iv);
936     
937     void Contours_Close(Contours cs);
938     void KeyPoints_Close(KeyPoints ks);
939     void Rects_Close(Rects rs);
940     void Mats_Close(Mats mats);
941     void Point_Close(Point p);
942     void Points_Close(Points ps);
943     void DMatches_Close(DMatches ds);
944     void MultiDMatches_Close(MultiDMatches mds);
945 }
946 
947 private extern (C) {
948     
949     Mat Mat_New();
950     Mat Mat_NewWithSize(int rows, int cols, int type);
951     Mat Mat_NewFromScalar(const Scalar ar, int type);
952     Mat Mat_NewWithSizeFromScalar(const Scalar ar, int rows, int cols, int type);
953     Mat Mat_NewFromBytes(int rows, int cols, int type, ByteArray buf);
954     Mat Mat_FromPtr(Mat m, int rows, int cols, int type, int prows, int pcols);
955     Mat Mat_FromArrayPtr(int rows, int cols, int type, void* data);
956     Mat Mat_FromContour(Contour points);
957     ubyte* Mat_RowPtr(Mat m, int i);
958     
959     int Mat_Rows(Mat m);
960     int Mat_Cols(Mat m);
961     int Mat_Type(Mat m);
962     int Mat_Channels(Mat m);
963     int Mat_Step(Mat m);
964     
965     char* _type2str(int type);
966 
967     ByteArray Mat_DataPtr(Mat m);
968     int Mat_FlatLength(Mat src);
969     void* Mat_DataPtrNoCast(Mat src);
970     Scalar Mat_ColorAt(Mat src, int row, int col);
971     
972     Mat Mat_Reshape(Mat m, int cn, int rows);
973 
974     void Mat_Close(Mat m);
975     int Mat_Empty(Mat m);
976     Mat Mat_Clone(Mat m);
977     void Mat_CopyTo(Mat m, Mat dst);
978     void Mat_CopyToWithMask(Mat m, Mat dst, Mat mask);
979     void Mat_ConvertTo(Mat m, Mat dst, int type);
980     void Mat_convertTo2(Mat m, Mat dst, int rtype, double alpha, double beta);
981 
982     int Mat_Total(Mat m);
983     Scalar Mat_Mean(Mat m);
984     Mat Mat_Sqrt(Mat m);
985     
986     void Mat_SetColorAt(Mat src, Scalar color, int row, int col);
987     void Mat_SetTo(Mat m, Scalar value);
988     void Mat_SetUChar(Mat m, int row, int col, uint8_t val);
989     void Mat_SetUChar3(Mat m, int x, int y, int z, uint8_t val);
990     void Mat_SetSChar(Mat m, int row, int col, int8_t val);
991     void Mat_SetSChar3(Mat m, int x, int y, int z, int8_t val);
992     void Mat_SetShort(Mat m, int row, int col, int16_t val);
993     void Mat_SetShort3(Mat m, int x, int y, int z, int16_t val);
994     void Mat_SetInt(Mat m, int row, int col, int32_t val);
995     void Mat_SetInt3(Mat m, int x, int y, int z, int32_t val);
996     void Mat_SetFloat(Mat m, int row, int col, float val);
997     void Mat_SetFloat3(Mat m, int x, int y, int z, float val);
998     void Mat_SetDouble(Mat m, int row, int col, double val);
999     void Mat_SetDouble3(Mat m, int x, int y, int z, double val);
1000 
1001     uint8_t Mat_GetUChar(Mat m, int row, int col);
1002     uint8_t Mat_GetUChar3(Mat m, int x, int y, int z);
1003     int8_t Mat_GetSChar(Mat m, int row, int col);
1004     int8_t Mat_GetSChar3(Mat m, int x, int y, int z);
1005     int16_t Mat_GetShort(Mat m, int row, int col);
1006     int16_t Mat_GetShort3(Mat m, int x, int y, int z);
1007     int32_t Mat_GetInt(Mat m, int row, int col);
1008     int32_t Mat_GetInt3(Mat m, int x, int y, int z);
1009     float Mat_GetFloat(Mat m, int row, int col);
1010     float Mat_GetFloat3(Mat m, int x, int y, int z);
1011     double Mat_GetDouble(Mat m, int row, int col);
1012     double Mat_GetDouble3(Mat m, int x, int y, int z);
1013 
1014     Mat Mat_Region(Mat m, Rect r);
1015     void Mat_PatchNaNs(Mat m);
1016     
1017     void Mat_MultiplyInt(Mat m, int val);
1018     void Mat_DivideInt(Mat m, int val);
1019     void Mat_AddDouble(Mat m, double val);
1020     void Mat_SubtractDouble(Mat m, double val);
1021     void Mat_AddInt(Mat m, int val);
1022     void Mat_SubtractInt(Mat m, int val);
1023     void Mat_AddScalar(Mat m, Scalar s);
1024     
1025     Mat Mat_EQInt(Mat m, int a);
1026     Mat Mat_GTInt(Mat m, int a);
1027     Mat Mat_GEInt(Mat m, int a);
1028     Mat Mat_LTInt(Mat m, int a);
1029     Mat Mat_LEInt(Mat m, int a);
1030     Mat Mat_NEInt(Mat m, int a);
1031 
1032     Mat Mat_EQDouble(Mat m, double a);
1033     Mat Mat_GTDouble(Mat m, double a);
1034     Mat Mat_GEDouble(Mat m, double a);
1035     Mat Mat_LTDouble(Mat m, double a);
1036     Mat Mat_LEDouble(Mat m, double a);
1037     Mat Mat_NEDouble(Mat m, double a);
1038     
1039     void Mat_AddUChar(Mat m, uint8_t val);
1040     void Mat_SubtractUChar(Mat m, uint8_t val);
1041     void Mat_MultiplyUChar(Mat m, uint8_t val);
1042     void Mat_DivideUChar(Mat m, uint8_t val);
1043     void Mat_AddFloat(Mat m, float val);
1044     void Mat_SubtractFloat(Mat m, float val);
1045     void Mat_MultiplyFloat(Mat m, float val);
1046     void Mat_MultiplyDouble(Mat m, double val);
1047     void Mat_DivideFloat(Mat m, float val);
1048 
1049     void LUT(Mat src, Mat lut, Mat dst);
1050 
1051     void Mat_AbsDiff(Mat src1, Mat src2, Mat dst);
1052     void Mat_Add(Mat src1, Mat src2, Mat dst);
1053     void Mat_AddWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst);
1054     void Mat_BitwiseAnd(Mat src1, Mat src2, Mat dst);
1055     void Mat_BitwiseAndWithMask(Mat src1, Mat src2, Mat dst, Mat mask);
1056     void Mat_BitwiseNot(Mat src1, Mat dst);
1057     void Mat_BitwiseNotWithMask(Mat src1, Mat dst, Mat mask);
1058     void Mat_BitwiseOr(Mat src1, Mat src2, Mat dst);
1059     void Mat_BitwiseOrWithMask(Mat src1, Mat src2, Mat dst, Mat mask);
1060     void Mat_BitwiseXor(Mat src1, Mat src2, Mat dst);
1061     void Mat_BitwiseXorWithMask(Mat src1, Mat src2, Mat dst, Mat mask);
1062     void Mat_Compare(Mat src1, Mat src2, Mat dst, int ct);
1063     void Mat_CompareWithScalar(Mat src1, Scalar src2, Mat dst, int ct);
1064     void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, Mat mask, int update, bool crosscheck);
1065     int Mat_BorderInterpolate(int p, int len, int borderType);
1066     void Mat_CalcCovarMatrix(Mat samples, Mat covar, Mat mean, int flags, int ctype);
1067     void Mat_CartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, bool angleInDegrees);
1068     bool Mat_CheckRange(Mat m);
1069     void Mat_CompleteSymm(Mat m, bool lowerToUpper);
1070     void Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta);
1071     void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, Scalar value);
1072     int Mat_CountNonZero(Mat src);
1073     void Mat_DCT(Mat src, Mat dst, int flags);
1074     double Mat_Determinant(Mat m);
1075     void Mat_DFT(Mat m, Mat dst, int flags);
1076     void Mat_Divide(Mat src1, Mat src2, Mat dst);
1077     bool Mat_Eigen(Mat src, Mat eigenvalues, Mat eigenvectors);
1078     void Mat_EigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors);
1079     void Mat_Exp(Mat src, Mat dst);
1080     void Mat_ExtractChannel(Mat src, Mat dst, int coi);
1081     void Mat_FindNonZero(Mat src, Mat idx);
1082     void Mat_Flip(Mat src, Mat dst, int flipCode);
1083     void Mat_Gemm(Mat src1, Mat src2, double alpha, Mat src3, double beta, Mat dst, int flags);
1084     int Mat_GetOptimalDFTSize(int vecsize);
1085     void Mat_Hconcat(Mat src1, Mat src2, Mat dst);
1086     void Mat_Vconcat(Mat src1, Mat src2, Mat dst);
1087     void Rotate(Mat src, Mat dst, int rotationCode);
1088     void Mat_Idct(Mat src, Mat dst, int flags);
1089     void Mat_Idft(Mat src, Mat dst, int flags, int nonzeroRows);
1090     void Mat_InRange(Mat src, Mat lowerb, Mat upperb, Mat dst);
1091     void Mat_InRangeWithScalar(Mat src, const Scalar lowerb, const Scalar upperb, Mat dst);
1092     void Mat_InsertChannel(Mat src, Mat dst, int coi);
1093     double Mat_Invert(Mat src, Mat dst, int flags);
1094     void Mat_Log(Mat src, Mat dst);
1095     void Mat_Magnitude(Mat x, Mat y, Mat magnitude);
1096     void Mat_Max(Mat src1, Mat src2, Mat dst);
1097     void Mat_MeanStdDev(Mat src, Mat dstMean, Mat dstStdDev);
1098     void Mat_Merge(Mats mats, Mat dst);
1099     void Mat_Merge2(Mats mats, int count, Mat dst);
1100     void Mat_Min(Mat src1, Mat src2, Mat dst);
1101     void Mat_MinMaxIdx(Mat m, double* minVal, double* maxVal, int* minIdx, int* maxIdx);
1102     void Mat_MinMaxLoc(Mat m, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc);
1103     void Mat_MinMaxLoc2(Mat a, double* minVal, double* maxVal, int* minIdx, int* maxIdx);
1104     void Mat_MulSpectrums(Mat a, Mat b, Mat c, int flags);
1105     void Mat_Multiply(Mat src1, Mat src2, Mat dst);
1106     void Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ);
1107     double Norm(Mat src1, int normType);
1108     void Mat_PerspectiveTransform(Mat src, Mat dst, Mat tm);
1109     bool Mat_Solve(Mat src1, Mat src2, Mat dst, int flags);
1110     int Mat_SolveCubic(Mat coeffs, Mat roots);
1111     double Mat_SolvePoly(Mat coeffs, Mat roots, int maxIters);
1112     void Mat_Reduce(Mat src, Mat dst, int dim, int rType, int dType);
1113     void Mat_Repeat(Mat src, int nY, int nX, Mat dst);
1114     void Mat_ScaleAdd(Mat src1, double alpha, Mat src2, Mat dst);
1115     void Mat_Sort(Mat src, Mat dst, int flags);
1116     void Mat_SortIdx(Mat src, Mat dst, int flags);
1117     void Mat_Split(Mat src, Mats* mats);
1118     Mats Mat_Split2(Mat src);
1119     void Mat_Subtract(Mat src1, Mat src2, Mat dst);
1120     Scalar Mat_Trace(Mat src);
1121     void Mat_Transform(Mat src, Mat dst, Mat tm);
1122     void Mat_Transpose(Mat src, Mat dst);
1123     void Mat_PolarToCart(Mat magnitude, Mat degree, Mat x, Mat y, bool angleInDegrees);
1124     void Mat_Pow(Mat src, double power, Mat dst);
1125     void Mat_Phase(Mat x, Mat y, Mat angle, bool angleInDegrees);
1126     Scalar Mat_Sum(Mat src1);
1127 
1128     TermCriteria TermCriteria_New(int typ, int maxCount, double epsilon);
1129 
1130     int64_t GetCVTickCount();
1131     double GetTickFrequency();
1132     
1133     Mat Mat_ZerosFromRC(int rows, int cols, int type);
1134     Mat Mat_ZerosFromSize(Size sz, int type);
1135     Mat Mat_OnesFromRC(int rows, int cols, int type);
1136     Mat Mat_OnesFromSize(Size sz, int type);
1137     
1138     double Mat_Dot(Mat m1, Mat m2); // TODO: implement operator overload
1139     Mat Mat_Diag(Mat src, int d);
1140     Mat Mat_EyeFromRC(int rows, int cols, int type);
1141     
1142     bool Rect_Contains(Rect r, Point p);
1143 }
1144 
1145 
1146 Mat newMat(){
1147     return Mat_New();
1148 }
1149 
1150 Mat newMatWithSize( int rows, int cols, int mt ){
1151     return Mat_NewWithSize(rows, cols, mt);
1152 }
1153 
1154 Mat newMatFromScalar( const Scalar ar, int type){
1155     return Mat_NewFromScalar(ar, type);
1156 }
1157 
1158 Mat newMatWithSizeFromScalar(const Scalar ar, int rows, int cols, int type){
1159     return Mat_NewWithSizeFromScalar(ar, rows, cols, type);
1160 }
1161 
1162 Mat newMatFromBytes(int rows, int cols, int type, ByteArray buf){
1163     return Mat_NewFromBytes(rows, cols, type, buf);
1164 }
1165 
1166 Mat newMatFromPtr(Mat m, int rows, int cols, int type, int prows, int pcols){
1167     return Mat_FromPtr(m, rows, cols, type, prows, pcols);
1168 }
1169 
1170 Mat newMatFromArrayPtr(int rows, int cols, int type, void* data){
1171     return Mat_FromArrayPtr(rows, cols, type, data);
1172 }
1173 
1174 Mat newMatFromContour(Point[] pts){
1175     return Mat_FromContour(Contour(pts.ptr, pts.length.to!int));
1176 }
1177 
1178 Mat zeros(int rows, int cols, int type){
1179     return Mat_ZerosFromRC(rows, cols, type);
1180 }
1181 
1182 Mat zeros(Size sz, int type){
1183     return Mat_ZerosFromSize(sz, type);
1184 }
1185 
1186 Mat ones(int rows, int cols, int type){
1187     return Mat_OnesFromRC(rows, cols, type);
1188 }
1189 Mat ones(Size sz, int type){
1190     return Mat_OnesFromSize(sz, type);
1191 }
1192 
1193 Size getSize(Mat m){
1194     return Size(m.rows, m.cols);
1195 }
1196 
1197 Mat reshape(Mat m, int cn, int rows){
1198     return Mat_Reshape( m, cn, rows);
1199 }
1200 
1201 void Destroy(Mat m){
1202     Mat_Close(m);
1203 }
1204 
1205 bool isEmpty(Mat m){
1206     return Mat_Empty(m) == 0 ? false: true;
1207 }
1208 
1209 alias empty = isEmpty;
1210 
1211 Mat clone(Mat m){
1212     return Mat_Clone(m);
1213 }
1214 
1215 void copyTo(Mat m, Mat dst){
1216     Mat_CopyTo(m, dst);
1217 }
1218 
1219 void copyToWithMask(Mat m, Mat dst, Mat mask){
1220     Mat_CopyToWithMask(m, dst, mask);
1221 }
1222 
1223 void convertTo(Mat m, Mat dst, int type){
1224     Mat_ConvertTo(m, dst, type);
1225 }
1226 
1227 void convertTo(Mat m, Mat dst, int rtype, double alpha = 1, double beta = 0 ){
1228     Mat_convertTo2(m, dst, rtype, alpha, beta);
1229 }
1230 
1231 void setTo(Mat m, Scalar s){
1232     Mat_SetTo(m, s);
1233 }
1234 
1235 void patchNaNs(Mat m){
1236     Mat_PatchNaNs(m);
1237 }
1238 
1239 Mat matFromRect(Mat m, Rect r){
1240     return Mat_Region(m, r);
1241 }
1242 
1243 alias subImageFromROI = matFromRect;
1244 
1245 void addUChar(Mat m, ubyte val){
1246     Mat_AddUChar(m, val);
1247 }
1248 
1249 void subtractUChar(Mat m, ubyte val){
1250     Mat_SubtractUChar(m, val);
1251 }
1252 
1253 void multiplyUChar(Mat m, ubyte val){
1254     Mat_MultiplyUChar(m, val);
1255 }
1256 
1257 void divideUChar(Mat m, ubyte val){
1258     Mat_DivideUChar(m, val);
1259 }
1260 
1261 void addFloat(Mat m, float val){
1262     Mat_AddFloat(m, val);
1263 }
1264 
1265 void subtractFloat(Mat m, float val){
1266     Mat_SubtractFloat(m, val);
1267 }
1268 
1269 void multiplyFloat(Mat m, float val){
1270     multiplyFloat(m, val);
1271 }
1272 
1273 void multiplyDouble(Mat m, double val){
1274     Mat_MultiplyDouble(m, val);
1275 }
1276 
1277 void divideFloat(Mat m, float val){
1278     Mat_DivideFloat(m, val);
1279 }
1280 
1281 void multiplyInt(Mat m, int val){
1282     Mat_MultiplyInt(m, val);
1283 }
1284 
1285 void divideInt(Mat m, int val){
1286     Mat_DivideInt(m, val);
1287 }
1288 
1289 void addDouble(Mat m, double val){
1290     Mat_AddDouble(m, val);
1291 }
1292 
1293 void subtractDouble(Mat m, double val){
1294     Mat_SubtractDouble(m, val);
1295 }
1296 
1297 void addInt(Mat m, int val){
1298     Mat_AddInt(m, val);
1299 }
1300 
1301 void subtractInt(Mat m, int val){
1302     Mat_SubtractInt(m, val);
1303 }
1304 
1305 
1306 void performLUT(Mat src, Mat lut, Mat dst){
1307     LUT(src, lut, dst);
1308 }
1309 
1310 void absDiff(Mat src1, Mat src2, Mat dst){
1311     Mat_AbsDiff(src1, src2, dst);
1312 }
1313 
1314 void add(Mat src1, Mat src2, Mat dst){
1315     Mat_Add(src1, src2, dst);
1316 }
1317 
1318 void addScalar(Mat m, Scalar s){
1319     Mat_AddScalar(m, s);
1320 }
1321 
1322 void addWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst){
1323     Mat_AddWeighted(src1, alpha, src2, beta, gamma, dst);
1324 }
1325 
1326 void bitwiseAnd(Mat src1, Mat src2, Mat dst){
1327     Mat_BitwiseAnd(src1, src2, dst);
1328 }
1329 
1330 void bitwiseAndWithMask(Mat src1, Mat src2, Mat dst, Mat mask){
1331     Mat_BitwiseAndWithMask(src1, src2, dst, mask);
1332 }
1333 
1334 void bitwiseNot(Mat src1, Mat dst){
1335     Mat_BitwiseNot(src1, dst);
1336 }
1337 
1338 void bitwiseNotWithMask(Mat src1, Mat dst, Mat mask){
1339     Mat_BitwiseNotWithMask(src1, dst, mask);
1340 }
1341 
1342 void bitwiseOr(Mat src1, Mat src2, Mat dst){
1343     Mat_BitwiseOr(src1, src2, dst);
1344 }
1345 
1346 void bitwiseOrWithMask(Mat src1, Mat src2, Mat dst, Mat mask){
1347     Mat_BitwiseOrWithMask(src1, src2, dst, mask);
1348 }
1349 
1350 void bitwiseXor(Mat src1, Mat src2, Mat dst){
1351     Mat_BitwiseXor(src1, src2, dst);
1352 }
1353 
1354 void bitwiseXorWithMask(Mat src1, Mat src2, Mat dst, Mat mask){
1355     Mat_BitwiseXorWithMask(src1, src2, dst, mask);
1356 }
1357 
1358 enum: int {
1359     // enum cv::CmpTypes
1360     CMP_EQ,
1361     CMP_GT,
1362     CMP_GE,
1363     CMP_LT,
1364     CMP_LE,
1365     CMP_NE,
1366 }
1367 
1368 void compare(Mat src1, Mat src2, Mat dst, int ct){
1369     Mat_Compare(src1, src2, dst, ct);
1370 }
1371 
1372 void compare(Mat src1, Scalar src2, Mat dst, int ct){
1373     Mat_CompareWithScalar(src1, src2, dst, ct);
1374 }
1375 
1376 void batchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, Mat mask, int update, bool crosscheck){
1377     Mat_BatchDistance(src1, src2, dist, dtype, nidx, normType, K, mask, update, crosscheck);
1378 }
1379 
1380 enum: int {
1381 	// CovarScrambled indicates to scramble the results.
1382 	CovarScrambled = 0,
1383 
1384 	// CovarNormal indicates to use normal covariation.
1385 	CovarNormal = 1,
1386 
1387 	// CovarUseAvg indicates to use average covariation.
1388 	CovarUseAvg = 2,
1389 
1390 	// CovarScale indicates to use scaled covariation.
1391 	CovarScale = 4,
1392 
1393 	// CovarRows indicates to use covariation on rows.
1394 	CovarRows = 8,
1395 
1396 	// CovarCols indicates to use covariation on columns.
1397 	CovarCols = 16,
1398 }
1399 alias CovarFlags = int;
1400 
1401 int borderInterpolate(int p, int len, CovarFlags borderType){
1402     return Mat_BorderInterpolate(p, len, borderType);
1403 }
1404 
1405 void calcCovarMatrix(Mat samples, Mat covar, Mat mean, CovarFlags flags, int ctype){
1406     Mat_CalcCovarMatrix(samples, covar, mean, flags, ctype);
1407 }
1408 
1409 void cartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, bool angleInDegrees){
1410     Mat_CartToPolar(x, y, magnitude, angle, angleInDegrees);
1411 }
1412 
1413 bool checkRange(Mat m){
1414     return Mat_CheckRange(m);
1415 }
1416 
1417 void completeSymm(Mat m, bool lowerToUpper){
1418     Mat_CompleteSymm(m, lowerToUpper);
1419 }
1420 
1421 void convertScaleAbs(Mat src, Mat dst, double alpha = 1, double beta = 0){
1422     Mat_ConvertScaleAbs(src, dst, alpha, beta);
1423 }
1424 
1425 void copyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, CovarFlags borderType, Scalar value){
1426     Mat_CopyMakeBorder(src, dst, top, bottom, left, right, borderType, value);
1427 }
1428 
1429 enum: int {
1430     // DftForward performs forward 1D or 2D dft or dct.
1431     DftForward  = 0,
1432 
1433     // DftInverse performs an inverse 1D or 2D transform.
1434     DftInverse = 1,
1435 
1436     // DftScale scales the result: divide it by the number of array elements. Normally, it is combined with DFT_INVERSE.
1437     DftScale = 2,
1438 
1439     // DftRows performs a forward or inverse transform of every individual row of the input matrix.
1440     DftRows = 4,
1441 
1442     // DftComplexOutput performs a forward transformation of 1D or 2D real array; the result, though being a complex array, has complex-conjugate symmetry
1443     DftComplexOutput = 16,
1444 
1445     // DftRealOutput performs an inverse transformation of a 1D or 2D complex array; the result is normally a complex array of the same size,
1446     // however, if the input array has conjugate-complex symmetry (for example, it is a result of forward transformation with DFT_COMPLEX_OUTPUT flag),
1447     // the output is a real array.
1448     DftRealOutput = 32,
1449 
1450     // DftComplexInput specifies that input is complex input. If this flag is set, the input must have 2 channels.
1451     DftComplexInput = 64,
1452 
1453     // DctInverse performs an inverse 1D or 2D dct transform.
1454     DctInverse = DftInverse,
1455 
1456     // DctRows performs a forward or inverse dct transform of every individual row of the input matrix.
1457     DctRows = DftRows
1458 }
1459 
1460 alias DftFlags = int;
1461 
1462 int countNonZero(Mat src){
1463     return Mat_CountNonZero(src);
1464 }
1465 
1466 void DCT(Mat src, Mat dst, int flags){
1467     Mat_DCT(src, dst, flags);
1468 }
1469 
1470 double determinant(Mat m){
1471     return Mat_Determinant(m);
1472 }
1473 
1474 void DFT(Mat m, Mat dst, DftFlags flags){
1475     Mat_DFT(m, dst, flags);
1476 }
1477 
1478 void divide(Mat src1, Mat src2, Mat dst){
1479     Mat_Divide(src1, src2, dst);
1480 }
1481 
1482 bool eigen(Mat src, Mat eigenvalues, Mat eigenvectors){
1483     return Mat_Eigen(src, eigenvalues, eigenvectors);
1484 }
1485 
1486 void eigenNonSymmetric(Mat src, Mat eigenvalues, Mat eigenvectors){
1487     Mat_EigenNonSymmetric(src, eigenvalues, eigenvectors);
1488 }
1489 
1490 void matExp(Mat src, Mat dst){
1491     Mat_Exp(src, dst);
1492 }
1493 
1494 void extractChannel(Mat src, Mat dst, int coi){
1495     Mat_ExtractChannel(src, dst, coi);
1496 }
1497 
1498 void findNonZero(Mat src, Mat idx){
1499     Mat_FindNonZero(src, idx);
1500 }
1501 
1502 void flip(Mat src, Mat dst, int flipCode){
1503     Mat_Flip(src, dst, flipCode);
1504 }
1505 
1506 void gemm(Mat src1, Mat src2, double alpha, Mat src3, double beta, Mat dst, int flags){
1507     Mat_Gemm(src1, src2, alpha, src3, beta, dst, flags);
1508 }
1509 
1510 int getOptimalDFTSize(int vecsize){
1511     return Mat_GetOptimalDFTSize(vecsize);
1512 }
1513 
1514 void hconcat(Mat src1, Mat src2, Mat dst){
1515     Mat_Hconcat(src1, src2, dst);
1516 }
1517 
1518 void vconcat(Mat src1, Mat src2, Mat dst){
1519     Mat_Vconcat(src1, src2, dst);
1520 }
1521 
1522 void rotate(Mat src, Mat dst, int rotationCode){
1523     Rotate(src, dst, rotationCode);
1524 }
1525 
1526 void idct(Mat src, Mat dst, int flags){
1527     Mat_Idct(src, dst, flags);
1528 }
1529 
1530 void idft(Mat src, Mat dst, int flags, int nonzeroRows){
1531     Mat_Idft(src, dst, flags, nonzeroRows);
1532 }
1533 
1534 void inRange(Mat src, Mat lowerb, Mat upperb, Mat dst){
1535     Mat_InRange(src, lowerb, upperb, dst);
1536 }
1537 
1538 void inRange(Mat src, const Scalar lowerb, const Scalar upperb, Mat dst){
1539     Mat_InRangeWithScalar(src, lowerb, upperb, dst);
1540 }
1541 
1542 void insertChannel(Mat src, Mat dst, int coi){
1543     Mat_InsertChannel(src, dst, coi);
1544 }
1545 
1546 double invert(Mat src, Mat dst, int flags){
1547     return Mat_Invert(src, dst, flags);
1548 }
1549 
1550 void matLog(Mat src, Mat dst){
1551     Mat_Log(src, dst);
1552 }
1553 
1554 void magnitude(Mat x, Mat y, Mat magnitude){
1555     Mat_Magnitude(x, y, magnitude);
1556 }
1557 
1558 void matMax(Mat src1, Mat src2, Mat dst){
1559     Mat_Max(src1, src2, dst);
1560 }
1561 
1562 void meanStdDev(Mat src, Mat dstMean, Mat dstStdDev){
1563     Mat_MeanStdDev(src, dstMean, dstStdDev);
1564 }
1565 
1566 void merge(Mats mats, Mat dst){
1567     Mat_Merge(mats, dst);
1568 }
1569 
1570 void merge(Mat[] mats, Mat dst){
1571     Mat_Merge(Mats(mats.ptr, cast(int)mats.length), dst);
1572 }
1573 
1574 void matMin(Mat src1, Mat src2, Mat dst){
1575     Mat_Min(src1, src2, dst);
1576 }
1577 
1578 void minMaxIdx(Mat m, double* minVal, double* maxVal, int* minIdx, int* maxIdx){
1579     Mat_MinMaxIdx(m, minVal, maxVal, minIdx, maxIdx);
1580 }
1581 
1582 void minMaxLoc(Mat m, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc){
1583     Mat_MinMaxLoc(m, minVal, maxVal, minLoc, maxLoc);
1584 }
1585 
1586 void minMaxLoc(Mat a, double* minVal, double* maxVal, int* minIdx, int* maxIdx){
1587     Mat_MinMaxLoc2(a, minVal, maxVal, minIdx, maxIdx);
1588 }
1589 
1590 void mulSpectrums(Mat a, Mat b, Mat c, int flags){
1591     Mat_MulSpectrums(a, b, c, flags);
1592 }
1593 
1594 void multiply(Mat src1, Mat src2, Mat dst){
1595     Mat_Multiply(src1, src2, dst);
1596 }
1597 
1598 void subtract(Mat src1, Mat src2, Mat dst){
1599     Mat_Subtract(src1, src2, dst);
1600 }
1601 
1602 enum: int {// cv::NormTypes
1603     NORM_INF = 1, 
1604     NORM_L1 = 2, 
1605     NORM_L2 = 4, 
1606     NORM_L2SQR = 5, 
1607     NORM_HAMMING = 6, 
1608     NORM_HAMMING2 = 7, 
1609     NORM_TYPE_MASK = 7, 
1610     NORM_RELATIVE = 8, 
1611     NORM_MINMAX = 32 
1612 }
1613 
1614 void normalize(Mat src, Mat dst, double alpha, double beta, int typ){
1615     Mat_Normalize(src, dst, alpha, beta, typ);
1616 }
1617 
1618 double norm(Mat src1, int normType){
1619     return Norm(src1, normType);
1620 }
1621 
1622 void perspectiveTransform(Mat src, Mat dst, Mat tm){
1623     Mat_PerspectiveTransform(src, dst, tm);
1624 }
1625 
1626 bool solve(Mat src1, Mat src2, Mat dst, int flags){
1627     return Mat_Solve(src1, src2, dst, flags);
1628 }
1629 
1630 int solveCubic(Mat coeffs, Mat roots){
1631     return Mat_SolveCubic(coeffs, roots);
1632 }
1633 
1634 double solvePoly(Mat coeffs, Mat roots, int maxIters){
1635     return Mat_SolvePoly(coeffs, roots, maxIters);
1636 }
1637 
1638 void reduce(Mat src, Mat dst, int dim, int rType, int dType){
1639     Mat_Reduce(src, dst, dim, rType, dType);
1640 }
1641 
1642 void repeat(Mat src, int nY, int nX, Mat dst){
1643     Mat_Repeat(src, nY, nX, dst);
1644 }
1645 
1646 void scaleAdd(Mat src1, double alpha, Mat src2, Mat dst){
1647     Mat_ScaleAdd(src1, alpha, src2, dst);
1648 }
1649 
1650 void matSort(Mat src, Mat dst, int flags){
1651     Mat_Sort(src, dst, flags);
1652 }
1653 
1654 void matSortIdx(Mat src, Mat dst, int flags){
1655     Mat_SortIdx(src, dst, flags);
1656 }
1657 
1658 void matSplit(Mat src, Mats* mats){
1659     Mats _mats = Mat_Split2(src);
1660     mats = &_mats;
1661 }
1662 
1663 void matSplit(Mat src, ref Mat[] _mats){
1664     Mats mats = Mat_Split2(src);
1665     _mats = mats.mats[0..mats.length];
1666 }
1667 
1668 alias split = matSplit;
1669 
1670 void matSubtract(Mat src1, Mat src2, Mat dst){
1671     Mat_Subtract(src1, src2, dst);
1672 }
1673 
1674 Scalar matTrace(Mat src){
1675     return Mat_Trace(src);
1676 }
1677 
1678 void transform(Mat src, Mat dst, Mat tm){
1679     Mat_Transform(src, dst, tm);
1680 }
1681 
1682 void transpose(Mat src, Mat dst){
1683     Mat_Transpose(src, dst);
1684 }
1685 
1686 void polarToCart(Mat magnitude, Mat degree, Mat x, Mat y, bool angleInDegrees){
1687     Mat_PolarToCart(magnitude, degree, x, y, angleInDegrees);
1688 }
1689 
1690 void matPow(Mat src, double power, Mat dst){
1691     Mat_Pow(src, power, dst);
1692 }
1693 
1694 void phase(Mat x, Mat y, Mat angle, bool angleInDegrees){
1695     Mat_Phase(x, y, angle, angleInDegrees);
1696 }
1697 
1698 Scalar matSum(Mat src1){
1699     return Mat_Sum(src1);
1700 }
1701 
1702 struct TermCriteria {
1703     void* p;
1704 }
1705 
1706 TermCriteria newTermCriteria(int typ, int maxCount, double epsilon){
1707     return TermCriteria_New(typ, maxCount, epsilon);
1708 }
1709 
1710 int64_t getCVTickCount(){
1711     return GetCVTickCount();
1712 }
1713 
1714 double getTickFrequency(){
1715     return GetTickFrequency();
1716 }
1717 
1718 double dot(Mat m1, Mat m2){
1719     return Mat_Dot(m1, m2);
1720 }
1721 
1722 Mat diag(Mat src, int d = 0){
1723     return Mat_Diag(src, d);
1724 }
1725 
1726 Mat eye(int rows, int cols, int type){
1727     return Mat_EyeFromRC(rows, cols, type);
1728 }
1729 
1730 Mat eye(Size sz, int type){
1731     return Mat_EyeFromRC(sz.height, sz.width, type);
1732 }