Ask Your Question

Revision history [back]

I stand to be corrected but according to their documentation, there are two ways of attaining the size of a Matrix.

So let us say we have Mat temp. If we want to find its size, you could either:

  1. Old School method

From their documentation, a Mat consists of a size attribute which returns a MatSize struct object. By doing temp.size, you will get the correct matrix size but in MatSize return type and of height X width format.

  1. Operator method

A look into MatSize, you will see that it implements the () operator. With this method though, its return type is Size and of the famously adapted format width X height. So by doing temp.size(), the MatSize's operator() method gets called.

You might ask, so which one should be used? It depends on your scenario.

I believe the MatSize version was there for the old C-API (speculation). If you are still using it (you shouldn't be by now), then .size makes sense. During my lazy coding days, I tend to use it as well just for quick matrix size checkups.

I mostly use .size() because other functions adapted Size. For example, this default constructor takes Size instead of MSize.

Either one you choose to use, keep in mind of the returned format.

I stand to be corrected but according to their documentation, there are two ways of attaining the size of a Matrix.

So let us say we have Mat temp. If we want to find its size, you could either:

  1. 1. Old School method

From their documentation, a Mat consists of a size attribute which returns a MatSize struct object. By doing temp.size, you will get the correct matrix size but in MatSize return type and of height X width format.

  1. 2. Operator method

A look into MatSize, you will see that it implements the () operator. With this method though, its return type is Size and of the famously adapted format width X height. So by doing temp.size(), the MatSize's operator() method gets called.

You might ask, so which one should be used? It depends on your scenario.

I believe the MatSize version was there for the old C-API (speculation). If you are still using it (you shouldn't be by now), then .size makes sense. During my lazy coding days, I tend to use it as well just for quick matrix size checkups.

I mostly use .size() because other functions adapted Size. For example, this default constructor takes Size instead of MSize.

Either one you choose to use, keep in mind of the returned format.