opencv - Finding the size in bytes of cv::Mat -
i'm using opencv cv::mat
objects, , need know number of bytes matrix occupies in order pass low-level c api. seems opencv's api doesn't have method returns number of bytes matrix uses, , have raw uchar *data
public fellow member no fellow member contains actual size.
how can 1 find cv::mat
size in bytes?
the mutual reply calculate total number of elements in matrix , multiply size of each element, this:
// given cv::mat named mat. size_t sizeinbytes = mat.total() * mat.elemsize();
this work in conventional scenarios, matrix allocated contiguous chunk in memory.
but consider case scheme has alignment constraint on number of bytes per row in matrix. in case, if mat.cols * mat.elemsize()
not aligned, mat.iscontinuous()
false
, , previous size calculation wrong, since mat.elemsize()
have same number of elements, although buffer larger!
the right answer, then, find size of each matrix row in bytes, , multiply number of rows:
size_t sizeinbytes = mat.step[0] * mat.rows;
read more step
here.
opencv
No comments:
Post a Comment