Ask Your Question
0

Creating an array of Mats of size n

asked Apr 12 '14

Luek gravatar image

I am trying to create an array of Mat objects to store images and am getting warnings for using anything other than a statically typed number such as 10

int numberOfRects = boundRect.size();
Mat image_array[numberOfRects];

When I try this code I get an error stating Variable length array of non-POD element type 'cv::Mat'

Same goes for this code: Mat image_array[boundRect.size()];

How can I create an array of Mats based on the size of boundRect?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Apr 12 '14

Guanta gravatar image

Static arrays need the size for their construction at compile time. If you want to have the size controlled at run-time, you need to either create the mat-array via new or use std::vector (I'd prefer the latter one, since when using new you'll also need to call delete[] and it also prevents you from writing at non existent memory).

Preview: (hide)

Question Tools

Stats

Asked: Apr 12 '14

Seen: 3,337 times

Last updated: Apr 12 '14