Thus references or pointers to these two classes can be freely but carefully converted one to another. In opencv mat is an image image is a mat. To tackle this issue opencv uses a reference counting system.