Declaring and initializing Mat object inside while loop

Does declaring and initializing a Mat inside a while loop create performance issues? For example mat2 inside the while loop? If so what would be a better approach?

Mat mat1;
Mat mat2(mat1,Range(10,20),Range(10,20));

that? not at all. that’s creating a view into the first Mat. that’s constant time effort. perfectly reasonable to do.

what you should be worried about is opening (and closing) a VideoCapture repeatedly. that is a tangible and serious waste of time. the capture device id is always 0 in your example.

Thank you! I did miss that Video Capture while creating the example, normally I keep it outside the while loop.