Ask Your Question
2

How to set number of channels for Mat using a variable ?

asked 2017-02-22 21:25:13 -0600

Nbb gravatar image

I know I can initialize a Mat this way

cv::Mat image(cv::Size(480,640), CV_32FC1);

But is there a way I can initialize it using a variable ?

auto type = image.type();
cv::Mat image2(cv::Size(480,640), type);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2017-02-22 21:56:51 -0600

LBerger gravatar image

You can use macro CV_32FC(n) :

int nbChannels=48;
cv::Mat image2(cv::Size(480,640), CV_32FC(nbChannels))

PS cv::Size(480,640)= 480 column and 640 rows

edit flag offensive delete link more

Comments

Thanks ! Do you know how I can access such a matrix ? Since cv::Vec3f is meant for 3 matrices with 3 channels. cv::Vec48f = image2.at<cv::vec38f>(row,col). I think I found it. cv::Vec<float,48> data = image2.at<cv::Vec<float, 48> >(row,col)

Nbb gravatar imageNbb ( 2017-02-23 00:56:35 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-22 21:25:13 -0600

Seen: 5,628 times

Last updated: Feb 22 '17