Merge branch 'master' into dev_train_binocular_ui
[The-Artvertiser.git] / starter / math / growmat.cpp
blobcec68bf031d236b0312e0166961b7d08fcaf3eb3
1 #include "growmat.h"
3 CvGrowMat::CvGrowMat(int maxlines, int maxcols, int type)
5 mat = cvCreateMat(maxlines, maxcols, type);
6 cvSetZero(mat);
7 cvGetSubRect(mat, this, cvRect(0,0,maxcols,maxlines));
10 CvGrowMat::~CvGrowMat()
12 cvReleaseMat(&mat);
15 void CvGrowMat::resize(int lines, int cols)
17 if (lines <= mat->rows && cols <= mat->cols) {
18 cvGetSubRect(mat, this, cvRect(0,0,cols,lines));
19 //this->rows = lines;
20 //this->cols = cols;
21 } else {
22 int nl = (lines > mat->rows ? lines*2 : mat->rows);
23 int nc = (cols > mat->cols ? cols*2 : mat->cols);
24 CvMat *nm = cvCreateMat(nl, nc, mat->type);
25 cvSetZero(nm);
26 if (this->rows && this->cols) {
27 CvMat sub;
28 cvGetSubRect(nm, &sub, cvRect(0,0,this->cols, this->rows));
29 cvCopy(this, &sub);
30 cvGetSubRect(nm, this, cvRect(0,0,cols, lines));
31 } else {
32 cvGetSubRect(nm, this, cvRect(0,0,mat->cols, mat->rows));
33 this->rows = lines;
34 this->cols = cols;
36 cvReleaseMat(&mat);
37 mat = nm;