12

What is the difference in opencv between these two transposes?

Using cv::Mat::t():

cv::Mat a;
a = a.t();

Using cv::transpose():

cv::Mat a;
cv::transpose(a,a);

I'm interested in particular about efficiency.

justHelloWorld
  • 6,478
  • 8
  • 58
  • 138
  • One appears to be in-place, the other writes to a separate output. – Kerrek SB Apr 09 '17 at 18:41
  • @KerrekSB thanks for your comment. So is it correct to say that the first one is more efficient? – justHelloWorld Apr 09 '17 at 18:42
  • 1
    I don't think that's a sensible question. The two functions do different things. Each of them is as efficient as it can be at what it's doing. – Kerrek SB Apr 09 '17 at 18:46
  • @KerrekSB From my knowledge, doing something in-place means without allocating memory, which is more a efficient than non-in-place method (like the second one). So, in this particular case, is more efficient the first method. Am I wrong? – justHelloWorld Apr 09 '17 at 18:48
  • I'm with @KerrekSB on this one. If you want to use the transpose for solving another expression then use the first method, if you want the transposed matrix, the second – Rick M. Apr 09 '17 at 20:29

1 Answers1

11

There's no difference. Here's the code for cv::Mat::t() from opencv/modules/core/src/matop.cpp:

MatExpr MatExpr::t() const
{
    MatExpr e;
    op->transpose(*this, e);
    return e;
}

So cv::Mat::t() just calls cv::transpose().

beaker
  • 16,331
  • 3
  • 32
  • 49