# Revision history [back]

You don't really need the size. You can define a void pointer :

Mat Image;
...
void *P=(void *) &Image;


and then at the destination recreate the Mat using:

Mat Image1=((Mat) *(Mat *)P);
Mat Image2=((Mat) *(Mat *)P).clone();


Note that Image1 is the same Mat as you had originally if you change anything in Image, Image1 will also change and vice versa Image2 is a new Mat, that has a copy of the original image

As a note, you should think seriously on how you want to do this as, using Image1 will likely mess up the reference counting in OpenCV and (if you are not careful) can lead to either a memory leak or to your image going out of scope while you are still using it.
guy

You don't really need the size. You can define a void pointer :

Mat Image;
...
void *P=(void *) &Image;


and then at the destination recreate the Mat using:

Mat Image1=((Mat) *(Mat *)P);
Mat Image2=((Mat) *(Mat *)P).clone();


Note that Image1 is the same Mat as you had originally if originally. If you change anything in Image, Image1 will also change and vice versa versa.

Image2 is a new Mat, that has a copy of the original image

As a note, you should think seriously on how you want to do this as, using this.

Using Image1 is faster and more memory efficient, but will likely mess up the reference counting in OpenCV and (if you are not careful) can lead to either a memory leak or to your image going out of scope while you are still using it.

guy