Ask Your Question

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

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

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

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

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


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

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

Question Tools

1 follower


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

Seen: 3,708 times

Last updated: Feb 22 '17