cv;
ml;
highgui;

IPL_ALIGN_DWORD=IPL_ALIGN_4BYTES;
IPL_ALIGN_QWORD=IPL_ALIGN_8BYTES;
CV_GRAPH=CV_SEQ_KIND_GRAPH;
CV_HIST_TREE=CV_HIST_SPARSE;
CV_TERMCRIT_NUMBER=CV_TERMCRIT_ITER;
CV_SEQ_ELTYPE_PTR=CV_USRTYPE1;
CV_SEQ_CONTOUR=CV_SEQ_POLYGON;
CV_STORAGE_WRITE_TEXT=CV_STORAGE_WRITE;
CV_STORAGE_WRITE_BINARY=CV_STORAGE_WRITE;
CV_NODE_INTEGER=CV_NODE_INT;
CV_NODE_FLOAT=CV_NODE_REAL;
CV_NODE_STRING=CV_NODE_STR;
CV_DXT_INVERSE_SCALE=CV_DXT_INV_SCALE;
CV_RGB2RGBA=CV_BGR2BGRA;
CV_FONT_VECTOR0=CV_FONT_HERSHEY_SIMPLEX;
CV_RGBA2RGB=CV_BGRA2BGR;
CV_RGB2BGRA=CV_BGR2RGBA;
CV_BGRA2RGB=CV_RGBA2BGR;
CV_RGB2BGR=CV_BGR2RGB;
CV_RGBA2BGRA=CV_BGRA2RGBA;
CV_GRAY2RGB=CV_GRAY2BGR;
CV_GRAY2RGBA=CV_GRAY2BGRA;
CV_BayerBG2RGB=CV_BayerRG2BGR;
CV_BayerGB2RGB=CV_BayerGR2BGR;
CV_BayerRG2RGB=CV_BayerBG2BGR;
CV_BayerGR2RGB=CV_BayerGB2BGR;

CV_MAKE_TYPE=@CV_MAKETYPE;
CV_IS_CONT_MAT=@CV_IS_MAT_CONT;
cvGetSubArr=@cvGetSubRect;
cvZero=@cvSetZero;
cvCvtScale=@cvConvertScale;
cvScale=@cvConvertScale;
cvCvtScaleAbs=@cvConvertScaleAbs;
cvCheckArray=@cvCheckArr;
cvMatMulAddEx=@cvGEMM;
cvMatMulAddS=@cvTransform;
cvT=@cvTranspose;
cvMirror=@cvFlip;
cvInv=@cvInvert;
cvMahalonobis=@cvMahalanobis;
cvFFT=@cvDFT;
cvGraphFindEdge=@cvFindGraphEdge;
cvGraphFindEdgeByPtr=@cvFindGraphEdgeByPtr;
cvDrawRect=@cvRectangle;
cvDrawLine=@cvLine;
cvDrawCircle=@cvCircle;
cvDrawEllipse=@cvEllipse;
cvDrawPolyLine=@cvPolyLine;
cvCalcHist=@cvCalcArrHist;

## use subsasgn/assign, combine with above
## or expose octave_swig_type install_global etc
cv.CV_MAKE_TYPE=@CV_MAKETYPE;
cv.CV_IS_CONT_MAT=@CV_IS_MAT_CONT;
cv.cvGetSubArr=@cvGetSubRect;
cv.cvZero=@cvSetZero;
cv.cvCvtScale=@cvConvertScale;
cv.cvScale=@cvConvertScale;
cv.cvCvtScaleAbs=@cvConvertScaleAbs;
cv.cvCheckArray=@cvCheckArr;
cv.cvMatMulAddEx=@cvGEMM;
cv.cvMatMulAddS=@cvTransform;
cv.cvT=@cvTranspose;
cv.cvMirror=@cvFlip;
cv.cvInv=@cvInvert;
cv.cvMahalonobis=@cvMahalanobis;
cv.cvFFT=@cvDFT;
cv.cvGraphFindEdge=@cvFindGraphEdge;
cv.cvGraphFindEdgeByPtr=@cvFindGraphEdgeByPtr;
cv.cvDrawRect=@cvRectangle;
cv.cvDrawLine=@cvLine;
cv.cvDrawCircle=@cvCircle;
cv.cvDrawEllipse=@cvEllipse;
cv.cvDrawPolyLine=@cvPolyLine;
cv.cvCalcHist=@cvCalcArrHist;

