Ask Your Question
0

mat transpose .t() a Nx2 mat gives me a 1x2N output.

asked 2016-05-20 01:07:25 -0600

nil gravatar image

updated 2016-05-20 03:49:02 -0600

Hi a Nx2 mat variable temp that has form

[a,b;
c,d;
e,f;
...,...]

in cout<<temp when i type temp.rows it gives me N, when i type temp.cols it gives me 1!!!!!! hence when I used temp.t() the cout output is a 1x2N row vector.

What happened ? Thx

edit retag flag offensive close merge delete

Comments

How many channels does your Mat have? are you sure it is an Nx2 Mat and not a n Nx1 mat with two channels?
Both should print as N rows of 2 using cout. but when you transpose, the first will print as two rows of N and the second will probably print as a row of 2N. guy

Guyygarty gravatar imageGuyygarty ( 2016-05-20 12:51:00 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-20 06:54:57 -0600

to understand your question i tried the code below and output is normal. if you show your code we can test it and try to explain why your transposed mat has 1x2N rows.

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int, char** argv )
{
    vector<Point> points;

    points.push_back(Point(0,1));
    points.push_back(Point(2,3));
    points.push_back(Point(4,5));
    points.push_back(Point(6,7));
    points.push_back(Point(8,9));

    Mat m = Mat(points);

    cout << "rows : " << m.rows << endl;
    cout << "cols : " << m.cols << endl;

    cout << m << endl;

    Mat transposed = m.t();

    cout << "transposed rows : " << transposed.rows << endl;
    cout << "transposed cols : " << transposed.cols << endl;

    cout << transposed << endl;

}

output:

rows : 5
cols : 1
[0, 1;
 2, 3;
 4, 5;
 6, 7;
 8, 9]
transposed rows : 1
transposed cols : 5
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-20 01:07:25 -0600

Seen: 11,639 times

Last updated: May 20 '16