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.imgproc;
26 
27 import std.stdio;
28 import std.string;
29 import std.typecons;
30 import std.conv;
31 import std.math: PI;
32 import core.stdc.stdlib;
33 
34 import opencvd.cvcore;
35 
36 private extern (C){
37 
38     double ArcLength(Contour curve, bool is_closed);
39     Contour ApproxPolyDP(Contour curve, double epsilon, bool closed);
40     void CvtColor(Mat src, Mat dst, int code);
41     void EqualizeHist(Mat src, Mat dst);
42     void CalcHist(Mats mats, IntVector chans, Mat mask, Mat hist, IntVector sz, FloatVector rng, bool acc);
43     void CalcHist1(Mat dst, int nimages, int* channels,
44         Mat mask, Mat hist, int dims, int* histSize, const float** ranges, bool uniform, bool accumulate);
45     void CalcHist2(Mat dst, Mat mask, Mat hist, int* histSize);
46     void ConvexHull(Contour points, Mat hull, bool clockwise, bool returnPoints);
47     Points ConvexHull2(Contour points, bool clockwise);
48     IntVector ConvexHull3(Contour points, bool clockwise);
49     void ConvexityDefects(Contour points, Mat hull, Mat result);
50     void BilateralFilter(Mat src, Mat dst, int d, double sc, double ss);
51     void Blur(Mat src, Mat dst, Size ps);
52     void BoxFilter(Mat src, Mat dst, int ddepth, Size ps);
53     void SqBoxFilter(Mat src, Mat dst, int ddepth, Size ps);
54     void Dilate(Mat src, Mat dst, Mat kernel);
55     void Erode(Mat src, Mat dst, Mat kernel);
56     void MatchTemplate(Mat image, Mat templ, Mat result, int method, Mat mask);
57     Moment Moments(Mat src, bool binaryImage);
58     void PyrDown(Mat src, Mat dst, Size dstsize, int borderType);
59     void PyrUp(Mat src, Mat dst, Size dstsize, int borderType);
60     Rect BoundingRect(Contour con);
61     void BoxPoints(RotatedRect rect, Mat boxPts);
62     double ContourArea(Contour con);
63     RotatedRect MinAreaRect(Points points);
64     void MinEnclosingCircle(Points points, Point2f* center, float* radius);
65     Contours FindContours(Mat src, int mode, int method);
66     Contours FindContoursWithHier(Mat src, Hierarchy* chierarchy, int mode, int method);
67     int ConnectedComponents(Mat src, Mat dst, int connectivity, int ltype, int ccltype);
68     int ConnectedComponentsWithStats(Mat src, Mat labels, Mat stats, Mat centroids, int connectivity, int ltype, int ccltype);
69 
70     void GaussianBlur(Mat src, Mat dst, Size ps, double sX, double sY, int bt);
71     void Laplacian(Mat src, Mat dst, int dDepth, int kSize, double scale, double delta, int borderType);
72     void Scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double delta,
73                 int borderType);
74     Mat GetStructuringElement(int shape, Size ksize);
75     Mat GetStructuringElementWithAnchor(int shape, Size ksize, Point anchor);
76     void MorphologyEx(Mat src, Mat dst, int op, Mat kernel);
77     void MedianBlur(Mat src, Mat dst, int ksize);
78     
79     void Canny(Mat src, Mat edges, double t1, double t2);
80     void Canny2(Mat dx, Mat dy, Mat edges, double threshold1, double threshold2, bool L2gradient);
81     void Canny3(Mat image, Mat edges, double threshold1, double threshold2, int apertureSize, bool L2gradient);
82     void CornerSubPix(Mat img, Mat corners, Size winSize, Size zeroZone, TermCriteria criteria);
83     void GoodFeaturesToTrack(Mat img, Mat corners, int maxCorners, double quality, double minDist);
84     void HoughCircles(Mat src, Mat circles, int method, double dp, double minDist);
85     void HoughCirclesWithParams(Mat src, Mat circles, int method, double dp, double minDist,
86                                 double param1, double param2, int minRadius, int maxRadius);
87     Vec3fs HoughCircles3(Mat image, int method, double dp,
88               double minDist, double param1, double param2, int minRadius, int maxRadius);
89     void HoughLines(Mat src, Mat lines, double rho, double theta, int threshold);
90     void HoughLinesP(Mat src, Mat lines, double rho, double theta, int threshold);
91     void HoughLinesP2(Mat image, Vec4is *lines, double rho, double theta,
92         int threshold, double minLineLength, double maxLineGap);
93     void HoughLinesPWithParams(Mat src, Mat lines, double rho, double theta, int threshold, double minLineLength, double maxLineGap);
94     void HoughLinesPointSet(Mat points, Mat lines, int lines_max, int threshold,
95                             double min_rho, double  max_rho, double rho_step,
96                             double min_theta, double max_theta, double theta_step);
97     void HoughLines2(Mat image, Vec2fs *lines, double rho, double theta,
98         int threshold, double srn, double stn, double min_theta, double max_theta);
99     void Threshold(Mat src, Mat dst, double thresh, double maxvalue, int typ);
100     void AdaptiveThreshold(Mat src, Mat dst, double maxValue, int adaptiveTyp, int typ, int blockSize,
101                            double c);
102                            
103     void ArrowedLine(Mat img, Point pt1, Point pt2, Scalar color, int thickness);
104     void Circle(Mat img, Point center, int radius, Scalar color, int thickness);
105     void Circle2(Mat img, Point center, int radius, Scalar color, int thickness, int shift);
106     void Ellipse(Mat img, Point center, Point axes, double angle, double
107                  startAngle, double endAngle, Scalar color, int thickness);
108     void Line(Mat img, Point pt1, Point pt2, Scalar color, int thickness);
109     void Line2(Mat img, Point pt1, Point pt2, Scalar color, int thickness, int lineType, int shift);
110     void Rectangle(Mat img, Rect rect, Scalar color, int thickness);
111     void Rectangle2(Mat img, Point pt1, Point pt2, Scalar color, int thickness, int lineType, int shift);
112     void FillPoly(Mat img, Contours points, Scalar color);
113     Size GetTextSize(const char* text, int fontFace, double fontScale, int thickness);
114     void PutText(Mat img, const char* text, Point org, int fontFace, double fontScale,
115                  Scalar color, int thickness);
116     void Resize(Mat src, Mat dst, Size sz, double fx, double fy, int interp);
117     Mat GetRotationMatrix2D(Point center, double angle, double scale);
118     void WarpAffine(Mat src, Mat dst, Mat rot_mat, Size dsize);
119     void WarpAffineWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode,
120                               Scalar borderValue);
121     void WarpPerspective(Mat src, Mat dst, Mat m, Size dsize);
122     void ApplyColorMap(Mat src, Mat dst, int colormap);
123     void ApplyCustomColorMap(Mat src, Mat dst, Mat colormap);
124     Mat GetPerspectiveTransform(Contour src, Contour dst);
125     void DrawContours(Mat src, Contours contours, int contourIdx, Scalar color, int thickness);
126     void DrawContours2(
127         Mat image,
128         Contours contours,
129         int contourIdx,
130         Scalar color,
131         int thickness,
132         int lineType,
133         Hierarchy hierarchy,
134         int maxLevel,
135         Point offset
136     );
137     void Sobel(Mat src, Mat dst, int ddepth, int dx, int dy, int ksize, double scale, double delta, int borderType);
138     void SpatialGradient(Mat src, Mat dx, Mat dy, int ksize, int borderType);
139     void Remap(Mat src, Mat dst, Mat map1, Mat map2, int interpolation, int borderMode, Scalar borderValue);
140     void Filter2D(Mat src, Mat dst, int ddepth, Mat kernel, Point anchor, double delta, int borderType);
141     void SepFilter2D(Mat src, Mat dst, int ddepth, Mat kernelX, Mat kernelY, Point anchor, double delta, int borderType);
142     void LogPolar(Mat src, Mat dst, Point center, double m, int flags);
143     void FitLine(Contour points, Mat line, int distType, double param, double reps, double aeps);
144     CLAHE CLAHE_Create();
145     CLAHE CLAHE_CreateWithParams(double clipLimit, Size tileGridSize);
146     void CLAHE_Close(CLAHE c);
147     void CLAHE_Apply(CLAHE c, Mat src, Mat dst);
148     
149     void Watershed(Mat src, Mat markers);
150     int FloodFill(Mat image, Mat mask, Point seedPoint, Scalar  newVal,
151             Rect rect, Scalar loDiff, Scalar upDiff, int flags);
152     int FloodFill2(Mat image, Point seedPoint, Scalar newVal, Rect rect, Scalar loDiff, Scalar upDiff, int flags);
153     void DistanceTransform(Mat src, Mat dst, Mat labels, int distanceType,
154         int maskSize, int labelType);
155     void DistanceTransform2(Mat src, Mat dst, int distanceType, int maskSize, int dstType);
156     
157     Subdiv2D Subdiv2d_New();
158     Subdiv2D Subdiv2d_NewFromRect(Rect r);
159     void Subdiv2D_Close(Subdiv2D sd);
160     void Subdiv2D_Insert(Subdiv2D sd, Point2f p);
161     void Subdiv2D_InsertMultiple(Subdiv2D sd, Point2fs ptvec);
162     Vec6fs Subdiv2D_GetTriangleList(Subdiv2D sd);
163     Point2fss Subdiv2D_GetVoronoiFacetList(Subdiv2D sd, IntVector idx, Point2fs* faceCenters);
164     int Subdiv2D_EdgeOrg(Subdiv2D sd, int edge, Point2f** orgpt);
165     int Subdiv2D_EdgeDst(Subdiv2D sd, int edge, Point2f** dstpt);
166     int Subdiv2D_NextEdge(Subdiv2D sd, int edge);
167     int Subdiv2D_RotateEdge(Subdiv2D sd, int edge, int rotate);
168     int Subdiv2D_SymEdge(Subdiv2D sd, int edge);
169     int Subdiv2D_GetEdge(Subdiv2D sd, int edge, int nextEdgeType);
170     Vec4fs Subdiv2D_GetEdgeList(Subdiv2D sd);
171     IntVector Subdiv2D_GetLeadingEdgeList(Subdiv2D sd);
172     int Subdiv2D_Locate(Subdiv2D sd, Point2f pt, ref int edge, ref int vertex);
173     Point2f Subdiv2D_GetVertex(Subdiv2D sd, int vertex, int* firstEdge);
174     void Subdiv2D_InitDelaunay(Subdiv2D sd, Rect bRect);
175     
176     void FillConvexPoly(Mat img, Points points, Scalar color, int lineType, int shift);
177     void FillConvexPoly2f(Mat img, Point2fs points, Scalar color, int lineType, int shift);
178     void Polylines(Mat img, Points pts, bool isClosed, Scalar color, int thickness, int lineType, int shift);
179     void Polylines2ss(Mat img, Pointss flist, bool isClosed, Scalar color, int thickness, int lineType, int shift);
180     void Polylines2f(Mat img, Point2fs pts, bool isClosed, Scalar color, int thickness, int lineType, int shift);
181     void Polylines2fss(Mat img, Point2fss pts, bool isClosed, Scalar color, int thickness, int lineType, int shift);
182     
183     RotatedRect FitEllipse(Points points);
184     RotatedRect FitEllipse2(Mat points);
185     RotatedRect FitEllipseAMS(Points points);
186     RotatedRect FitEllipseAMS2(Mat points);
187     RotatedRect FitEllipseDirect(Points points);
188     RotatedRect FitEllipseDirect2(Mat points);
189     void Ellipse2(Mat img, RotatedRect box, Scalar color, int thickness, int lineType);
190 
191 }
192 
193 double arcLength(Point[] curve, bool is_closed){
194     return ArcLength(Contour(curve.ptr, curve.length.to!int), is_closed);
195 }
196 
197 Point[] approxPolyDP(Point[] curve, double epsilon, bool isClosed){
198     Contour cret = ApproxPolyDP(Contour(curve.ptr, curve.length.to!int), epsilon, isClosed);
199     Point[] ret = cret.points[0..cret.length].dup;
200     Points_Close(cret);
201     return ret;
202 }
203 
204 void cvtColor(Mat src, Mat dst, int code){
205     CvtColor(src, dst, code);
206 }
207 
208 void equalizeHist(Mat src, Mat dst){
209     EqualizeHist(src, dst);
210 }
211 
212 void calcHist(Mats mats, int[] chans, Mat mask, Mat hist, IntVector sz, FloatVector rng, bool acc){
213     CalcHist(mats, IntVector(chans.ptr, chans.length.to!int), mask, hist, sz, rng, acc);
214 }
215 
216 void calcHist(Mat images, int nimages, int[] channels,
217             Mat mask, Mat hist, int dims, int[] histSize, float[][2] _ranges, bool uniform = true, bool accumulate = false){
218     
219     float*[] __ranges = new float*[channels.length];
220     
221     foreach(i; 0..channels.length){
222         float[] rng = [_ranges[i][0], _ranges[i][1]];
223         __ranges[i] = rng.ptr;
224     }
225     
226     CalcHist1(images, nimages, channels.ptr, mask, hist, dims, histSize.ptr, cast(const float**)__ranges, uniform, accumulate);
227     destroy(__ranges);
228 }
229 
230 void calcHist(Mat dst, Mat mask, Mat hist, int* histSize){
231     CalcHist2(dst, mask, hist, histSize);
232 }
233 
234 void convexHull(Point[] points, Mat hull, bool clockwise, bool returnPoints){
235     ConvexHull(Contour(points.ptr, cast(int)points.length), hull, clockwise, returnPoints);
236 }
237 
238 Point[] convexHull(Point[] points, bool clockwise = true){
239     Points pts = ConvexHull2(Contour(points.ptr, cast(int)points.length), clockwise);
240     Point[] ret = pts.points[0..pts.length].dup;
241     Points_Close(pts);
242     return ret;
243 }
244 
245 int[] convexHullIdx(Point[] points, bool clockwise = true){
246     IntVector iv = ConvexHull3(Contour(points.ptr, cast(int)points.length), clockwise);
247     int[] ret = iv.val[0..iv.length].dup;
248     Close_IntVector(iv);
249     return ret;
250 }
251 
252 void convexityDefects(Point[] points, Mat hull, Mat result){
253     ConvexityDefects(Contour(points.ptr, points.length.to!int), hull, result);
254 }
255 
256 void bilateralFilter(Mat src, Mat dst, int d, double sc, double ss){
257     BilateralFilter(src, dst, d, sc, ss);
258 }
259 
260 void blur(Mat src, Mat dst, Size ps){
261     Blur(src, dst, ps);
262 }
263 
264 void boxFilter(Mat src, Mat dst, int ddepth, Size ps){
265     BoxFilter(src, dst, ddepth, ps);
266 }
267 
268 void sqBoxFilter(Mat src, Mat dst, int ddepth, Size ps){
269     SqBoxFilter(src, dst, ddepth, ps);
270 }
271 
272 void dilate(Mat src, Mat dst, Mat kernel){
273     Dilate(src, dst, kernel);
274 }
275 
276 void erode(Mat src, Mat dst, Mat kernel){
277     Erode(src, dst, kernel);
278 }
279 
280 void matchTemplate(Mat image, Mat templ, Mat result, int method, Mat mask){
281     MatchTemplate(image, templ, result, method, mask);
282 }
283 
284 Moment moments(Mat src, bool isBinaryImage){
285     return Moments(src, isBinaryImage);
286 }
287 
288 void pyrDown(Mat src, Mat dst, Size dstsize, int borderType){
289     PyrDown(src, dst, dstsize, borderType);
290 }
291 
292 void pyrUp(Mat src, Mat dst, Size dstsize, int borderType){
293     PyrUp(src, dst, dstsize, borderType);
294 }
295 
296 Rect boundingRect(Point[] con){
297     return BoundingRect(Contour(con.ptr, con.length.to!int));
298 }
299 
300 void boxPoints(RotatedRect rect, Mat boxPts){
301     BoxPoints(rect, boxPts);
302 }
303 
304 double contourArea(Point[] con){
305     return ContourArea(Contour(con.ptr, con.length.to!int));
306 }
307 
308 RotatedRect minAreaRect(Point[] _points){
309     RotatedRect rr = MinAreaRect(Points(_points.ptr, _points.length.to!int));
310     Point[] ps = rr.pts.points[0..rr.pts.length].dup;
311     Points_Close(rr.pts);
312     RotatedRect ret = {Contour(ps.ptr, cast(int)ps.length), rr.boundingRect, rr.center, rr.size, rr.angle};
313     return ret;
314 }
315 void minEnclosingCircle(Point[] _points, Point2f* center, float* radius){
316     MinEnclosingCircle(Points(_points.ptr, _points.length.to!int), center, radius);
317 }
318 
319 // enum cv::RetrievalModes for findContours
320 enum: int {
321     RETR_EXTERNAL,
322     RETR_LIST,
323     RETR_CCOMP,
324     RETR_TREE,
325     RETR_FLOODFILL
326 }
327 // enum cv::ContourApproximationModes for findContours
328 enum: int {
329     CHAIN_APPROX_NONE,
330     CHAIN_APPROX_SIMPLE,
331     CHAIN_APPROX_TC89_L1,
332     CHAIN_APPROX_TC89_KCOS
333 }
334 
335 Point[][] findContours(Mat src, int mode, int method){
336     Contours cnts = FindContours(src, mode, method);
337     Point[][] dcnts;
338     foreach(i; 0..cnts.length){
339         Points pts = cnts.contours[i];
340         Point[] dpts = pts.points[0..pts.length].dup;
341         dcnts ~= dpts;
342     }
343     Contours_Close(cnts);
344     return dcnts;
345 }
346 
347 Tuple!(Point[][], Scalar[]) findContoursWithHier(Mat src, int mode, int method){
348     Hierarchy chier;
349     Contours cntrs = FindContoursWithHier(src, &chier, mode, method);
350     
351     Scalar[] hier = chier.scalars[0..chier.length].dup;
352     free(chier.scalars);
353     
354     Point[][] rc;
355     
356     foreach(i; 0..cntrs.length){
357         Contour cp = cntrs.contours[i];
358         Point[] dp = cp.points[0..cp.length].dup;
359         free(cp.points);
360         rc ~= dp;
361     }
362     free(cntrs.contours);
363     return tuple(rc, hier);
364 }
365 
366 int connectedComponents(Mat src, Mat dst, int connectivity, int ltype, int ccltype){
367     return ConnectedComponents(src, dst, connectivity, ltype, ccltype);
368 }
369 
370 int connectedComponentsWithStats(Mat src, Mat labels, Mat stats, Mat centroids, int connectivity, int ltype, int ccltype){
371     return ConnectedComponentsWithStats(src, labels, stats, centroids, connectivity, ltype, ccltype);
372 }
373 
374 void gaussianBlur(Mat src, Mat dst, Size ps, double sX, double sY, int bt){
375     GaussianBlur(src, dst, ps, sX, sY, bt);
376 }
377 
378 void laplacian(Mat src, Mat dst, int dDepth, int kSize, double scale, double delta, int borderType){
379     Laplacian(src, dst, dDepth, kSize, scale, delta, borderType);
380 }
381 
382 void scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double delta,
383             int borderType){
384     Scharr(src, dst, dDepth, dx, dy, scale, delta, borderType);
385 }
386 
387 enum: int { // cv::MorphShapes
388     MORPH_RECT,
389     MORPH_CROSS,
390     MORPH_ELLIPSE
391 }
392 
393 Mat getStructuringElement(int shape, Size ksize){
394     return getStructuringElement(shape, ksize);
395 }
396 
397 Mat getStructuringElement(int shape, Size ksize, Point anchor){
398     return GetStructuringElementWithAnchor(shape, ksize, anchor);
399 }
400 
401 enum: int { // cv::MorphTypes
402     MORPH_ERODE,
403     MORPH_DILATE,
404     MORPH_OPEN,
405     MORPH_CLOSE,
406     MORPH_GRADIENT,
407     MORPH_TOPHAT,
408     MORPH_BLACKHAT,
409     MORPH_HITMISS
410 }
411 
412 void morphologyEx(Mat src, Mat dst, int op, Mat kernel){
413     MorphologyEx(src, dst, op, kernel);
414 }
415 
416 void medianBlur(Mat src, Mat dst, int ksize){
417     MedianBlur(src, dst, ksize);
418 }
419 
420 void canny(Mat src, Mat edges, double t1, double t2){
421     Canny(src, edges, t1, t2);
422 }
423 
424 void canny(Mat dx, Mat dy, Mat edges, double threshold1, double threshold2, bool L2gradient = false){
425     Canny2(dx, dy, edges, threshold1, threshold2, L2gradient);
426 }
427 
428 void canny(Mat image, Mat edges, double threshold1, double threshold2, int apertureSize = 3, bool L2gradient = false){
429     Canny3(image, edges, threshold1, threshold2, apertureSize, L2gradient);
430 }
431 
432 void cornerSubPix(Mat img, Mat corners, Size winSize, Size zeroZone, TermCriteria criteria){
433     CornerSubPix(img, corners, winSize, zeroZone, criteria);
434 }
435 
436 void goodFeaturesToTrack(Mat img, Mat corners, int maxCorners, double quality, double minDist){
437     GoodFeaturesToTrack(img, corners, maxCorners, quality, minDist);
438 }
439 
440 enum: int { // cv::HoughModes
441   HOUGH_STANDARD = 0, 
442   HOUGH_PROBABILISTIC = 1, 
443   HOUGH_MULTI_SCALE = 2, 
444   HOUGH_GRADIENT = 3 
445 }
446 
447 void houghCircles(Mat src, Mat circles, int method, double dp, double minDist){
448     HoughCircles(src, circles, method, dp, minDist);
449 }
450 void houghCirclesWithParams(Mat src, Mat circles, int method, double dp, double minDist,
451                             double param1, double param2, int minRadius, int maxRadius){
452     HoughCirclesWithParams(src, circles, method, dp, minDist,
453                             param1, param2, minRadius, maxRadius);
454 }
455 
456 void houghCircles(Mat image, ref Vec3f[] circles, int method, double dp,
457                   double minDist, double param1 = 100,
458                   double param2 = 100, int minRadius = 0, int maxRadius = 0){
459     Vec3fs ccircles = HoughCircles3(image, method, dp, minDist, param1, param2, minRadius, maxRadius);
460     circles = ccircles.vec3fs[0..ccircles.length].dup;
461     free(ccircles.vec3fs);
462 }
463 
464 void houghLines(Mat src, Mat lines, double rho, double theta, int threshold){
465     HoughLines(src, lines, rho, theta, threshold);
466 }
467 
468 void houghLinesP(Mat src, Mat lines, double rho, double theta, int threshold){
469     HoughLinesP(src, lines, rho, theta, threshold);
470 }
471 
472 void houghLinesP(Mat image, ref Vec4i[] lines, double rho, double theta,
473     int threshold, double minLineLength = 0, double maxLineGap = 0){
474     Vec4is clines;
475     HoughLinesP2(image, &clines, rho, theta, threshold, minLineLength, maxLineGap);
476     lines = clines.vec4is[0..clines.length].dup;
477     free(clines.vec4is);
478 }
479 
480 void houghLinesPWithParams(Mat src, Mat lines, double rho, double theta, int threshold, double minLineLength, double maxLineGap){
481     HoughLinesPWithParams(src, lines, rho, theta, threshold, minLineLength, maxLineGap);
482 }
483 
484 void houghLines(Mat image, ref Vec2f[] lines, double rho, double theta,
485     int threshold, double srn = 0, double stn = 0, double min_theta = 0, double max_theta = PI){
486     Vec2fs clines;
487     HoughLines2(image, &clines, rho, theta, threshold, srn, stn, min_theta, max_theta);
488     lines = clines.vec2fs[0..clines.length].dup;
489     free(clines.vec2fs);
490 }
491 
492 void houghLinesPointSet(Mat points, Mat lines, int lines_max, int threshold,
493                         double min_rho, double  max_rho, double rho_step,
494                         double min_theta, double max_theta, double theta_step){
495     HoughLinesPointSet(points, lines, lines_max, threshold,
496                         min_rho, max_rho, rho_step,
497                         min_theta, max_theta, theta_step);
498 }
499 
500 enum: int {
501     THRESH_BINARY,
502     THRESH_BINARY_INV,
503     THRESH_TRUNC,
504     THRESH_TOZERO,
505     THRESH_TOZERO_INV,
506     THRESH_MASK,
507     THRESH_OTSU,
508     THRESH_TRIANGLE
509 }
510 
511 void threshold(Mat src, Mat dst, double thresh, double maxvalue, int typ){
512     Threshold(src, dst, thresh, maxvalue, typ);
513 }
514 
515 void adaptiveThreshold(Mat src, Mat dst, double maxValue, int adaptiveTyp, int typ, int blockSize,
516                        double c){
517     AdaptiveThreshold(src, dst, maxValue, adaptiveTyp, typ, blockSize, c);
518 }
519 
520 
521 void arrowedLine(Mat img, Point pt1, Point pt2, Scalar color, int thickness){
522     ArrowedLine(img, pt1, pt2, color, thickness);
523 }
524 
525 void circle(Mat img, Point center, int radius, Scalar color, int thickness){
526     Circle(img, center, radius, color, thickness);
527 }
528 
529 void circle(Mat img, Point center, int radius, Scalar color, int thickness, int shift){
530     Circle2(img, center, radius, color, thickness, shift);
531 }
532 
533 void ellipse(Mat img, Point center, Point axes, double angle, double
534              startAngle, double endAngle, Scalar color, int thickness){
535     Ellipse(img, center, axes, angle, startAngle, endAngle, color, thickness);
536 }
537 
538 void line(Mat img, Point pt1, Point pt2, Scalar color, int thickness){
539     Line(img, pt1, pt2, color, thickness);
540 }
541 
542 void line(Mat img, Point pt1, Point pt2, Scalar color, int thickness = 1, int lineType = LINE_8, int shift = 0){
543     Line2(img, pt1, pt2, color, thickness, lineType, shift);
544 }
545 
546 void rectangle(Mat img, Rect rect, Scalar color, int thickness){
547     Rectangle(img, rect, color, thickness);
548 }
549 
550 enum: int { // cv::LineTypes
551     FILLED = -1, 
552     LINE_4 = 4, 
553     LINE_8 = 8, 
554     LINE_AA = 16
555 }
556 
557 void rectangle(Mat img, Point _pt1, Point _pt2, Scalar color, int thickness = 1, int lineType = LINE_8, int shift = 0){
558     Rectangle2(img, _pt1, _pt2, color, thickness, lineType, shift);
559 }
560 
561 void fillPoly(Mat img, Point[][] _points, Scalar color){
562     Points[] incpts = new Points[_points.length];
563     foreach(i; 0.._points.length){
564         Point[] inception = new Point[_points[i].length];
565         foreach(j; 0.._points[i].length){
566             inception[j] = _points[i][j];
567         }
568         
569         incpts[i] = Points(inception.ptr, _points[i].length.to!int);
570     }
571     Contours param = {incpts.ptr, _points.length.to!int};
572     FillPoly(img, param, color);
573 }
574 
575 enum: int { // cv::HersheyFonts
576     FONT_HERSHEY_SIMPLEX = 0, 
577     FONT_HERSHEY_PLAIN = 1, 
578     FONT_HERSHEY_DUPLEX = 2, 
579     FONT_HERSHEY_COMPLEX = 3, 
580     FONT_HERSHEY_TRIPLEX = 4, 
581     FONT_HERSHEY_COMPLEX_SMALL = 5, 
582     FONT_HERSHEY_SCRIPT_SIMPLEX = 6, 
583     FONT_HERSHEY_SCRIPT_COMPLEX = 7, 
584     FONT_ITALIC = 16 
585 }
586 
587 Size getTextSize(string text, int fontFace, double fontScale, int thickness){
588     return GetTextSize(toStringz(text), fontFace, fontScale, thickness);
589 }
590 
591 void putText(Mat img, string text, Point org, int fontFace, double fontScale,
592              Scalar color, int thickness){
593     PutText(img, toStringz(text), org, fontFace, fontScale, color, thickness);
594 }
595 
596 void resize(Mat src, Mat dst, Size sz, double fx, double fy, int interp){
597     Resize(src, dst, sz, fx, fy, interp);
598 }
599 
600 Mat getRotationMatrix2D(Point center, double angle, double scale){
601     return GetRotationMatrix2D(center, angle, scale);
602 }
603 
604 void warpAffine(Mat src, Mat dst, Mat rot_mat, Size dsize){
605     WarpAffine(src, dst, rot_mat, dsize);
606 }
607 
608 void warpAffineWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode,
609                           Scalar borderValue){
610     WarpAffineWithParams(src, dst, rot_mat, dsize, flags, borderMode, borderValue);
611 }
612 
613 void warpPerspective(Mat src, Mat dst, Mat m, Size dsize){
614     WarpPerspective(src, dst, m, dsize);
615 }
616 
617 void applyColorMap(Mat src, Mat dst, int colormap){
618     ApplyColorMap(src, dst, colormap);
619 }
620 
621 void applyCustomColorMap(Mat src, Mat dst, Mat colormap){
622     ApplyCustomColorMap(src, dst, colormap);
623 }
624 
625 Mat getPerspectiveTransform(Point[] src, Point[] dst){
626     return GetPerspectiveTransform(Contour(src.ptr, src.length.to!int), Contour(dst.ptr, dst.length.to!int));
627 }
628 
629 void drawContours(Mat src, Point[][] contours, int contourIdx, Scalar color, int thickness){
630     Points[] incpts = new Points[contours.length];
631     foreach(i; 0..contours.length){
632         Point[] inception = new Point[contours[i].length];
633         foreach(j; 0..contours[i].length){
634             inception[j] = contours[i][j];
635         }
636         
637         incpts[i] = Points(inception.ptr, contours[i].length.to!int);
638     }
639     Contours param = {incpts.ptr, contours.length.to!int};
640     DrawContours(src, param, contourIdx, color, thickness);
641 }
642 
643 void drawContours(
644             Mat image,
645             Point[][] contours,
646             int contourIdx,
647             Scalar color,
648             int thickness,
649             int lineType,
650             Scalar[] hierarchy,
651             int maxLevel,
652             Point offset = Point(0,0)
653         ){
654     Points[] incpts = new Points[contours.length];
655     foreach(i; 0..contours.length){
656         Point[] inception = new Point[contours[i].length];
657         foreach(j; 0..contours[i].length){
658             inception[j] = contours[i][j];
659         }
660         
661         incpts[i] = Points(inception.ptr, contours[i].length.to!int);
662     }
663     Contours param = {incpts.ptr, contours.length.to!int};
664     
665     Hierarchy chie = {hierarchy.ptr, hierarchy.length.to!int};
666     
667     DrawContours2(image, param, contourIdx, color, thickness, lineType, chie, maxLevel, offset);
668 }
669 
670 void sobel(Mat src, Mat dst, int ddepth, int dx, int dy, int ksize, double scale, double delta, int borderType){
671     Sobel(src, dst, ddepth, dx, dy, ksize, scale, delta, borderType);
672 }
673 
674 void spatialGradient(Mat src, Mat dx, Mat dy, int ksize, int borderType){
675     SpatialGradient(src, dx, dy, ksize, borderType);
676 }
677 
678 void remap(Mat src, Mat dst, Mat map1, Mat map2, int interpolation, int borderMode, Scalar borderValue){
679     Remap(src, dst, map1, map2, interpolation, borderMode, borderValue);
680 }
681 
682 void filter2D(Mat src, Mat dst, int ddepth, Mat kernel, Point anchor, double delta, int borderType){
683     Filter2D(src, dst, ddepth, kernel, anchor, delta, borderType);
684 }
685 
686 void sepFilter2D(Mat src, Mat dst, int ddepth, Mat kernelX, Mat kernelY, Point anchor, double delta, int borderType){
687     SepFilter2D(src, dst, ddepth, kernelX, kernelY, anchor, delta, borderType);
688 }
689 
690 void logPolar(Mat src, Mat dst, Point center, double m, int flags){
691     LogPolar(src, dst, center, m, flags);
692 }
693 
694 void fitLine(Point[] points, Mat line, int distType, double param, double reps, double aeps){
695     FitLine(Contour(points.ptr, points.length.to!int), line, distType, param, reps, aeps);
696 }
697 
698 void watershed(Mat src, Mat markers){
699     Watershed(src, markers);
700 }
701 
702 int floodFill(Mat image, Mat mask, Point seedPoint, Scalar  newVal,
703                 Rect rect = Rect(), Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), int flags = 4){
704     return FloodFill(image, mask, seedPoint, newVal, rect, loDiff, upDiff, flags);
705 }
706 
707 int floodFill(Mat image, Point seedPoint, Scalar newVal, Rect rect = Rect(), Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), int flags = 4){
708     return FloodFill2(image, seedPoint, newVal, rect, loDiff, upDiff, flags);
709 }
710 
711 enum: int{ // cv::DistanceTransformMasks
712     DIST_MASK_3 = 3, 
713     DIST_MASK_5 = 5, 
714     DIST_MASK_PRECISE = 0 
715 }
716 
717 enum: int { // cv::DistanceTransformLabelTypes
718     DIST_LABEL_CCOMP = 0, 
719     DIST_LABEL_PIXEL = 1 
720 }
721 
722 enum: int { // cv::DistanceTypes
723     DIST_USER = -1, 
724     DIST_L1 = 1, 
725     DIST_L2 = 2, 
726     DIST_C = 3, 
727     DIST_L12 = 4, 
728     DIST_FAIR = 5, 
729     DIST_WELSCH = 6, 
730     DIST_HUBER = 7 
731 }
732 
733 
734 void distanceTransform(Mat src, Mat dst, Mat labels, int distanceType,
735     int maskSize, int labelType = DIST_LABEL_CCOMP){
736     
737     DistanceTransform(src, dst, labels, distanceType, maskSize, labelType);
738 }	
739 
740 
741 void distanceTransform(Mat src, Mat	dst, int distanceType, int maskSize, int dstType = CV32F){
742     DistanceTransform2(src, dst, distanceType, maskSize, dstType);
743 }	
744 
745 /** Subdiv2D point location cases */
746 enum: int {
747     PTLOC_ERROR        = -2, //!< Point location error
748     PTLOC_OUTSIDE_RECT = -1, //!< Point outside the subdivision bounding rect
749     PTLOC_INSIDE       = 0, //!< Point inside some facet
750     PTLOC_VERTEX       = 1, //!< Point coincides with one of the subdivision vertices
751     PTLOC_ON_EDGE      = 2  //!< Point on some edge
752 }
753 
754 struct Subdiv2D {
755     void* p;
756     
757     static Subdiv2D opCall(){
758         return Subdiv2d_New();
759     }
760     
761     static Subdiv2D opCall(Rect rect){
762         return Subdiv2d_NewFromRect(rect);
763     }
764     
765     void insert(Point2f p){
766         Subdiv2D_Insert(this, p);
767     }
768     
769     void insert(Point2f[] ptvec){
770         Subdiv2D_InsertMultiple(this, Point2fs(ptvec.ptr, ptvec.length.to!int));
771     }
772     
773     Vec6f[] getTriangleList(){
774         auto v6fs = Subdiv2D_GetTriangleList(this);
775         Vec6f[] ret = v6fs.vec6fs[0..v6fs.length].dup;
776         Close_Vec6fs(v6fs);
777         return ret;
778     }
779     
780     Tuple!(Point2f[][], Point2f[]) getVoronoiFacetList(int[] idx = null){
781        Point2fs _faceCenters;
782        Point2fss _facetList = Subdiv2D_GetVoronoiFacetList(this, IntVector(idx.ptr, cast(int)idx.length), &_faceCenters);
783        
784        Point2f[] faceCenters = _faceCenters.points[0.._faceCenters.length].dup;
785        free(_faceCenters.points);
786        Point2f[][] retFL;
787        for(size_t i = 0; i < _facetList.length; i++){
788            Point2fs fl = _facetList.point2fss[i];
789            Point2f[] point2fs = fl.points[0..fl.length].dup;
790            free(fl.points);
791            retFL ~= point2fs;
792        }
793        free(_facetList.point2fss);
794        return tuple(retFL, faceCenters);
795     }
796     
797     /** Subdiv2D edge type navigation (see: getEdge()) */
798     static int NEXT_AROUND_ORG   = 0x00;
799     static int NEXT_AROUND_DST   = 0x22;
800     static int PREV_AROUND_ORG   = 0x11;
801     static int PREV_AROUND_DST   = 0x33;
802     static int NEXT_AROUND_LEFT  = 0x13;
803     static int NEXT_AROUND_RIGHT = 0x31;
804     static int PREV_AROUND_LEFT  = 0x20;
805     static int PREV_AROUND_RIGHT = 0x02;
806     
807     int edgeOrg(int edge, ref Point2f orgpt){
808         Point2f *pt;
809         int retVal = Subdiv2D_EdgeOrg(this, edge, &pt);
810         orgpt = *pt;
811         return retVal;
812     }
813     
814     int edgeDst(int edge, ref Point2f dstpt){
815         Point2f *pt;
816         int retVal = Subdiv2D_EdgeDst(this, edge, &pt);
817         dstpt = *pt;
818         return retVal;
819     }
820     
821     int getEdge(int edge, int nextEdgeType){
822         return Subdiv2D_GetEdge(this, edge, nextEdgeType);
823     }
824     
825     Vec4f[] getEdgeList(){
826         Vec4fs vec4fs = Subdiv2D_GetEdgeList(this);
827         Vec4f[] ret = vec4fs.vec4fs[0..vec4fs.length].dup;
828         free(vec4fs.vec4fs);
829         return ret;
830     }
831     
832     int[] getLeadingEdgeList(){
833         IntVector intv = Subdiv2D_GetLeadingEdgeList(this);
834         int[] ret = intv.val[0..intv.length].dup;
835         Close_IntVector(intv);
836         return ret;
837     }
838     
839     int nextEdge(int edge){
840         return Subdiv2D_NextEdge(this, edge);
841     }
842     
843     int rotateEdge(int edge, int rotate){
844         return Subdiv2D_RotateEdge(this, edge, rotate);
845     }
846     
847     int symEdge(int edge){
848         return Subdiv2D_SymEdge(this, edge);
849     }
850     
851     int locate(Point2f pt, ref int edge, ref int vertex){
852         return Subdiv2D_Locate(this, pt, edge, vertex);
853     }
854     
855     Point2f getVertex(int vertex, int* firstEdge = null){
856         return Subdiv2D_GetVertex(this, vertex, firstEdge);
857     }
858     
859     void initDelaunay(Rect bRect){
860         Subdiv2D_InitDelaunay(this, bRect);
861     }
862 }
863 
864 void Destroy(Subdiv2D sd){
865     Subdiv2D_Close(sd);
866 }
867 
868 void fillConvexPoly(Mat img, Point[] points, Scalar color, int lineType = LINE_8, int shift = 0){
869     FillConvexPoly(img, Points(points.ptr, cast(int)points.length), color, lineType, shift);
870 }
871 
872 enum: int {
873     CV_FILLED = -1,
874     CV_AA = 16
875 }
876 
877 void polylines(Mat img, Point[] pts, bool isClosed, Scalar color, int thickness = 1, int lineType = LINE_8, int shift = 0){
878     Polylines(img, Points(pts.ptr, pts.length.to!int), isClosed, color, thickness, lineType, shift);
879 }
880 
881 void polylines(Mat img, Point[][] pts, bool isClosed, Scalar color,
882     int thickness = 1, int lineType = LINE_8, int shift = 0){
883     
884     Points[] incpts = new Points[pts.length];
885     foreach(i; 0..pts.length){
886         Point[] inception = new Point[pts[i].length];
887         foreach(j; 0..pts[i].length){
888             inception[j] = pts[i][j];
889         }
890         
891         incpts[i] = Points(inception.ptr, pts[i].length.to!int);
892     }
893     Pointss param = {incpts.ptr, pts.length.to!int}; 
894     Polylines2ss(img, param, isClosed, color, thickness, lineType, shift);
895 }
896 
897 // Contrast-limited adaptive histogram equalization
898 struct _CLAHE{
899 	void* p;
900     
901     void close(){
902         CLAHE_Close(&this);
903     }
904     
905     void apply(Mat src, Mat dst){
906         CLAHE_Apply(&this, src, dst);
907     }
908 }
909 
910 alias CLAHE = _CLAHE*;
911 
912 CLAHE newCLAHE(){ // implement in 'this'?
913     return CLAHE_Create();
914 }
915 
916 CLAHE newCLAHEWithParams(double clipLimit, Size tileGridSize){ // implement in 'this'?
917     return CLAHE_CreateWithParams(clipLimit, tileGridSize);
918 }
919 
920 RotatedRect fitEllipse(Point[] points){
921     RotatedRect rect = FitEllipse(Points(points.ptr, points.length.to!int));
922     Point[] pts = rect.pts.points[0..rect.pts.length].dup;
923     
924     RotatedRect retRect = {
925         Contour(pts.ptr, pts.length.to!int),
926         rect.boundingRect,
927         rect.center,
928         rect.size,
929         rect.angle
930     };
931     Points_Close(rect.pts);
932     return retRect;
933 }
934 
935 RotatedRect fitEllipse(Mat points){
936     return FitEllipse2(points);
937 }
938 
939 RotatedRect fitEllipseAMS(Point[] points){
940     RotatedRect rect = FitEllipseAMS(Points(points.ptr, points.length.to!int));
941     Point[] pts = rect.pts.points[0..rect.pts.length].dup;
942     
943     RotatedRect retRect = {
944         Contour(pts.ptr, pts.length.to!int),
945         rect.boundingRect,
946         rect.center,
947         rect.size,
948         rect.angle
949     };
950     Points_Close(rect.pts);
951     return retRect;
952 }
953 
954 RotatedRect fitEllipseAMS(Mat points){
955     return FitEllipseAMS2(points);
956 }
957 
958 RotatedRect fitEllipseDirect(Point[] points){
959     RotatedRect rect = FitEllipseDirect(Points(points.ptr, points.length.to!int));
960     Point[] pts = rect.pts.points[0..rect.pts.length].dup;
961     
962     RotatedRect retRect = {
963         Contour(pts.ptr, pts.length.to!int),
964         rect.boundingRect,
965         rect.center,
966         rect.size,
967         rect.angle
968     };
969     Points_Close(rect.pts);
970     return retRect;
971 }
972 
973 RotatedRect fitEllipseDirect(Mat points){
974     return FitEllipseDirect2(points);
975 }
976 
977 void ellipse(Mat img, RotatedRect box, Scalar color, int thickness = 1, int lineType = LINE_8){
978     Ellipse2(img, box, color, thickness, lineType);
979 }
980 
981 enum: int {
982     COLOR_BGR2BGRA = 0, 
983 
984     COLOR_RGB2RGBA = COLOR_BGR2BGRA, 
985 
986     COLOR_BGRA2BGR = 1, 
987 
988     COLOR_RGBA2RGB = COLOR_BGRA2BGR, 
989 
990     COLOR_BGR2RGBA = 2, 
991 
992     COLOR_RGB2BGRA = COLOR_BGR2RGBA, 
993 
994     COLOR_RGBA2BGR = 3, 
995 
996     COLOR_BGRA2RGB = COLOR_RGBA2BGR, 
997 
998     COLOR_BGR2RGB = 4, 
999 
1000     COLOR_RGB2BGR = COLOR_BGR2RGB, 
1001 
1002     COLOR_BGRA2RGBA = 5, 
1003 
1004     COLOR_RGBA2BGRA = COLOR_BGRA2RGBA, 
1005 
1006     COLOR_BGR2GRAY = 6, 
1007 
1008     COLOR_RGB2GRAY = 7, 
1009 
1010     COLOR_GRAY2BGR = 8, 
1011 
1012     COLOR_GRAY2RGB = COLOR_GRAY2BGR, 
1013 
1014     COLOR_GRAY2BGRA = 9, 
1015 
1016     COLOR_GRAY2RGBA = COLOR_GRAY2BGRA, 
1017 
1018     COLOR_BGRA2GRAY = 10, 
1019 
1020     COLOR_RGBA2GRAY = 11, 
1021 
1022     COLOR_BGR2BGR565 = 12, 
1023 
1024     COLOR_RGB2BGR565 = 13, 
1025 
1026     COLOR_BGR5652BGR = 14, 
1027 
1028     COLOR_BGR5652RGB = 15, 
1029 
1030     COLOR_BGRA2BGR565 = 16, 
1031 
1032     COLOR_RGBA2BGR565 = 17, 
1033 
1034     COLOR_BGR5652BGRA = 18, 
1035 
1036     COLOR_BGR5652RGBA = 19, 
1037 
1038     COLOR_GRAY2BGR565 = 20, 
1039 
1040     COLOR_BGR5652GRAY = 21, 
1041 
1042     COLOR_BGR2BGR555 = 22, 
1043 
1044     COLOR_RGB2BGR555 = 23, 
1045 
1046     COLOR_BGR5552BGR = 24, 
1047 
1048     COLOR_BGR5552RGB = 25, 
1049 
1050     COLOR_BGRA2BGR555 = 26, 
1051 
1052     COLOR_RGBA2BGR555 = 27, 
1053 
1054     COLOR_BGR5552BGRA = 28, 
1055 
1056     COLOR_BGR5552RGBA = 29, 
1057 
1058     COLOR_GRAY2BGR555 = 30, 
1059 
1060     COLOR_BGR5552GRAY = 31, 
1061 
1062     COLOR_BGR2XYZ = 32, 
1063 
1064     COLOR_RGB2XYZ = 33, 
1065 
1066     COLOR_XYZ2BGR = 34, 
1067 
1068     COLOR_XYZ2RGB = 35, 
1069 
1070     COLOR_BGR2YCrCb = 36, 
1071 
1072     COLOR_RGB2YCrCb = 37, 
1073 
1074     COLOR_YCrCb2BGR = 38, 
1075 
1076     COLOR_YCrCb2RGB = 39, 
1077 
1078     COLOR_BGR2HSV = 40, 
1079 
1080     COLOR_RGB2HSV = 41, 
1081 
1082     COLOR_BGR2Lab = 44, 
1083 
1084     COLOR_RGB2Lab = 45, 
1085 
1086     COLOR_BGR2Luv = 50, 
1087 
1088     COLOR_RGB2Luv = 51, 
1089 
1090     COLOR_BGR2HLS = 52, 
1091 
1092     COLOR_RGB2HLS = 53, 
1093 
1094     COLOR_HSV2BGR = 54, 
1095 
1096     COLOR_HSV2RGB = 55, 
1097 
1098     COLOR_Lab2BGR = 56, 
1099 
1100     COLOR_Lab2RGB = 57, 
1101 
1102     COLOR_Luv2BGR = 58, 
1103 
1104     COLOR_Luv2RGB = 59, 
1105 
1106     COLOR_HLS2BGR = 60, 
1107 
1108     COLOR_HLS2RGB = 61, 
1109 
1110     COLOR_BGR2HSV_FULL = 66, 
1111 
1112     COLOR_RGB2HSV_FULL = 67, 
1113 
1114     COLOR_BGR2HLS_FULL = 68, 
1115 
1116     COLOR_RGB2HLS_FULL = 69, 
1117 
1118     COLOR_HSV2BGR_FULL = 70, 
1119 
1120     COLOR_HSV2RGB_FULL = 71, 
1121 
1122     COLOR_HLS2BGR_FULL = 72, 
1123 
1124     COLOR_HLS2RGB_FULL = 73, 
1125 
1126     COLOR_LBGR2Lab = 74, 
1127 
1128     COLOR_LRGB2Lab = 75, 
1129 
1130     COLOR_LBGR2Luv = 76, 
1131 
1132     COLOR_LRGB2Luv = 77, 
1133 
1134     COLOR_Lab2LBGR = 78, 
1135 
1136     COLOR_Lab2LRGB = 79, 
1137 
1138     COLOR_Luv2LBGR = 80, 
1139 
1140     COLOR_Luv2LRGB = 81, 
1141 
1142     COLOR_BGR2YUV = 82, 
1143 
1144     COLOR_RGB2YUV = 83, 
1145 
1146     COLOR_YUV2BGR = 84, 
1147 
1148     COLOR_YUV2RGB = 85, 
1149 
1150     COLOR_YUV2RGB_NV12 = 90, 
1151 
1152     COLOR_YUV2BGR_NV12 = 91, 
1153 
1154     COLOR_YUV2RGB_NV21 = 92, 
1155 
1156     COLOR_YUV2BGR_NV21 = 93, 
1157 
1158     COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21, 
1159 
1160     COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21, 
1161 
1162     COLOR_YUV2RGBA_NV12 = 94, 
1163 
1164     COLOR_YUV2BGRA_NV12 = 95, 
1165 
1166     COLOR_YUV2RGBA_NV21 = 96, 
1167 
1168     COLOR_YUV2BGRA_NV21 = 97, 
1169 
1170     COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21, 
1171 
1172     COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21, 
1173 
1174     COLOR_YUV2RGB_YV12 = 98, 
1175 
1176     COLOR_YUV2BGR_YV12 = 99, 
1177 
1178     COLOR_YUV2RGB_IYUV = 100, 
1179 
1180     COLOR_YUV2BGR_IYUV = 101, 
1181 
1182     COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV, 
1183 
1184     COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV, 
1185 
1186     COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12, 
1187 
1188     COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12, 
1189 
1190     COLOR_YUV2RGBA_YV12 = 102, 
1191 
1192     COLOR_YUV2BGRA_YV12 = 103, 
1193 
1194     COLOR_YUV2RGBA_IYUV = 104, 
1195 
1196     COLOR_YUV2BGRA_IYUV = 105, 
1197 
1198     COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV, 
1199 
1200     COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV, 
1201 
1202     COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12, 
1203 
1204     COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12, 
1205 
1206     COLOR_YUV2GRAY_420 = 106, 
1207 
1208     COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420, 
1209 
1210     COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420, 
1211 
1212     COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420, 
1213 
1214     COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420, 
1215 
1216     COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420, 
1217 
1218     COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420, 
1219 
1220     COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420, 
1221 
1222     COLOR_YUV2RGB_UYVY = 107, 
1223 
1224     COLOR_YUV2BGR_UYVY = 108, 
1225 
1226     COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY, 
1227 
1228     COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY, 
1229 
1230     COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY, 
1231 
1232     COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY, 
1233 
1234     COLOR_YUV2RGBA_UYVY = 111, 
1235 
1236     COLOR_YUV2BGRA_UYVY = 112, 
1237 
1238     COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY, 
1239 
1240     COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY, 
1241 
1242     COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY, 
1243 
1244     COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY, 
1245 
1246     COLOR_YUV2RGB_YUY2 = 115, 
1247 
1248     COLOR_YUV2BGR_YUY2 = 116, 
1249 
1250     COLOR_YUV2RGB_YVYU = 117, 
1251 
1252     COLOR_YUV2BGR_YVYU = 118, 
1253 
1254     COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2, 
1255 
1256     COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2, 
1257 
1258     COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2, 
1259 
1260     COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2, 
1261 
1262     COLOR_YUV2RGBA_YUY2 = 119, 
1263 
1264     COLOR_YUV2BGRA_YUY2 = 120, 
1265 
1266     COLOR_YUV2RGBA_YVYU = 121, 
1267 
1268     COLOR_YUV2BGRA_YVYU = 122, 
1269 
1270     COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2, 
1271 
1272     COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2, 
1273 
1274     COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2, 
1275 
1276     COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2, 
1277 
1278     COLOR_YUV2GRAY_UYVY = 123, 
1279 
1280     COLOR_YUV2GRAY_YUY2 = 124, 
1281 
1282     COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY, 
1283 
1284     COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY, 
1285 
1286     COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2, 
1287 
1288     COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2, 
1289 
1290     COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2, 
1291 
1292     COLOR_RGBA2mRGBA = 125, 
1293 
1294     COLOR_mRGBA2RGBA = 126, 
1295 
1296     COLOR_RGB2YUV_I420 = 127, 
1297 
1298     COLOR_BGR2YUV_I420 = 128, 
1299 
1300     COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420, 
1301 
1302     COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420, 
1303 
1304     COLOR_RGBA2YUV_I420 = 129, 
1305 
1306     COLOR_BGRA2YUV_I420 = 130, 
1307 
1308     COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420, 
1309 
1310     COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420, 
1311 
1312     COLOR_RGB2YUV_YV12 = 131, 
1313 
1314     COLOR_BGR2YUV_YV12 = 132, 
1315 
1316     COLOR_RGBA2YUV_YV12 = 133, 
1317 
1318     COLOR_BGRA2YUV_YV12 = 134, 
1319 
1320     COLOR_BayerBG2BGR = 46, 
1321 
1322     COLOR_BayerGB2BGR = 47, 
1323 
1324     COLOR_BayerRG2BGR = 48, 
1325 
1326     COLOR_BayerGR2BGR = 49, 
1327 
1328     COLOR_BayerBG2RGB = COLOR_BayerRG2BGR, 
1329 
1330     COLOR_BayerGB2RGB = COLOR_BayerGR2BGR, 
1331 
1332     COLOR_BayerRG2RGB = COLOR_BayerBG2BGR, 
1333 
1334     COLOR_BayerGR2RGB = COLOR_BayerGB2BGR, 
1335 
1336     COLOR_BayerBG2GRAY = 86, 
1337 
1338     COLOR_BayerGB2GRAY = 87, 
1339 
1340     COLOR_BayerRG2GRAY = 88, 
1341 
1342     COLOR_BayerGR2GRAY = 89, 
1343 
1344     COLOR_BayerBG2BGR_VNG = 62, 
1345 
1346     COLOR_BayerGB2BGR_VNG = 63, 
1347 
1348     COLOR_BayerRG2BGR_VNG = 64, 
1349 
1350     COLOR_BayerGR2BGR_VNG = 65, 
1351 
1352     COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG, 
1353 
1354     COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG, 
1355 
1356     COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG, 
1357 
1358     COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG, 
1359 
1360     COLOR_BayerBG2BGR_EA = 135, 
1361 
1362     COLOR_BayerGB2BGR_EA = 136, 
1363 
1364     COLOR_BayerRG2BGR_EA = 137, 
1365 
1366     COLOR_BayerGR2BGR_EA = 138, 
1367 
1368     COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA, 
1369 
1370     COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA, 
1371 
1372     COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA, 
1373 
1374     COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA, 
1375 
1376     COLOR_BayerBG2BGRA = 139, 
1377 
1378     COLOR_BayerGB2BGRA = 140, 
1379 
1380     COLOR_BayerRG2BGRA = 141, 
1381 
1382     COLOR_BayerGR2BGRA = 142, 
1383 
1384     COLOR_BayerBG2RGBA = COLOR_BayerRG2BGRA, 
1385 
1386     COLOR_BayerGB2RGBA = COLOR_BayerGR2BGRA, 
1387 
1388     COLOR_BayerRG2RGBA = COLOR_BayerBG2BGRA, 
1389 
1390     COLOR_BayerGR2RGBA = COLOR_BayerGB2BGRA, 
1391 
1392     COLOR_COLORCVT_MAX = 143
1393 }