Ask Your Question
0

How to initialize array of cv::Mat with rows, cols and value?

asked 2019-04-09 09:54:59 -0600

JeyP4 gravatar image

updated 2019-04-09 09:55:45 -0600

How to initialize an array with 10 Mat's?

cv::Mat im[10](r, c, CV_8UC3);

Each mat consists of 'r' rows and 'c' columns.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-04-12 02:24:22 -0600

berak gravatar image

you need a fresh Mat instance for each element of your array /vector, like:

vector<Mat> im {
     Mat(r,c,CV_8UC3),
     Mat(r,c,CV_8UC3),
     Mat(r,c,CV_8UC3)
};

please do NOT try like this:

vector<Mat> im(3, Mat(r,c,16));

(because all 3 Mat instances will point to the same Mat.data)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-04-09 09:54:59 -0600

Seen: 1,930 times

Last updated: Apr 12 '19