| 276 | // The returned matrix may or may not use the same buffer as mat. |
| 277 | |
| 278 | MAT DimKeep(const MAT& mat, int nrows, int ncols) |
| 279 | { |
| 280 | if (mat.rows == nrows && mat.cols == ncols) // no change needed? |
| 281 | return mat; |
| 282 | if (mat.rows * mat.cols == nrows * ncols) // same number of elements? |
| 283 | { |
| 284 | CV_Assert(mat.isContinuous()); |
| 285 | MAT newmat(mat); |
| 286 | newmat.rows = nrows; |
| 287 | newmat.cols = ncols; |
| 288 | newmat.step = ncols * sizeof(newmat(0)); |
| 289 | return newmat; |
| 290 | } |
| 291 | // copy as much of the data as will fit in the new matrix |
| 292 | MAT newmat(nrows, ncols, 0.); |
| 293 | int minrows = MIN(nrows, mat.rows); |
| 294 | for (int i = 0; i < minrows; i++) |
| 295 | { |
| 296 | const double* const rowbuf = mat.ptr<double>(i); |
| 297 | double* const rowbuf1 = newmat.ptr<double>(i); |
| 298 | for (int j = 0; j < ncols; j++) |
| 299 | rowbuf1[j] = rowbuf[j]; |
| 300 | } |
| 301 | return newmat; |
| 302 | } |
| 303 | |
| 304 | const MAT ArrayAsMat( // create a MAT from a C array of doubles |
| 305 | int nrows, // in |
no outgoing calls
no test coverage detected