Using Mat objects.
Refer to the page onĀ Mat.
Data Size
Make sure you take into account the number of channels.
int size = mymat.total() * mymat.elemSize();