Ask Your Question
0

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

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

JeyP4 gravatar image

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

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 -0500

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
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 78 times

Last updated: Apr 12