Ask Your Question
0

Matrix to single row

asked 2013-06-15 14:01:55 -0600

Hansg91 gravatar image

Hello,

I need to convert a square cv::Mat to a single row. Right now I iterate over its rows and append them horizontally (cv::hconcat) to a separate matrix to get my single row matrix, but is there perhaps a better way?

Best regards, Hans

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2013-06-15 14:12:23 -0600

berak gravatar image

updated 2013-06-15 14:16:37 -0600

Mat row = mat.reshape(1,1);

and it even comes almost for free, as it's just adjusting the Mat's row/col members, no copy involved.

edit flag offensive delete link more

Comments

Hmm, thought I had tried that but it didn't work back then for some reason. Tried it again and seems to work now, hehe, thanks !

Hansg91 gravatar imageHansg91 ( 2013-06-15 14:37:23 -0600 )edit

Ah, I tried it again in another situation, reshape only works for continuous matrices, that was the problem I was having ... any reshape call for that?

Hansg91 gravatar imageHansg91 ( 2013-06-15 14:39:43 -0600 )edit

yea, have to admit, that the arguments for reshape are quite confusing

oh, imho it won't work at all for non-continuous Mat's. iterating is your only option there

berak gravatar imageberak ( 2013-06-15 14:42:40 -0600 )edit

Hmm, too bad, was hoping for some cv function.

Hansg91 gravatar imageHansg91 ( 2013-06-15 14:48:07 -0600 )edit
1

or cloning beforehand and then reshaping it

Guanta gravatar imageGuanta ( 2013-06-15 15:37:47 -0600 )edit

Question Tools

Stats

Asked: 2013-06-15 14:01:55 -0600

Seen: 3,062 times

Last updated: Jun 15 '13