## add %octavecode support, or use subsref

function [count,seq] = cvFindContours(varargin)
  global cv;
  [count, seq] = cv.cvFindContoursUntyped( varargin{:} );
  if (swig_this(seq))
    seq = cv.CvSeq_CvPoint.cast(seq);
  endif
endfunction
cv.cvFindContours=@cvFindContours;

function [count,seq] = cvHoughCircles(varargin)
  global cv;
  [count, seq] = cv.cvHoughCirclesUntyped( varargin{:} );
  if (swig_this(seq))
    seq = cv.CvSeq_float_3.cast(seq);
  endif
endfunction
cv.cvHoughCircles=@cvHoughCircles;

function [count,seq] = cvPyrSegmentation(varargin)
  global cv;
  [count, seq] = cv.cvPyrSegmentationUntyped( varargin{:} );
  if (swig_this(seq))
    seq = cv.CvSeq_CvConnectedComp.cast(seq);
  endif
endfunction
cv.cvPyrSegmentation=@cvPyrSegmentation;

function [count,seq] = cvApproxChains(varargin)
  global cv;
  [count, seq] = cv.cvApproxChainsUntyped( varargin{:} );
  if (swig_this(seq))
    seq = cv.CvSeq_CvPoint.cast(seq);
  endif
endfunction
cv.cvApproxChains=@cvApproxChains;

function [count,seq] = cvContourFromContourTree(varargin)
  global cv;
  [count, seq] = cv.cvContourFromContourTreeUntyped( varargin{:} );
  if (swig_this(seq))
    seq = cv.CvSeq_CvPoint.cast(seq);
  endif
endfunction
cv.cvContourFromContourTree=@cvContourFromContourTree;

function [count,seq] = cvConvexityDefects(varargin)
  global cv;
  [count, seq] = cv.cvConvexityDefectsUntyped( varargin{:} );
  if (swig_this(seq))
    seq = cv.CvSeq_CvConvexityDefect.cast(seq);
  endif
endfunction
cv.cvConvexityDefects=@cvConvexityDefects;

function seq = cvHoughLines2(varargin)
  global cv;
  seq = cv.cvHoughLinesUntyped( varargin{:} );
  if (swig_this(seq))
    seq = cv.CvSeq_CvPoint.cast(seq);
    t = CV_SEQ_ELTYPE(seq) 
    if (t == cv.CV_32SC4)
      seq = cv.CvSeq_CvPoint_2.cast(seq)
    else
      seq = cv.CvSeq_float_2.cast(seq)
    endif
  endif
endfunction
cv.cvHoughLines2=@cvHoughLines2;


function c = CvSeq_map(self)
  c = cell(1, self.total);
  for i = 1:self.total, c{i} = self{i}; end;
endfunction
cv.CvSeq_map=@CvSeq_map;

function c = CvSeq_hrange(self)
  c = {};
  i = 0;
  if swig_this(self)
    s = self;
    while swig_this(s.h_next), s = s.cast(s.h_next); c{++i} = s; end;
  endif
endfunction
cv.CvSeq_hrange=@CvSeq_hrange;

function c = CvSeq_vrange(self)
  c = {};
  i = 0;
  if swig_this(self)
    s = self;
    while swig_this(s.v_next), s = s.cast(s.v_next); c{++i} = s; end;
  endif
endfunction
cv.CvSeq_vrange=@CvSeq_vrange;
